}
}
*out = '\0';
- EnsureUTF8( psz );
return psz;
}
assert (0);
}
+static void format_duration (char *buf, size_t len, int64_t duration)
+{
+ lldiv_t d;
+ int sec;
+
+ duration /= CLOCK_FREQ;
+ d = lldiv (duration, 60);
+ sec = d.rem;
+ d = lldiv (d.quot, 60);
+ snprintf (buf, len, "%02lld:%02d:%02d", d.quot, (int)d.rem, sec);
+}
+
#define INSERT_STRING( string ) \
if( string != NULL ) \
{ \
vlc_mutex_unlock( &p_item->p_stats->lock );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'g':
var_GetInteger( p_input, "bit-rate" )/1000 );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'C':
var_GetInteger( p_input, "chapter" ) );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'D':
if( p_item )
{
mtime_t i_duration = input_item_GetDuration( p_item );
- snprintf( buf, 10, "%02d:%02d:%02d",
- (int)(i_duration/(3600000000)),
- (int)((i_duration/(60000000))%60),
- (int)((i_duration/1000000)%60) );
+ format_duration (buf, sizeof (buf), i_duration);
}
else
- {
- snprintf( buf, 10, b_empty_if_na ? "" : "--:--:--" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "--:--:--" );
INSERT_STRING_NO_FREE( buf );
break;
case 'F':
var_GetInteger( p_input, "title" ) );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'L':
{
mtime_t i_duration = input_item_GetDuration( p_item );
int64_t i_time = var_GetTime( p_input, "time" );
- snprintf( buf, 10, "%02d:%02d:%02d",
- (int)( ( i_duration - i_time ) / 3600000000 ),
- (int)( ( ( i_duration - i_time ) / 60000000 ) % 60 ),
- (int)( ( ( i_duration - i_time ) / 1000000 ) % 60 ) );
+ format_duration( buf, sizeof(buf),
+ i_duration - i_time );
}
else
- {
- snprintf( buf, 10, b_empty_if_na ? "" : "--:--:--" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "--:--:--" );
INSERT_STRING_NO_FREE( buf );
break;
case 'N':
snprintf( buf, 10, "%.3f", f );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'S':
snprintf( buf, 10, "%d.%d", r/1000, (r/100)%10 );
}
else
- {
- sprintf( buf, b_empty_if_na ? "" : "-" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "-" );
INSERT_STRING_NO_FREE( buf );
break;
case 'T':
if( p_input )
{
int64_t i_time = var_GetTime( p_input, "time" );
- snprintf( buf, 10, "%02d:%02d:%02d",
- (int)( i_time / ( 3600000000 ) ),
- (int)( ( i_time / ( 60000000 ) ) % 60 ),
- (int)( ( i_time / 1000000 ) % 60 ) );
+ format_duration( buf, sizeof(buf), i_time );
}
else
- {
- snprintf( buf, 10, b_empty_if_na ? "" : "--:--:--" );
- }
+ strcpy( buf, b_empty_if_na ? "" : "--:--:--" );
INSERT_STRING_NO_FREE( buf );
break;
case 'U':
/**
* Remove forbidden characters from filenames (including slashes)
*/
-char* filename_sanitize( const char *str_origin )
+void filename_sanitize( char *str )
{
- char *str = strdup( str_origin );
+#if defined( WIN32 )
char *str_base = str;
+#endif
+
if( *str == '.' && (str[1] == '\0' || (str[1] == '.' && str[2] == '\0' ) ) )
{
while( *str )
*str = '_';
str++;
}
- return str_base;
+ return;
}
#if defined( WIN32 )
*str-- = '_';
}
#endif
-
- return str_base;
}
/**
#ifndef WIN32
/* \\host\share\path -> smb://host/share/path */
if (strchr (path + 2, '\\') != NULL)
- { /* Convert antislashes to slashes */
+ { /* Convert backslashes to slashes */
char *dup = strdup (path);
if (dup == NULL)
return NULL;
if (schemelen == 4 && !strncasecmp (url, "file", 4))
{
#if (DIR_SEP_CHAR != '/')
- for (char *p = strchr (path, '/'); p; p = strchr (p, '/'))
- *p == DIR_SEP_CHAR;
+ for (char *p = strchr (path, '/'); p; p = strchr (p + 1, '/'))
+ *p = DIR_SEP_CHAR;
#endif
+ /* Leading slash => local path */
if (*path == DIR_SEP_CHAR)
+#if !defined (WIN32) || defined (UNDER_CE)
return path;
+#else
+ return memmove (path, path + 1, strlen (path + 1) + 1);
+#endif
/* Local path disguised as a remote one (MacOS X) */
if (!strncasecmp (path, "localhost"DIR_SEP, 10))
- {
- memmove (path, path + 9, strlen (path + 9) + 1);
- return path;
- }
+ return memmove (path, path + 9, strlen (path + 9) + 1);
#ifdef WIN32
if (*path && asprintf (&ret, "\\\\%s", path) == -1)
ret = strdup ("/dev/stdout");
break;
case 2:
- ret = strdup ("/dev/strerr");
+ ret = strdup ("/dev/stderr");
break;
default:
if (asprintf (&ret, "/dev/fd/%d", fd) == -1)
ret = NULL;
}
#else
+ /* XXX: Does this work on WinCE? */
if (fd < 2)
ret = strdup ("CON");
else