1 /*****************************************************************************
2 * libc.c: Extra libc function for some systems.
3 *****************************************************************************
4 * Copyright (C) 2002-2006 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Christophe Massiot <massiot@via.ecp.fr>
12 * Rémi Denis-Courmont <rem à videolan.org>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
27 *****************************************************************************/
28 #include <string.h> /* strdup() */
39 #if defined(HAVE_ICONV)
48 # include <sys/time.h>
51 # include <sys/wait.h>
54 #if defined(WIN32) || defined(UNDER_CE)
58 # define WIN32_LEAN_AND_MEAN
63 # define strcoll strcmp
66 /*****************************************************************************
67 * getenv: just in case, but it should never be called
68 *****************************************************************************/
69 #if !defined( HAVE_GETENV )
70 char *vlc_getenv( const char *name )
76 /*****************************************************************************
77 * strdup: returns a malloc'd copy of a string
78 *****************************************************************************/
79 #if !defined( HAVE_STRDUP )
80 char *vlc_strdup( const char *string )
82 return strndup( string, strlen( string ) );
86 /*****************************************************************************
87 * strndup: returns a malloc'd copy of at most n bytes of string
88 * Does anyone know whether or not it will be present in Jaguar?
89 *****************************************************************************/
90 #if !defined( HAVE_STRNDUP )
91 char *vlc_strndup( const char *string, size_t n )
94 size_t len = strlen( string );
96 len = __MIN( len, n );
97 psz = (char*)malloc( len + 1 );
101 memcpy( (void*)psz, (const void*)string, len );
109 /*****************************************************************************
110 * strcasecmp: compare two strings ignoring case
111 *****************************************************************************/
112 #if !defined( HAVE_STRCASECMP ) && !defined( HAVE_STRICMP )
113 int vlc_strcasecmp( const char *s1, const char *s2 )
116 if( !s1 || !s2 ) return -1;
123 if( c1 != c2 ) return (c1 < c2 ? -1 : 1);
127 if( !*s1 && !*s2 ) return 0;
128 else return (*s1 ? 1 : -1);
132 /*****************************************************************************
133 * strncasecmp: compare n chars from two strings ignoring case
134 *****************************************************************************/
135 #if !defined( HAVE_STRNCASECMP ) && !defined( HAVE_STRNICMP )
136 int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
139 if( !s1 || !s2 ) return -1;
141 while( n > 0 && *s1 && *s2 )
146 if( c1 != c2 ) return (c1 < c2 ? -1 : 1);
150 if( !n || (!*s1 && !*s2) ) return 0;
151 else return (*s1 ? 1 : -1);
155 /******************************************************************************
156 * strcasestr: find a substring (little) in another substring (big)
157 * Case sensitive. Return NULL if not found, return big if little == null
158 *****************************************************************************/
159 #if !defined( HAVE_STRCASESTR ) && !defined( HAVE_STRISTR )
160 char * vlc_strcasestr( const char *psz_big, const char *psz_little )
162 char *p_pos = (char *)psz_big;
164 if( !psz_big || !psz_little || !*psz_little ) return p_pos;
168 if( toupper( *p_pos ) == toupper( *psz_little ) )
170 char * psz_cur1 = p_pos + 1;
171 char * psz_cur2 = (char *)psz_little + 1;
172 while( *psz_cur1 && *psz_cur2 &&
173 toupper( *psz_cur1 ) == toupper( *psz_cur2 ) )
178 if( !*psz_cur2 ) return p_pos;
186 /*****************************************************************************
188 *****************************************************************************/
189 #if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
190 int vlc_vasprintf(char **strp, const char *fmt, va_list ap)
192 /* Guess we need no more than 100 bytes. */
194 char *p = malloc( i_size );
205 /* Try to print in the allocated space. */
206 n = vsnprintf( p, i_size, fmt, ap );
208 /* If that worked, return the string. */
209 if (n > -1 && n < i_size)
214 /* Else try again with more space. */
215 if (n > -1) /* glibc 2.1 */
217 i_size = n+1; /* precisely what is needed */
221 i_size *= 2; /* twice the old size */
223 if( (p = realloc( p, i_size ) ) == NULL)
232 /*****************************************************************************
234 *****************************************************************************/
235 #if !defined(HAVE_ASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
236 int vlc_asprintf( char **strp, const char *fmt, ... )
241 va_start( args, fmt );
242 i_ret = vasprintf( strp, fmt, args );
249 /*****************************************************************************
250 * atof: convert a string to a double.
251 *****************************************************************************/
252 #if !defined( HAVE_ATOF )
253 double vlc_atof( const char *nptr )
257 int i_len = strlen( nptr ) + 1;
259 psz_tmp = malloc( i_len * sizeof(wchar_t) );
260 MultiByteToWideChar( CP_ACP, 0, nptr, -1, psz_tmp, i_len );
261 f_result = wcstod( psz_tmp, NULL );
268 /*****************************************************************************
269 * strtoll: convert a string to a 64 bits int.
270 *****************************************************************************/
271 #if !defined( HAVE_STRTOLL )
272 int64_t vlc_strtoll( const char *nptr, char **endptr, int base )
275 int sign = 1, newbase = base ? base : 10;
277 while( isspace(*nptr) ) nptr++;
285 /* Try to detect base */
298 if( base && newbase != base )
300 if( endptr ) *endptr = (char *)nptr;
307 while( *nptr >= '0' && *nptr <= '9' )
310 i_value += ( *nptr++ - '0' );
312 if( endptr ) *endptr = (char *)nptr;
316 while( (*nptr >= '0' && *nptr <= '9') ||
317 (*nptr >= 'a' && *nptr <= 'f') ||
318 (*nptr >= 'A' && *nptr <= 'F') )
321 if(*nptr >= '0' && *nptr <= '9') i_valc = *nptr - '0';
322 else if(*nptr >= 'a' && *nptr <= 'f') i_valc = *nptr - 'a' +10;
323 else if(*nptr >= 'A' && *nptr <= 'F') i_valc = *nptr - 'A' +10;
328 if( endptr ) *endptr = (char *)nptr;
332 i_value = strtol( nptr, endptr, newbase );
336 return i_value * sign;
340 /*****************************************************************************
341 * atoll: convert a string to a 64 bits int.
342 *****************************************************************************/
343 #if !defined( HAVE_ATOLL )
344 int64_t vlc_atoll( const char *nptr )
346 return strtoll( nptr, (char **)NULL, 10 );
350 /*****************************************************************************
351 * lldiv: returns quotient and remainder
352 *****************************************************************************/
353 #if defined(SYS_BEOS) \
354 || (defined (__FreeBSD__) && (__FreeBSD__ < 5))
355 lldiv_t vlc_lldiv( long long numer, long long denom )
358 d.quot = numer / denom;
359 d.rem = numer % denom;
366 * Copy a string to a sized buffer. The result is always nul-terminated
367 * (contrary to strncpy()).
369 * @param dest destination buffer
370 * @param src string to be copied
371 * @param len maximum number of characters to be copied plus one for the
374 * @return strlen(src)
377 extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize)
381 for (length = 1; (length < bufsize) && *src; length++)
394 /*****************************************************************************
395 * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters
396 * when called with an empty argument or just '\'
397 *****************************************************************************/
398 #if defined(WIN32) && !defined(UNDER_CE)
401 typedef struct vlc_DIR
405 struct _wdirent dd_dir;
406 vlc_bool_t b_insert_back;
409 void *vlc_wopendir( const wchar_t *wpath )
414 if ( wpath == NULL || wpath[0] == '\0'
415 || (wcscmp (wpath, L"\\") == 0) )
417 /* Special mode to list drive letters */
418 p_dir = malloc( sizeof(vlc_DIR) );
419 p_dir->p_real_dir = NULL;
420 p_dir->i_drives = GetLogicalDrives();
421 return (void *)p_dir;
424 p_real_dir = _wopendir( wpath );
425 if ( p_real_dir == NULL )
428 p_dir = malloc( sizeof(vlc_DIR) );
429 p_dir->p_real_dir = p_real_dir;
431 assert (wpath[0]); // wpath[1] is defined
432 p_dir->b_insert_back = !wcscmp (wpath + 1, L":\\");
433 return (void *)p_dir;
436 struct _wdirent *vlc_wreaddir( void *_p_dir )
438 vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
442 if ( p_dir->p_real_dir != NULL )
444 if ( p_dir->b_insert_back )
446 /* Adds "..", gruik! */
447 p_dir->dd_dir.d_ino = 0;
448 p_dir->dd_dir.d_reclen = 0;
449 p_dir->dd_dir.d_namlen = 2;
450 wcscpy( p_dir->dd_dir.d_name, L".." );
451 p_dir->b_insert_back = VLC_FALSE;
452 return &p_dir->dd_dir;
455 return _wreaddir( p_dir->p_real_dir );
458 /* Drive letters mode */
459 i_drives = p_dir->i_drives;
461 return NULL; /* end */
463 for ( i = 0; i < sizeof(DWORD)*8; i++, i_drives >>= 1 )
464 if ( i_drives & 1 ) break;
467 return NULL; /* this should not happen */
469 swprintf( p_dir->dd_dir.d_name, L"%c:\\", 'A' + i );
470 p_dir->dd_dir.d_namlen = wcslen(p_dir->dd_dir.d_name);
471 p_dir->i_drives &= ~(1UL << i);
472 return &p_dir->dd_dir;
475 int vlc_wclosedir( void *_p_dir )
477 vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
480 if ( p_dir->p_real_dir != NULL )
481 i_ret = _wclosedir( p_dir->p_real_dir );
488 /*****************************************************************************
489 * scandir: scan a directory alpha-sorted
490 *****************************************************************************/
491 #if !defined( HAVE_SCANDIR )
492 /* FIXME: I suspect this is dead code -> utf8_scandir */
498 int vlc_alphasort( const struct dirent **a, const struct dirent **b )
500 return strcoll( (*a)->d_name, (*b)->d_name );
503 int vlc_scandir( const char *name, struct dirent ***namelist,
504 int (*filter) ( const struct dirent * ),
505 int (*compar) ( const struct dirent **,
506 const struct dirent ** ) )
509 struct dirent * p_content;
510 struct dirent ** pp_list;
513 if( !namelist || !( p_dir = opendir( name ) ) ) return -1;
517 while( ( p_content = readdir( p_dir ) ) )
519 if( filter && !filter( p_content ) )
523 pp_list = realloc( pp_list, ( ret + 1 ) * sizeof( struct dirent * ) );
524 size = sizeof( struct dirent ) + strlen( p_content->d_name ) + 1;
525 pp_list[ret] = malloc( size );
526 memcpy( pp_list[ret], p_content, size );
534 qsort( pp_list, ret, sizeof( struct dirent * ),
535 (int (*)(const void *, const void *)) compar );
543 #if defined (WIN32) || !defined (HAVE_SHARED_LIBVLC)
544 /*****************************************************************************
545 * dgettext: gettext for plugins.
546 *****************************************************************************/
547 char *vlc_dgettext( const char *package, const char *msgid )
549 #if defined( ENABLE_NLS ) \
550 && ( defined(HAVE_GETTEXT) || defined(HAVE_INCLUDED_GETTEXT) )
551 return dgettext( package, msgid );
553 return (char *)msgid;
558 /*****************************************************************************
559 * count_utf8_string: returns the number of characters in the string.
560 *****************************************************************************/
561 static int count_utf8_string( const char *psz_string )
563 int i = 0, i_count = 0;
564 while( psz_string[ i ] != 0 )
566 if( ((unsigned char *)psz_string)[ i ] < 0x80UL ) i_count++;
572 /*****************************************************************************
573 * wraptext: inserts \n at convenient places to wrap the text.
574 * Returns the modified string in a new buffer.
575 *****************************************************************************/
576 char *vlc_wraptext( const char *psz_text, int i_line )
579 char *psz_line, *psz_new_text;
581 psz_line = psz_new_text = strdup( psz_text );
583 i_len = count_utf8_string( psz_text );
585 while( i_len > i_line )
587 /* Look if there is a newline somewhere. */
588 char *psz_parser = psz_line;
590 while( i_count <= i_line && *psz_parser != '\n' )
592 while( *((unsigned char *)psz_parser) >= 0x80UL ) psz_parser++;
596 if( *psz_parser == '\n' )
598 i_len -= (i_count + 1);
599 psz_line = psz_parser + 1;
603 /* Find the furthest space. */
604 while( psz_parser > psz_line && *psz_parser != ' ' )
606 while( *((unsigned char *)psz_parser) >= 0x80UL ) psz_parser--;
610 if( *psz_parser == ' ' )
613 i_len -= (i_count + 1);
614 psz_line = psz_parser + 1;
618 /* Wrapping has failed. Find the first space or newline */
619 while( i_count < i_len && *psz_parser != ' ' && *psz_parser != '\n' )
621 while( *((unsigned char *)psz_parser) >= 0x80UL ) psz_parser++;
625 if( i_count < i_len ) *psz_parser = '\n';
626 i_len -= (i_count + 1);
627 psz_line = psz_parser + 1;
633 /*****************************************************************************
635 *****************************************************************************/
636 vlc_iconv_t vlc_iconv_open( const char *tocode, const char *fromcode )
638 #if defined(HAVE_ICONV)
639 return iconv_open( tocode, fromcode );
645 size_t vlc_iconv( vlc_iconv_t cd, const char **inbuf, size_t *inbytesleft,
646 char **outbuf, size_t *outbytesleft )
648 #if defined(HAVE_ICONV)
649 return iconv( cd, (ICONV_CONST char **)inbuf, inbytesleft,
650 outbuf, outbytesleft );
654 if (inbytesleft == NULL || outbytesleft == NULL)
659 i_bytes = __MIN(*inbytesleft, *outbytesleft);
660 if( !inbuf || !outbuf || !i_bytes ) return (size_t)(-1);
661 memcpy( *outbuf, *inbuf, i_bytes );
664 inbytesleft -= i_bytes;
665 outbytesleft -= i_bytes;
670 int vlc_iconv_close( vlc_iconv_t cd )
672 #if defined(HAVE_ICONV)
673 return iconv_close( cd );
679 /*****************************************************************************
681 * (adapted from libavcodec, author Michael Niedermayer <michaelni@gmx.at>)
682 *****************************************************************************/
683 vlc_bool_t vlc_ureduce( unsigned *pi_dst_nom, unsigned *pi_dst_den,
684 uint64_t i_nom, uint64_t i_den, uint64_t i_max )
686 vlc_bool_t b_exact = 1;
696 i_gcd = GCD( i_nom, i_den );
700 if( i_max == 0 ) i_max = I64C(0xFFFFFFFF);
702 if( i_nom > i_max || i_den > i_max )
704 uint64_t i_a0_num = 0, i_a0_den = 1, i_a1_num = 1, i_a1_den = 0;
709 uint64_t i_x = i_nom / i_den;
710 uint64_t i_a2n = i_x * i_a1_num + i_a0_num;
711 uint64_t i_a2d = i_x * i_a1_den + i_a0_den;
713 if( i_a2n > i_max || i_a2d > i_max ) break;
717 i_a0_num = i_a1_num; i_a0_den = i_a1_den;
718 i_a1_num = i_a2n; i_a1_den = i_a2d;
719 if( i_nom == 0 ) break;
720 i_x = i_nom; i_nom = i_den; i_den = i_x;
732 /*************************************************************************
733 * vlc_parse_cmdline: Command line parsing into elements.
735 * The command line is composed of space/tab separated arguments.
736 * Quotes can be used as argument delimiters and a backslash can be used to
738 *************************************************************************/
739 static void find_end_quote( char **s, char **ppsz_parser, int i_quote )
748 (*ppsz_parser)++; (*s)++;
751 else if( **s == '"' || **s == '\'' )
753 /* Preceeded by a number of '\' which we erase. */
754 *ppsz_parser -= i_bcount / 2;
757 /* '\\' followed by a '"' or '\'' */
760 (*ppsz_parser)++; (*s)++;
772 /* Different quoting */
775 (*ppsz_parser)++; (*s)++;
776 find_end_quote( s, ppsz_parser, i_quote );
778 (*ppsz_parser)++; (*s)++;
785 /* A regular character */
787 (*ppsz_parser)++; (*s)++;
793 char **vlc_parse_cmdline( const char *psz_cmdline, int *i_args )
797 char *s, *psz_parser, *psz_arg, *psz_orig;
800 if( !psz_cmdline ) return 0;
801 psz_orig = strdup( psz_cmdline );
802 psz_arg = psz_parser = s = psz_orig;
806 if( *s == '\t' || *s == ' ' )
808 /* We have a complete argument */
810 TAB_APPEND( argc, argv, strdup(psz_arg) );
812 /* Skip trailing spaces/tabs */
813 do{ s++; } while( *s == '\t' || *s == ' ' );
816 psz_arg = psz_parser = s;
819 else if( *s == '\\' )
821 *psz_parser++ = *s++;
824 else if( *s == '"' || *s == '\'' )
826 if( ( i_bcount & 1 ) == 0 )
828 /* Preceeded by an even number of '\', this is half that
829 * number of '\', plus a quote which we erase. */
831 psz_parser -= i_bcount / 2;
833 find_end_quote( &s, &psz_parser, i_quote );
838 /* Preceeded by an odd number of '\', this is half that
839 * number of '\' followed by a '"' */
840 psz_parser = psz_parser - i_bcount/2 - 1;
848 /* A regular character */
849 *psz_parser++ = *s++;
854 /* Take care of the last arg */
858 TAB_APPEND( argc, argv, strdup(psz_arg) );
861 if( i_args ) *i_args = argc;
866 /*************************************************************************
867 * vlc_execve: Execute an external program with a given environment,
868 * wait until it finishes and return its standard output
869 *************************************************************************/
870 int __vlc_execve( vlc_object_t *p_object, int i_argc, char **ppsz_argv,
871 char **ppsz_env, char *psz_cwd, char *p_in, int i_in,
872 char **pp_data, int *pi_data )
882 if ( (i_child_pid = fork()) == -1 )
884 msg_Err( p_object, "unable to fork (%s)", strerror(errno) );
888 if ( i_child_pid == 0 )
900 if ( psz_cwd != NULL )
902 execve( ppsz_argv[0], ppsz_argv, ppsz_env );
909 close( pi_stdin[0] );
912 *pp_data = malloc( 1025 ); /* +1 for \0 */
914 while ( !p_object->b_die )
917 fd_set readfds, writefds;
921 FD_ZERO( &writefds );
922 FD_SET( pi_stdout[0], &readfds );
924 FD_SET( pi_stdin[0], &writefds );
929 i_ret = select( pi_stdin[0] > pi_stdout[0] ? pi_stdin[0] + 1 :
930 pi_stdout[0] + 1, &readfds, &writefds, NULL, &tv );
933 if ( FD_ISSET( pi_stdout[0], &readfds ) )
935 ssize_t i_read = read( pi_stdout[0], &(*pp_data)[*pi_data],
940 *pp_data = realloc( *pp_data, *pi_data + 1025 );
943 if ( FD_ISSET( pi_stdin[0], &writefds ) )
945 ssize_t i_write = write( pi_stdin[0], p_in, __MIN(i_in, 1024) );
953 close( pi_stdin[0] );
957 if ( waitpid( i_child_pid, &i_status, WNOHANG ) == i_child_pid )
959 if ( WIFEXITED( i_status ) )
961 if ( WEXITSTATUS( i_status ) )
964 "child %s returned with error code %d",
965 ppsz_argv[0], WEXITSTATUS( i_status ) );
970 if ( WIFSIGNALED( i_status ) )
973 "child %s quit on signal %d", ppsz_argv[0],
974 WTERMSIG( i_status ) );
978 close( pi_stdin[0] );
979 close( pi_stdout[0] );
983 if ( i_ret < 0 && errno != EINTR )
985 msg_Warn( p_object, "select failed (%s)", strerror(errno) );
989 #elif defined( WIN32 ) && !defined( UNDER_CE )
990 SECURITY_ATTRIBUTES saAttr;
991 PROCESS_INFORMATION piProcInfo;
992 STARTUPINFO siStartInfo;
993 BOOL bFuncRetn = FALSE;
994 HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr;
996 char *psz_cmd, *p_env, *p;
1000 /* Set the bInheritHandle flag so pipe handles are inherited. */
1001 saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
1002 saAttr.bInheritHandle = TRUE;
1003 saAttr.lpSecurityDescriptor = NULL;
1005 /* Create a pipe for the child process's STDOUT. */
1006 if ( !CreatePipe( &hChildStdoutRd, &hChildStdoutWr, &saAttr, 0 ) )
1008 msg_Err( p_object, "stdout pipe creation failed" );
1012 /* Ensure the read handle to the pipe for STDOUT is not inherited. */
1013 SetHandleInformation( hChildStdoutRd, HANDLE_FLAG_INHERIT, 0 );
1015 /* Create a pipe for the child process's STDIN. */
1016 if ( !CreatePipe( &hChildStdinRd, &hChildStdinWr, &saAttr, 0 ) )
1018 msg_Err( p_object, "stdin pipe creation failed" );
1022 /* Ensure the write handle to the pipe for STDIN is not inherited. */
1023 SetHandleInformation( hChildStdinWr, HANDLE_FLAG_INHERIT, 0 );
1025 /* Set up members of the PROCESS_INFORMATION structure. */
1026 ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
1028 /* Set up members of the STARTUPINFO structure. */
1029 ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
1030 siStartInfo.cb = sizeof(STARTUPINFO);
1031 siStartInfo.hStdError = hChildStdoutWr;
1032 siStartInfo.hStdOutput = hChildStdoutWr;
1033 siStartInfo.hStdInput = hChildStdinRd;
1034 siStartInfo.wShowWindow = SW_HIDE;
1035 siStartInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
1037 /* Set up the command line. */
1038 psz_cmd = malloc(32768);
1041 ppsz_parser = &ppsz_argv[0];
1042 while ( ppsz_parser[0] != NULL && i_size > 0 )
1044 /* Protect the last argument with quotes ; the other arguments
1045 * are supposed to be already protected because they have been
1046 * passed as a command-line option. */
1047 if ( ppsz_parser[1] == NULL )
1049 strncat( psz_cmd, "\"", i_size );
1052 strncat( psz_cmd, *ppsz_parser, i_size );
1053 i_size -= strlen( *ppsz_parser );
1054 if ( ppsz_parser[1] == NULL )
1056 strncat( psz_cmd, "\"", i_size );
1059 strncat( psz_cmd, " ", i_size );
1064 /* Set up the environment. */
1065 p = p_env = malloc(32768);
1067 ppsz_parser = &ppsz_env[0];
1068 while ( *ppsz_parser != NULL && i_size > 0 )
1070 memcpy( p, *ppsz_parser,
1071 __MIN((int)(strlen(*ppsz_parser) + 1), i_size) );
1072 p += strlen(*ppsz_parser) + 1;
1073 i_size -= strlen(*ppsz_parser) + 1;
1078 /* Create the child process. */
1079 bFuncRetn = CreateProcess( NULL,
1080 psz_cmd, // command line
1081 NULL, // process security attributes
1082 NULL, // primary thread security attributes
1083 TRUE, // handles are inherited
1084 0, // creation flags
1087 &siStartInfo, // STARTUPINFO pointer
1088 &piProcInfo ); // receives PROCESS_INFORMATION
1093 if ( bFuncRetn == 0 )
1095 msg_Err( p_object, "child creation failed" );
1099 /* Read from a file and write its contents to a pipe. */
1100 while ( i_in > 0 && !p_object->b_die )
1103 if ( !WriteFile( hChildStdinWr, p_in, i_in, &i_written, NULL ) )
1109 /* Close the pipe handle so the child process stops reading. */
1110 CloseHandle(hChildStdinWr);
1112 /* Close the write end of the pipe before reading from the
1113 * read end of the pipe. */
1114 CloseHandle(hChildStdoutWr);
1116 /* Read output from the child process. */
1118 *pp_data = malloc( 1025 ); /* +1 for \0 */
1120 while ( !p_object->b_die )
1123 if ( !ReadFile( hChildStdoutRd, &(*pp_data)[*pi_data], 1024, &i_read,
1128 *pp_data = realloc( *pp_data, *pi_data + 1025 );
1131 while ( !p_object->b_die
1132 && !GetExitCodeProcess( piProcInfo.hProcess, &i_status )
1133 && i_status != STILL_ACTIVE )
1136 CloseHandle(piProcInfo.hProcess);
1137 CloseHandle(piProcInfo.hThread);
1141 "child %s returned with error code %ld",
1142 ppsz_argv[0], i_status );
1145 msg_Err( p_object, "vlc_execve called but no implementation is available" );
1150 (*pp_data)[*pi_data] = '\0';