32 error (
"Invalid file descriptor supplied: fd2fpath_malloc(%i).", fd );
37 char *fsym = xmalloc ( ( 1 << 8 ) + 2 );
38 sprintf ( fsym,
"/proc/self/fd/%i", fd );
40 if ( lstat64 ( fsym, &st64 ) ) {
41 error (
"Cannot lstat64(\"%s\", st64).", fsym );
45 ssize_t fpathlen = st64.st_size;
47 char *fpath = xmalloc ( fpathlen + 2 );
49 debug ( 3,
"Getting file path from symlink \"%s\". Path length is: %i.", fsym, fpathlen );
51 if ( ( fpathlen = readlink ( fsym, fpath, fpathlen + 1 ) ) < 0 ) {
52 error (
"Cannot readlink(\"%s\", fpath, bufsize).", fsym );
58 debug ( 3,
"The path is: \"%s\"", fpath );
62 critical (
"Function fd2fpath_malloc() is not supported in this OS" );
82 from = fopen ( path_from,
"r" );
85 error (
"fileutils_copy(\"%s\", \"%s\"): Cannot open file \"%s\" for reading",
86 path_from, path_to, path_from );
90 to = fopen ( path_to,
"w" );
93 error (
"fileutils_copy(\"%s\", \"%s\"): Cannot open file \"%s\" for writing",
94 path_from, path_to, path_to );
98 while ( !feof ( from ) ) {
101 r = fread ( buf, 1,
BUFSIZ, from );
103 if ( ( err = ferror ( from ) ) ) {
104 error (
"fileutils_copy(\"%s\", \"%s\"): Cannot read from file \"%s\"",
105 path_from, path_to, path_from );
109 w = fwrite ( buf, 1, r, to );
111 if ( ( err = ferror ( to ) ) ) {
112 error (
"fileutils_copy(\"%s\", \"%s\"): Cannot write to file \"%s\"",
113 path_from, path_to, path_to );
118 error (
"fileutils_copy(\"%s\", \"%s\"): Got error while writing to file \"%s\" (%u != %u)",
119 path_from, path_to, path_to, r, w );
179int mkdirat_open (
const char *
const dir_path,
int dirfd_parent, mode_t dir_mode )
182 debug ( 5,
"mkdirat(%u, \"%s\", %o)", dirfd_parent, dir_path, dir_mode );
184 if ( mkdirat ( dirfd_parent, dir_path, dir_mode ) )
187 debug ( 5,
"openat(%u, \"%s\", %x)", dirfd_parent, dir_path, O_RDWR | O_DIRECTORY | O_PATH );
188 dirfd = openat ( dirfd_parent, dir_path, O_RDWR | O_DIRECTORY | O_PATH );
int mkdirat_open(const char *const dir_path, int dirfd_parent, mode_t dir_mode)
Combination of mkdirat() and openat()