73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
/****************************************************************************
|
|
* Private *at functions *
|
|
****************************************************************************/
|
|
|
|
/**
|
|
* @file private_at_functions.c
|
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
|
* @date 15 June 2015
|
|
* @brief Private replacement functions for *at functions.
|
|
*/
|
|
|
|
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <dirent.h>
|
|
|
|
#include "private_at_functions.h"
|
|
#include "obidebug.h"
|
|
#include "obierrno.h"
|
|
|
|
|
|
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
|
|
|
|
|
char* get_full_path(int directory_file_descriptor, const char* path_name)
|
|
{
|
|
char* full_path;
|
|
|
|
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
|
|
if (full_path == NULL)
|
|
{
|
|
obidebug(1, "\nError allocating memory for the char* path to a file or directory");
|
|
return NULL;
|
|
}
|
|
|
|
if (fcntl(directory_file_descriptor, F_GETPATH, full_path) < 0)
|
|
{
|
|
obidebug(1, "\nError getting the path to a file or directory");
|
|
return NULL;
|
|
}
|
|
|
|
// TODO check errors?
|
|
strlcat(full_path, "/", MAX_PATH_LEN);
|
|
strlcat(full_path, path_name, MAX_PATH_LEN);
|
|
|
|
return full_path;
|
|
}
|
|
|
|
|
|
DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
|
|
{
|
|
char* full_path;
|
|
DIR* directory;
|
|
|
|
full_path = get_full_path(directory_file_descriptor, path_name);
|
|
if (full_path == NULL)
|
|
return NULL;
|
|
|
|
directory = opendir(full_path);
|
|
if (directory == NULL)
|
|
obidebug(1, "\nError opening a directory");
|
|
|
|
free(full_path);
|
|
|
|
return directory;
|
|
}
|
|
|
|
|