X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Ftext%2Ffilesystem.c;h=6aa499d15976f64b951b38d3cbb923ef931cfcb6;hb=e30ad750353d3599fb791db99d80bed069dcf140;hp=bc602ae5f366c3511e74af4cf750a67a4d37efca;hpb=fd7f8f854a13f7b65cb2b8622755aa47ee932919;p=vlc diff --git a/src/text/filesystem.c b/src/text/filesystem.c index bc602ae5f3..6aa499d159 100644 --- a/src/text/filesystem.c +++ b/src/text/filesystem.c @@ -85,11 +85,24 @@ static int convert_path (const char *restrict path, wchar_t *restrict wpath) * * @param filename file path to open (with UTF-8 encoding) * @param flags open() flags, see the C library open() documentation - * @param mode file permissions if creating a new file * @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 utf8_open (const char *filename, int flags, mode_t mode) +int utf8_open (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 + #ifdef UNDER_CE /*_open translates to wchar internally on WinCE*/ return _open (filename, flags, mode); @@ -110,22 +123,11 @@ int utf8_open (const char *filename, int flags, mode_t mode) return -1; } - int fd; - -#ifdef O_CLOEXEC - fd = open (local_name, flags | O_CLOEXEC, mode); - if (fd == -1 && errno == EINVAL) -#endif - { - fd = open (local_name, flags, mode); + int fd = open (local_name, flags, mode); #ifdef HAVE_FCNTL - if (fd != -1) - { - int flags = fcntl (fd, F_GETFD); - fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0)); - } + if (fd != -1) + fcntl (fd, F_SETFD, FD_CLOEXEC); #endif - } LocaleFree (local_name); return fd; @@ -339,8 +341,7 @@ int utf8_loaddir( DIR *dir, char ***namelist, for( i = 0; i < num; i++ ) free( tab[i] ); - if( tab != NULL ) - free( tab ); + free( tab ); } } return -1;