2015-06-23 17:55:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private *at functions *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file private_at_functions.h
|
|
|
|
* @author Celine Mercier
|
|
|
|
* @date 15 June 2015
|
|
|
|
* @brief Private replacement functions for *at functions.
|
|
|
|
*/
|
|
|
|
|
2015-06-18 17:19:23 +02:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
2015-06-23 17:55:00 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dirent.h>
|
2015-06-18 17:19:23 +02:00
|
|
|
|
|
|
|
#include "private_at_functions.h"
|
|
|
|
|
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
/**********************************************************************
|
2015-06-18 17:19:23 +02:00
|
|
|
*
|
2015-06-23 17:55:00 +02:00
|
|
|
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
2015-06-18 17:19:23 +02:00
|
|
|
*
|
2015-06-23 17:55:00 +02:00
|
|
|
**********************************************************************/
|
2015-06-18 17:19:23 +02:00
|
|
|
|
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
char* get_full_path(int directory_file_descriptor, const char* path_name)
|
2015-06-18 17:19:23 +02:00
|
|
|
{
|
2015-06-23 17:55:00 +02:00
|
|
|
char* full_path;
|
2015-06-18 17:19:23 +02:00
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
|
|
|
|
if (full_path == NULL)
|
2015-06-18 17:19:23 +02:00
|
|
|
return NULL;
|
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
if (fcntl(directory_file_descriptor, F_GETPATH, full_path) < 0)
|
2015-06-18 17:19:23 +02:00
|
|
|
return NULL;
|
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
// check errors TODO
|
|
|
|
strlcat(full_path, "/", MAX_PATH_LEN);
|
|
|
|
strlcat(full_path, path_name, MAX_PATH_LEN);
|
2015-06-18 17:19:23 +02:00
|
|
|
|
|
|
|
return full_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
|
2015-06-18 17:19:23 +02:00
|
|
|
{
|
2015-06-23 17:55:00 +02:00
|
|
|
char* full_path;
|
|
|
|
DIR* directory;
|
2015-06-18 17:19:23 +02:00
|
|
|
|
|
|
|
full_path = get_full_path(directory_file_descriptor, path_name);
|
|
|
|
if (full_path == NULL)
|
2015-06-23 17:55:00 +02:00
|
|
|
return NULL;
|
2015-06-18 17:19:23 +02:00
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
directory = opendir(full_path);
|
2015-06-18 17:19:23 +02:00
|
|
|
|
2015-06-23 17:55:00 +02:00
|
|
|
free(full_path);
|
|
|
|
|
|
|
|
return directory;
|
2015-06-18 17:19:23 +02:00
|
|
|
}
|
2015-06-23 17:55:00 +02:00
|
|
|
|
2015-07-20 11:38:43 +02:00
|
|
|
|
|
|
|
//int private_openat(int directory_file_descriptor, const char* path_name, int flags)
|
|
|
|
//{
|
|
|
|
// char* full_path;
|
|
|
|
// int file_descriptor;
|
|
|
|
//
|
|
|
|
// full_path = get_full_path(directory_file_descriptor, path_name);
|
|
|
|
// if (full_path == NULL)
|
|
|
|
// return -1;
|
|
|
|
//
|
|
|
|
// file_descriptor = open(full_path, flags);
|
|
|
|
//
|
|
|
|
// free(full_path);
|
|
|
|
//
|
|
|
|
// return file_descriptor;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t mode)
|
|
|
|
//{
|
|
|
|
// char* full_path;
|
|
|
|
//
|
|
|
|
// full_path = get_full_path(directory_file_descriptor, path_name);
|
|
|
|
// if (full_path == NULL)
|
|
|
|
// return -1;
|
|
|
|
//
|
|
|
|
// if (mkdir(full_path, mode) < 0)
|
|
|
|
// {
|
|
|
|
// free(full_path);
|
|
|
|
// return -1;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// free(full_path);
|
|
|
|
//
|
|
|
|
// return 0;
|
|
|
|
//}
|
|
|
|
|