fixes #9 : replacement function for openat().
This commit is contained in:
22
src/private_openat.c
Normal file
22
src/private_openat.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "private_openat.h"
|
||||||
|
|
||||||
|
|
||||||
|
int private_openat(int directory_file_descriptor, const char* path_name, int flags)
|
||||||
|
{
|
||||||
|
int file_descriptor;
|
||||||
|
|
||||||
|
char full_path[MAX_PATH_LEN];
|
||||||
|
|
||||||
|
fcntl(directory_file_descriptor, F_GETPATH, full_path);
|
||||||
|
strlcat(full_path, "/", MAX_PATH_LEN);
|
||||||
|
strlcat(full_path, path_name, MAX_PATH_LEN);
|
||||||
|
|
||||||
|
file_descriptor = open(full_path, flags);
|
||||||
|
|
||||||
|
return file_descriptor;
|
||||||
|
}
|
27
src/private_openat.h
Normal file
27
src/private_openat.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* @file private_openat.h
|
||||||
|
* @author Celine Mercier
|
||||||
|
* @date 15 June 2015
|
||||||
|
* @brief Header file for a replacement function for openat.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PRIVATE_OPENAT_H_
|
||||||
|
#define PRIVATE_OPENAT_H_
|
||||||
|
|
||||||
|
#define MAX_PATH_LEN 4096
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
|
||||||
|
#endif /* PRIVATEOPENAT_H_ */
|
Reference in New Issue
Block a user