]> git.sesse.net Git - vlc/blobdiff - src/extras/libc.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / extras / libc.c
index 60c7139abfca8695a6635397cf6457a5463a11cd..d9aad6b4ea418892310af830e49cbebe0edd4809 100644 (file)
@@ -31,8 +31,7 @@
 
 #include <vlc_common.h>
 
-#include <ctype.h>
-
+#include <errno.h>
 
 #undef iconv_t
 #undef iconv_open
 #   include <iconv.h>
 #endif
 
-#ifdef HAVE_DIRENT_H
-#   include <dirent.h>
-#endif
-
-#include <signal.h>
-
 #ifdef HAVE_FORK
-#   include <sys/time.h>
+#   include <signal.h>
 #   include <unistd.h>
-#   include <errno.h>
 #   include <sys/wait.h>
-#   include <fcntl.h>
 #   include <sys/socket.h>
 #   include <sys/poll.h>
 #   ifndef PF_LOCAL
 #endif
 
 #if defined(WIN32) || defined(UNDER_CE)
-#   undef _wopendir
-#   undef _wreaddir
-#   undef _wclosedir
-#   undef rewinddir
 #   define WIN32_LEAN_AND_MEAN
 #   include <windows.h>
+#   include <dirent.h>
 #endif
 
 /*****************************************************************************
@@ -175,12 +163,10 @@ void vlc_rewinddir( void *_p_dir )
     if ( p_dir->p_real_dir != NULL )
         _wrewinddir( p_dir->p_real_dir );
 }
-#endif
 
 /* This one is in the libvlccore exported symbol list */
 int vlc_wclosedir( void *_p_dir )
 {
-#if defined(WIN32)
     vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
     int i_ret = 0;
 
@@ -189,10 +175,9 @@ int vlc_wclosedir( void *_p_dir )
 
     free( p_dir );
     return i_ret;
-#else
-    return closedir( _p_dir );
-#endif
 }
+#endif
+
 
 #ifdef ENABLE_NLS
 # include <libintl.h>
@@ -204,6 +189,8 @@ int vlc_wclosedir( void *_p_dir )
 char *vlc_gettext( const char *msgid )
 {
 #ifdef ENABLE_NLS
+    if( unlikely(!*msgid))
+        return (char *)"";
     return dgettext( PACKAGE_NAME, msgid );
 #else
     return (char *)msgid;
@@ -587,14 +574,15 @@ bool vlc_ureduce( unsigned *pi_dst_nom, unsigned *pi_dst_den,
     return b_exact;
 }
 
+#undef vlc_execve
 /*************************************************************************
  * vlc_execve: Execute an external program with a given environment,
  * wait until it finishes and return its standard output
  *************************************************************************/
-int __vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
-                  char *const *ppsz_env, const char *psz_cwd,
-                  const char *p_in, size_t i_in,
-                  char **pp_data, size_t *pi_data )
+int vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
+                char *const *ppsz_env, const char *psz_cwd,
+                const char *p_in, size_t i_in,
+                char **pp_data, size_t *pi_data )
 {
     (void)i_argc; // <-- hmph
 #ifdef HAVE_FORK
@@ -625,13 +613,11 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
             /* NOTE:
              * Like it or not, close can fail (and not only with EBADF)
              */
-            if ((close (0) == 0) && (close (1) == 0) && (close (2) == 0)
-             && (dup (fds[1]) == 0) && (dup (fds[1]) == 1)
-             && (open ("/dev/null", O_RDONLY) == 2)
+            if ((dup2 (fds[1], 0) == 0) && (dup2 (fds[1], 1) == 1)
              && ((psz_cwd == NULL) || (chdir (psz_cwd) == 0)))
                 execve (ppsz_argv[0], ppsz_argv, ppsz_env);
 
-            exit (EXIT_FAILURE);
+            _exit (EXIT_FAILURE);
         }
     }
 
@@ -866,7 +852,7 @@ int __vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
               || i_read == 0 )
             break;
         *pi_data += i_read;
-        *pp_data = realloc( *pp_data, *pi_data + 1025 );
+        *pp_data = xrealloc( *pp_data, *pi_data + 1025 );
     }
 
     while ( !p_object->b_die