Commit d212ab72 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

GNU libc-like support for "%m" expanded as strerror(errno) in Msg_*.

strerror() is mostly called in that case anyway.
parent f6911cc8
...@@ -301,6 +301,49 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue, int i_type, ...@@ -301,6 +301,49 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue, int i_type,
return; return;
} }
#ifndef __GLIBC__
/* Expand %m to strerror(errno) - only once */
char buf[strlen( psz_format ) + 2001], *ptr;
strcpy( buf, psz_format );
ptr = psz_format = buf;
for( ;; )
{
ptr = strchr( ptr, '%' );
if( ptr == NULL )
break;
if( ptr[1] == 'm' )
{
char errbuf[2001];
size_t errlen;
strerror_r( errno, errbuf, 1001 );
errbuf[1000] = 0;
/* Escape '%' from the error string */
for( char *percent = strchr( errbuf, '%' );
percent != NULL;
percent = strchr( percent + 2, '%' ) )
{
memmove( percent + 1, percent, strlen( percent ) + 1 );
}
errlen = strlen( errbuf );
memmove( ptr + errlen, ptr + 2, strlen( ptr + 2 ) + 1 );
memcpy( ptr, errbuf, errlen );
break; /* Only once, so we don't overflow */
}
/* Looks for conversion specifier... */
do
ptr++;
while( *ptr && ( strchr( "diouxXeEfFgGaAcspn%", *ptr ) == NULL ) );
if( *ptr )
ptr++; /* ...and skip it */
}
#endif
/* Convert message to string */ /* Convert message to string */
#if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined( SYS_BEOS ) #if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined( SYS_BEOS )
vlc_va_copy( args, _args ); vlc_va_copy( args, _args );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment