Commit d6d35240 authored by Laurent Aimar's avatar Laurent Aimar

* all: added own implementation of vasprintf. I hope it's ok this way.

parent b3dc4442
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.97 2004/01/05 12:59:43 zorglub Exp $
* $Id: vlc_common.h,v 1.98 2004/01/07 23:39:40 fenrir Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -612,6 +612,13 @@ static inline uint64_t GetQWLE( void * _p )
# define vlc_strdup NULL
#endif
#ifndef HAVE_VASPRINTF
# define vasprintf vlc_vasprintf
VLC_EXPORT( char *, vlc_vasprintf, ( const char *s ) );
#elif !defined(__PLUGIN__)
# define vlc_vasprintf NULL
#endif
#ifndef HAVE_STRNDUP
# if defined(STRNDUP_IN_GNOME_H) && \
(defined(MODULE_NAME_IS_gnome)||defined(MODULE_NAME_IS_gnome_main)||\
......
......@@ -2,7 +2,7 @@
* libc.c: Extra libc function for some systems.
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: libc.c,v 1.10 2003/10/08 19:40:42 gbazin Exp $
* $Id: libc.c,v 1.11 2004/01/07 23:39:41 fenrir Exp $
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Samuel Hocevar <sam@zoy.org>
......@@ -127,6 +127,52 @@ int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
}
#endif
/*****************************************************************************
* vasprintf:
*****************************************************************************/
#if !defined( HAVE_VASPRINTF )
int vlc_vasprintf(char **strp, const char *fmt, va_list ap)
{
/* Guess we need no more than 100 bytes. */
int i_size = 100;
char *p = malloc( i_size );
int n;
if( p == NULL )
{
*strp = NULL;
return -1;
}
for( ;; )
{
/* Try to print in the allocated space. */
n = vsnprintf( p, i_size, fmt, args );
/* If that worked, return the string. */
if (n > -1 && n < i_size)
{
*strp = p;
return strlen( p );
}
/* Else try again with more space. */
if (n > -1) /* glibc 2.1 */
{
i_size = n+1; /* precisely what is needed */
}
else /* glibc 2.0 */
{
i_size *= 2; /* twice the old size */
}
if( (p = realloc( p, i_size ) ) == NULL)
{
*strp = NULL;
return -1;
}
}
}
#endif
/*****************************************************************************
* atof: convert a string to a double.
*****************************************************************************/
......
......@@ -2,7 +2,7 @@
* net.c:
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: net.c,v 1.3 2004/01/07 14:59:03 fenrir Exp $
* $Id: net.c,v 1.4 2004/01/07 23:39:41 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@videolan.org>
*
......@@ -55,51 +55,6 @@
#include "network.h"
/*****************************************************************************
* vsprintf_m:
*****************************************************************************
* do like vsprintf but auto allocated memory
* XXX: should be move elsewhere (under vlc_vasprintf)
*****************************************************************************/
static char *vsprintf_m( const char *fmt, va_list args )
{
/* Guess we need no more than 100 bytes. */
int i_size = 100;
char *p = malloc( i_size );
int n;
if( p == NULL )
{
return NULL;
}
for( ;; )
{
/* Try to print in the allocated space. */
n = vsnprintf( p, i_size, fmt, args );
/* If that worked, return the string. */
if (n > -1 && n < i_size)
{
return p;
}
/* Else try again with more space. */
if (n > -1) /* glibc 2.1 */
{
i_size = n+1; /* precisely what is needed */
}
else /* glibc 2.0 */
{
i_size *= 2; /* twice the old size */
}
if( (p = realloc( p, i_size ) ) == NULL)
{
return NULL;
}
}
}
/*****************************************************************************
* __net_OpenTCP:
*****************************************************************************
......@@ -182,12 +137,13 @@ int __net_Read( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, vlc_b
int i_recv;
int i_total = 0;
int i_ret;
vlc_bool_t b_die = p_this->b_die;
while( i_data > 0 )
{
do
{
if( p_this->b_die || p_this->b_error )
if( p_this->b_die != b_die )
{
return 0;
}
......@@ -234,11 +190,13 @@ int __net_Write( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data )
int i_total = 0;
int i_ret;
vlc_bool_t b_die = p_this->b_die;
while( i_data > 0 )
{
do
{
if( p_this->b_die || p_this->b_error )
if( p_this->b_die != b_die )
{
return 0;
}
......@@ -323,7 +281,7 @@ int net_Printf( vlc_object_t *p_this, int fd, char *psz_fmt, ... )
int i_size, i_ret;
va_start( args, psz_fmt );
psz = vsprintf_m( psz_fmt, args );
vasprintf( &psz, psz_fmt, args );
va_end( args );
i_size = strlen( psz );
......
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