Commit 37ae6248 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

add vlc_openat wrapper around openat

parent d38c4f98
......@@ -33,6 +33,7 @@
VLC_EXPORT( int, vlc_open, ( const char *filename, int flags, ... ) LIBVLC_USED );
VLC_EXPORT( FILE *, vlc_fopen, ( const char *filename, const char *mode ) LIBVLC_USED );
VLC_EXPORT( int, vlc_openat, ( int fd, const char *filename, int flags, ... ) LIBVLC_USED );
VLC_EXPORT( DIR *, vlc_opendir, ( const char *dirname ) LIBVLC_USED );
VLC_EXPORT( char *, vlc_readdir, ( DIR *dir ) LIBVLC_USED );
......
......@@ -434,6 +434,7 @@ utf8_lstat
vlc_mkdir
vlc_mkstemp
vlc_open
vlc_openat
vlc_opendir
vlc_readdir
vlc_scandir
......
......@@ -193,6 +193,53 @@ FILE *vlc_fopen (const char *filename, const char *mode)
return stream;
}
/**
* Opens a system file handle relative to an existing directory handle.
*
* @param dir directory file descriptor
* @param filename file path to open (with UTF-8 encoding)
* @param flags open() flags, see the C library open() documentation
* @return a file handle on success, -1 on error (see errno).
* @note Contrary to standard open(), this function returns file handles
* with the close-on-exec flag enabled.
*/
int vlc_openat (int dir, const char *filename, int flags, ...)
{
unsigned int mode = 0;
va_list ap;
va_start (ap, flags);
if (flags & O_CREAT)
mode = va_arg (ap, unsigned int);
va_end (ap);
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
const char *local_name = ToLocale (filename);
if (local_name == NULL)
{
errno = ENOENT;
return -1;
}
#ifdef HAVE_FDOPENDIR
int fd = openat (dir, local_name, flags, mode);
# ifdef HAVE_FCNTL
if (fd != -1)
fcntl (fd, F_SETFD, FD_CLOEXEC);
# endif
#else
int fd = -1;
errno = ENOSYS;
#endif
LocaleFree (local_name);
return fd;
}
/**
* Creates a directory using UTF-8 paths.
*
......
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