2001-03-27 16:47:33 +04:00
/*************************************************************************
*
* $ Id $
*
* Copyright ( C ) 1998 Bjorn Reese and Daniel Stenberg .
*
* Permission to use , copy , modify , and distribute this software for any
* purpose with or without fee is hereby granted , provided that the above
* copyright notice and this permission notice appear in all copies .
*
* THIS SOFTWARE IS PROVIDED ` ` AS IS ' ' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES , INCLUDING , WITHOUT LIMITATION , THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE . THE AUTHORS AND
* CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-04-21 20:57:29 +04:00
# ifndef TRIO_TRIO_H
# define TRIO_TRIO_H
2001-03-27 16:47:33 +04:00
# include <stdio.h>
# include <stdarg.h>
# include <stdlib.h>
2001-04-21 20:57:29 +04:00
/*
* Use autoconf defines if present . Packages using trio must define
* HAVE_CONFIG_H as a compiler option themselves .
*/
# if defined(HAVE_CONFIG_H)
# include <config.h>
# endif
# if !defined(WITHOUT_TRIO)
2001-06-05 16:46:33 +04:00
# ifdef __cplusplus
extern " C " {
# endif
/* make utility and C++ compiler in Windows NT fails to find this symbol */
# if defined(WIN32) && !defined(isascii)
# define isascii ((unsigned)(x) < 0x80)
# endif
2001-03-27 16:47:33 +04:00
/*
* Error codes .
*
* Remember to add a textual description to trio_strerror .
*/
enum {
TRIO_EOF = 1 ,
TRIO_EINVAL = 2 ,
TRIO_ETOOMANY = 3 ,
TRIO_EDBLREF = 4 ,
TRIO_EGAP = 5 ,
TRIO_ENOMEM = 6 ,
2001-06-05 16:46:33 +04:00
TRIO_ERANGE = 7
2001-03-27 16:47:33 +04:00
} ;
/* Error macros */
# define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
# define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
# define TRIO_ERROR_NAME(x) trio_strerror(x)
2001-04-21 20:57:29 +04:00
const char * trio_strerror ( int ) ;
/*************************************************************************
* Print Functions
2001-03-27 16:47:33 +04:00
*/
int trio_printf ( const char * format , . . . ) ;
int trio_vprintf ( const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_printfv ( const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
int trio_fprintf ( FILE * file , const char * format , . . . ) ;
int trio_vfprintf ( FILE * file , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_fprintfv ( FILE * file , const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
int trio_dprintf ( int fd , const char * format , . . . ) ;
int trio_vdprintf ( int fd , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_dprintfv ( int fd , const char * format , void * * args ) ;
/* trio_sprintf(target, format, ...)
* trio_snprintf ( target , maxsize , format , . . . )
*
* Build ' target ' according to ' format ' and succesive
* arguments . This is equal to the sprintf ( ) and
* snprintf ( ) functions .
*/
2001-03-27 16:47:33 +04:00
int trio_sprintf ( char * buffer , const char * format , . . . ) ;
int trio_vsprintf ( char * buffer , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_sprintfv ( char * buffer , const char * format , void * * args ) ;
int trio_snprintf ( char * buffer , size_t max , const char * format , . . . ) ;
2001-03-27 16:47:33 +04:00
int trio_vsnprintf ( char * buffer , size_t bufferSize , const char * format ,
va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_snprintfv ( char * buffer , size_t bufferSize , const char * format ,
void * * args ) ;
int trio_snprintfcat ( char * buffer , size_t max , const char * format , . . . ) ;
2001-03-27 16:47:33 +04:00
int trio_vsnprintfcat ( char * buffer , size_t bufferSize , const char * format ,
va_list args ) ;
2001-04-21 20:57:29 +04:00
2001-03-27 16:47:33 +04:00
char * trio_aprintf ( const char * format , . . . ) ;
char * trio_vaprintf ( const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
2001-03-27 16:47:33 +04:00
int trio_asprintf ( char * * ret , const char * format , . . . ) ;
int trio_vasprintf ( char * * ret , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
/*************************************************************************
* Scan Functions
*/
2001-03-27 16:47:33 +04:00
int trio_scanf ( const char * format , . . . ) ;
int trio_vscanf ( const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_scanfv ( const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
int trio_fscanf ( FILE * file , const char * format , . . . ) ;
int trio_vfscanf ( FILE * file , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_fscanfv ( FILE * file , const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
int trio_dscanf ( int fd , const char * format , . . . ) ;
int trio_vdscanf ( int fd , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_dscanfv ( int fd , const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
int trio_sscanf ( const char * buffer , const char * format , . . . ) ;
int trio_vsscanf ( const char * buffer , const char * format , va_list args ) ;
2001-04-21 20:57:29 +04:00
int trio_sscanfv ( const char * buffer , const char * format , void * * args ) ;
2001-03-27 16:47:33 +04:00
2001-04-21 20:57:29 +04:00
/*************************************************************************
* Renaming
*/
2001-03-27 16:47:33 +04:00
# ifdef TRIO_REPLACE_STDIO
/* Replace the <stdio.h> functions */
2001-04-21 20:57:29 +04:00
# ifndef HAVE_PRINTF
# define printf trio_printf
# endif
# ifndef HAVE_VPRINTF
# define vprintf trio_vprintf
# endif
# ifndef HAVE_FPRINTF
# define fprintf trio_fprintf
# endif
# ifndef HAVE_VFPRINTF
# define vfprintf trio_vfprintf
# endif
# ifndef HAVE_SPRINTF
# define sprintf trio_sprintf
# endif
# ifndef HAVE_VSPRINTF
# define vsprintf trio_vsprintf
# endif
# ifndef HAVE_SNPRINTF
# define snprintf trio_snprintf
# endif
# ifndef HAVE_VSNPRINTF
# define vsnprintf trio_vsnprintf
# endif
# ifndef HAVE_SCANF
# define scanf trio_scanf
# endif
# ifndef HAVE_VSCANF
# define vscanf trio_vscanf
# endif
# ifndef HAVE_FSCANF
# define fscanf trio_fscanf
# endif
# ifndef HAVE_VFSCANF
# define vfscanf trio_vfscanf
# endif
# ifndef HAVE_SSCANF
# define sscanf trio_sscanf
# endif
# ifndef HAVE_VSSCANF
# define vsscanf trio_vsscanf
# endif
2001-03-27 16:47:33 +04:00
/* These aren't stdio functions, but we make them look similar */
# define dprintf trio_dprintf
# define vdprintf trio_vdprintf
# define aprintf trio_aprintf
# define vaprintf trio_vaprintf
# define asprintf trio_asprintf
# define vasprintf trio_vasprintf
# define dscanf trio_dscanf
# define vdscanf trio_vdscanf
# endif
/* strio compatible names */
2001-04-21 20:57:29 +04:00
# define StrScan trio_sscanf
2001-03-27 16:47:33 +04:00
# define StrFormat trio_sprintf
# define StrFormatMax trio_snprintf
# define StrFormatAlloc trio_aprintf
# define StrFormatAppendMax trio_snprintfcat
2001-06-05 16:46:33 +04:00
# ifdef __cplusplus
} /* extern "C" */
# endif
# endif /* WITHOUT_TRIO */
2001-04-21 20:57:29 +04:00
# endif /* TRIO_TRIO_H */