* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
-#include <string.h> /* strdup() */
-#include <stdlib.h>
#include <ctype.h>
# include <dirent.h>
#endif
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
#ifdef HAVE_FORK
# include <sys/time.h>
# include <unistd.h>
# undef _wreaddir
# undef _wclosedir
# undef rewinddir
-# undef seekdir
-# undef telldir
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#endif
/*****************************************************************************
- * strnlen:
+ * strnlen:
*****************************************************************************/
#if !defined( HAVE_STRNLEN )
size_t vlc_strnlen( const char *psz, size_t n )
{
const char *psz_end = memchr( psz, 0, n );
- return psz_end ? ( psz_end - psz ) : n;
+ return psz_end ? (size_t)( psz_end - psz ) : n;
}
#endif
if( !psz_big || !psz_little || !*psz_little ) return p_pos;
- while( *p_pos )
+ while( *p_pos )
{
if( toupper( *p_pos ) == toupper( *psz_little ) )
{
/*****************************************************************************
* lldiv: returns quotient and remainder
*****************************************************************************/
-#if defined(SYS_BEOS) \
- || (defined (__FreeBSD__) && (__FreeBSD__ < 5))
+#if !defined( HAVE_LLDIV )
lldiv_t vlc_lldiv( long long numer, long long denom )
{
lldiv_t d;
_WDIR *p_real_dir;
int i_drives;
struct _wdirent dd_dir;
- vlc_bool_t b_insert_back;
+ bool b_insert_back;
} vlc_DIR;
void *vlc_wopendir( const wchar_t *wpath )
p_dir->dd_dir.d_reclen = 0;
p_dir->dd_dir.d_namlen = 2;
wcscpy( p_dir->dd_dir.d_name, L".." );
- p_dir->b_insert_back = VLC_FALSE;
+ p_dir->b_insert_back = false;
return &p_dir->dd_dir;
}
if ( p_dir->p_real_dir != NULL )
_wrewinddir( p_dir->p_real_dir );
}
-
-void vlc_seekdir( void *_p_dir, long loc)
-{
- vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
-
- if ( p_dir->p_real_dir != NULL )
- _wseekdir( p_dir->p_real_dir, loc );
-}
-
-long vlc_telldir( void *_p_dir )
-{
- vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
-
- if ( p_dir->p_real_dir != NULL )
- return _wtelldir( p_dir->p_real_dir );
- return 0;
-}
#endif
/*****************************************************************************
}
#endif
-#if defined (WIN32) || !defined (HAVE_SHARED_LIBVLC)
-/*****************************************************************************
- * dgettext: gettext for plugins.
- *****************************************************************************/
+#if defined (WIN32)
+/**
+ * gettext callbacks for plugins.
+ * LibVLC links libintl statically on Windows.
+ */
char *vlc_dgettext( const char *package, const char *msgid )
{
-#if defined( ENABLE_NLS ) \
- && ( defined(HAVE_GETTEXT) || defined(HAVE_INCLUDED_GETTEXT) )
return dgettext( package, msgid );
-#else
- return (char *)msgid;
-#endif
}
#endif
+/**
+ * In-tree plugins share their gettext domain with LibVLC.
+ */
+char *vlc_gettext( const char *msgid )
+{
+ return dgettext( PACKAGE_NAME, msgid );
+}
+
/*****************************************************************************
* count_utf8_string: returns the number of characters in the string.
*****************************************************************************/
* reduce a fraction
* (adapted from libavcodec, author Michael Niedermayer <michaelni@gmx.at>)
*****************************************************************************/
-vlc_bool_t vlc_ureduce( unsigned *pi_dst_nom, unsigned *pi_dst_den,
+bool vlc_ureduce( unsigned *pi_dst_nom, unsigned *pi_dst_den,
uint64_t i_nom, uint64_t i_den, uint64_t i_max )
{
- vlc_bool_t b_exact = 1;
+ bool b_exact = 1;
uint64_t i_gcd;
if( i_den == 0 )
i_nom /= i_gcd;
i_den /= i_gcd;
- if( i_max == 0 ) i_max = I64C(0xFFFFFFFF);
+ if( i_max == 0 ) i_max = INT64_C(0xFFFFFFFF);
if( i_nom > i_max || i_den > i_max )
{
return b_exact;
}
-/*************************************************************************
- * vlc_parse_cmdline: Command line parsing into elements.
- *
- * The command line is composed of space/tab separated arguments.
- * Quotes can be used as argument delimiters and a backslash can be used to
- * escape a quote.
- *************************************************************************/
-static void find_end_quote( char **s, char **ppsz_parser, int i_quote )
-{
- int i_bcount = 0;
-
- while( **s )
- {
- if( **s == '\\' )
- {
- **ppsz_parser = **s;
- (*ppsz_parser)++; (*s)++;
- i_bcount++;
- }
- else if( **s == '"' || **s == '\'' )
- {
- /* Preceeded by a number of '\' which we erase. */
- *ppsz_parser -= i_bcount / 2;
- if( i_bcount & 1 )
- {
- /* '\\' followed by a '"' or '\'' */
- *ppsz_parser -= 1;
- **ppsz_parser = **s;
- (*ppsz_parser)++; (*s)++;
- i_bcount = 0;
- continue;
- }
-
- if( **s == i_quote )
- {
- /* End */
- return;
- }
- else
- {
- /* Different quoting */
- int i_quote = **s;
- **ppsz_parser = **s;
- (*ppsz_parser)++; (*s)++;
- find_end_quote( s, ppsz_parser, i_quote );
- **ppsz_parser = **s;
- (*ppsz_parser)++; (*s)++;
- }
-
- i_bcount = 0;
- }
- else
- {
- /* A regular character */
- **ppsz_parser = **s;
- (*ppsz_parser)++; (*s)++;
- i_bcount = 0;
- }
- }
-}
-
-char **vlc_parse_cmdline( const char *psz_cmdline, int *i_args )
-{
- int argc = 0;
- char **argv = 0;
- char *s, *psz_parser, *psz_arg, *psz_orig;
- int i_bcount = 0;
-
- if( !psz_cmdline ) return 0;
- psz_orig = strdup( psz_cmdline );
- psz_arg = psz_parser = s = psz_orig;
-
- while( *s )
- {
- if( *s == '\t' || *s == ' ' )
- {
- /* We have a complete argument */
- *psz_parser = 0;
- TAB_APPEND( argc, argv, strdup(psz_arg) );
-
- /* Skip trailing spaces/tabs */
- do{ s++; } while( *s == '\t' || *s == ' ' );
-
- /* New argument */
- psz_arg = psz_parser = s;
- i_bcount = 0;
- }
- else if( *s == '\\' )
- {
- *psz_parser++ = *s++;
- i_bcount++;
- }
- else if( *s == '"' || *s == '\'' )
- {
- if( ( i_bcount & 1 ) == 0 )
- {
- /* Preceeded by an even number of '\', this is half that
- * number of '\', plus a quote which we erase. */
- int i_quote = *s;
- psz_parser -= i_bcount / 2;
- s++;
- find_end_quote( &s, &psz_parser, i_quote );
- s++;
- }
- else
- {
- /* Preceeded by an odd number of '\', this is half that
- * number of '\' followed by a '"' */
- psz_parser = psz_parser - i_bcount/2 - 1;
- *psz_parser++ = '"';
- s++;
- }
- i_bcount = 0;
- }
- else
- {
- /* A regular character */
- *psz_parser++ = *s++;
- i_bcount = 0;
- }
- }
-
- /* Take care of the last arg */
- if( *psz_arg )
- {
- *psz_parser = '\0';
- TAB_APPEND( argc, argv, strdup(psz_arg) );
- }
-
- if( i_args ) *i_args = argc;
- free( psz_orig );
- return argv;
-}
-
/*************************************************************************
* vlc_execve: Execute an external program with a given environment,
* wait until it finishes and return its standard output
switch (pid)
{
case -1:
- msg_Err (p_object, "unable to fork (%s)", strerror (errno));
+ msg_Err (p_object, "unable to fork (%m)");
close (fds[0]);
close (fds[1]);
return -1;
case 0:
+ {
+ sigset_t set;
+ sigemptyset (&set);
+ pthread_sigmask (SIG_SETMASK, &set, NULL);
+
/* NOTE:
* Like it or not, close can fail (and not only with EBADF)
*/
&& ((psz_cwd == NULL) || (chdir (psz_cwd) == 0)))
execve (ppsz_argv[0], ppsz_argv, ppsz_env);
- exit (1);
+ exit (EXIT_FAILURE);
+ }
}
close (fds[1]);