/**************************************************************************** * 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 #include #include #include #include #include #include #include #include "private_at_functions.h" #include "obidebug.h" #include "obierrno.h" #include "obidms.h" #define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?) char* get_full_path(OBIDMS_p dms, 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 (getcwd(full_path, MAX_PATH_LEN) == NULL) { obidebug(1, "\nError getting the path to a file or directory"); return NULL; } // TODO check errors? strcat(full_path, "/"); strcat(full_path, dms->directory_name); strcat(full_path, "/"); strcat(full_path, path_name); return full_path; } DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name) { char* full_path; DIR* directory; full_path = get_full_path(dms, 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; }