Commit 484fcca5 by celinemercier

changed the private *at functions to the official ones for openat and

mkdirat, but not for opendirat, as there is no official version of it.
parent 802f9983
......@@ -26,7 +26,7 @@
#include "obierrno.h"
#include "obidebug.h"
#include "obilittlebigman.h"
#include "private_at_functions.h"
/**************************************************************************
*
......@@ -188,7 +188,7 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
}
// Open the version file
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDWR);
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDWR);
if (version_file_descriptor < 0)
{
free(version_file_name);
......@@ -335,7 +335,7 @@ static int create_version_file(OBIDMS_column_directory_p column_directory)
}
// Get the file descriptor associated to the version file
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDWR | O_CREAT);
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDWR | O_CREAT);
if (version_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -455,7 +455,7 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
}
// Get the file descriptor associated to the version file
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDONLY);
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDONLY);
if (version_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -583,7 +583,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
}
// Open the column file
column_file_descriptor = private_openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT);
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT);
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......
......@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
......@@ -158,7 +159,7 @@ OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char*
}
// Try to create the directory
if (private_mkdirat(dms_file_descriptor, column_directory_name, 0x777) < 0)
if (mkdirat(dms_file_descriptor, column_directory_name, 0x777) < 0)
{
if (errno == EEXIST)
obi_set_errno(OBICOLDIR_EXIST_ERROR);
......
......@@ -47,43 +47,6 @@ char* get_full_path(int directory_file_descriptor, const char* path_name)
}
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;
}
DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
{
char* full_path;
......@@ -100,3 +63,40 @@ DIR* private_opendirat(int directory_file_descriptor, const char* path_name)
return directory;
}
//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;
//}
......@@ -41,36 +41,6 @@ char* get_full_path(int directory_file_descriptor, const char* path_name);
/**
* @brief Replacement function for openat() : open a file relative to a directory file descriptor.
*
* @param directory_file_descriptor the file descriptor for the directory in which the file should be opened
* @param path_name the path name for the file, relative to directory_file_descriptor
* @param flags the access modes
*
* @return the file descriptor of the opened file
*
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int private_openat(int directory_file_descriptor, const char* path_name, int flags);
/**
* @brief Replacement function for mkdirat() : create a directory relative to a directory file descriptor.
*
* @param directory_file_descriptor the file descriptor for the directory in which the directory should be created
* @param path_name the path name for the new directory, relative to directory_file_descriptor
* @param mode the access mode
*
* @return the file descriptor of the created directory
*
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t mode);
/**
* @brief Replacement function for opendirat() : open a directory relative to a directory file descriptor.
*
* @param directory_file_descriptor the file descriptor for the directory in which the directory should be opened
......@@ -84,4 +54,34 @@ int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t
DIR* private_opendirat(int directory_file_descriptor, const char* path_name);
///**
// * @brief Replacement function for openat() : open a file relative to a directory file descriptor.
// *
// * @param directory_file_descriptor the file descriptor for the directory in which the file should be opened
// * @param path_name the path name for the file, relative to directory_file_descriptor
// * @param flags the access modes
// *
// * @return the file descriptor of the opened file
// *
// * @since June 2015
// * @author Celine Mercier (celine.mercier@metabarcoding.org)
// */
//int private_openat(int directory_file_descriptor, const char* path_name, int flags);
//
//
///**
// * @brief Replacement function for mkdirat() : create a directory relative to a directory file descriptor.
// *
// * @param directory_file_descriptor the file descriptor for the directory in which the directory should be created
// * @param path_name the path name for the new directory, relative to directory_file_descriptor
// * @param mode the access mode
// *
// * @return the file descriptor of the created directory
// *
// * @since June 2015
// * @author Celine Mercier (celine.mercier@metabarcoding.org)
// */
//int private_mkdirat(int directory_file_descriptor, const char* path_name, mode_t mode);
#endif /* PRIVATEOPENAT_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment