Files
obitools3/src/private_at_functions.c

77 lines
1.6 KiB
C
Raw Normal View History

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