* 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>
# 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)||\
* 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>
}
#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.
*****************************************************************************/
* 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>
*
#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:
*****************************************************************************
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;
}
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;
}
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 );