blob: 5a38f4a7885db5f94946921109d7abe9bc9ccece [file] [log] [blame]
Daniel Veillard92ad2102001-03-27 12:47:33 +00001/*************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
13 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND
14 * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
15 *
Bjorn Reese026d29f2002-01-19 15:40:18 +000016 *************************************************************************
17 *
18 * http://ctrio.sourceforge.net/
19 *
Daniel Veillard92ad2102001-03-27 12:47:33 +000020 ************************************************************************/
21
Bjorn Reese70a9da52001-04-21 16:57:29 +000022#ifndef TRIO_TRIO_H
23#define TRIO_TRIO_H
Daniel Veillard92ad2102001-03-27 12:47:33 +000024
25#include <stdio.h>
26#include <stdarg.h>
27#include <stdlib.h>
28
29/*
Bjorn Reese70a9da52001-04-21 16:57:29 +000030 * Use autoconf defines if present. Packages using trio must define
31 * HAVE_CONFIG_H as a compiler option themselves.
32 */
33#if defined(HAVE_CONFIG_H)
34# include <config.h>
35#endif
36
37#if !defined(WITHOUT_TRIO)
38
Bjorn Reese906ec8a2001-06-05 12:46:33 +000039#ifdef __cplusplus
40extern "C" {
41#endif
42
43/* make utility and C++ compiler in Windows NT fails to find this symbol */
44#if defined(WIN32) && !defined(isascii)
45# define isascii ((unsigned)(x) < 0x80)
46#endif
47
Bjorn Reese026d29f2002-01-19 15:40:18 +000048/* Error macros */
49#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
50#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
51#define TRIO_ERROR_NAME(x) trio_strerror(x)
52
Bjorn Reese70a9da52001-04-21 16:57:29 +000053/*
Daniel Veillard92ad2102001-03-27 12:47:33 +000054 * Error codes.
55 *
56 * Remember to add a textual description to trio_strerror.
57 */
58enum {
59 TRIO_EOF = 1,
60 TRIO_EINVAL = 2,
61 TRIO_ETOOMANY = 3,
62 TRIO_EDBLREF = 4,
63 TRIO_EGAP = 5,
64 TRIO_ENOMEM = 6,
Bjorn Reese026d29f2002-01-19 15:40:18 +000065 TRIO_ERANGE = 7,
66 TRIO_ERRNO = 8
Daniel Veillard92ad2102001-03-27 12:47:33 +000067};
68
Bjorn Reese70a9da52001-04-21 16:57:29 +000069const char *trio_strerror(int);
70
71/*************************************************************************
72 * Print Functions
73 */
74
75int trio_printf(const char *format, ...);
76int trio_vprintf(const char *format, va_list args);
77int trio_printfv(const char *format, void **args);
78
79int trio_fprintf(FILE *file, const char *format, ...);
80int trio_vfprintf(FILE *file, const char *format, va_list args);
81int trio_fprintfv(FILE *file, const char *format, void **args);
82
83int trio_dprintf(int fd, const char *format, ...);
84int trio_vdprintf(int fd, const char *format, va_list args);
85int trio_dprintfv(int fd, const char *format, void **args);
86
87/* trio_sprintf(target, format, ...)
Daniel Veillard92ad2102001-03-27 12:47:33 +000088 * trio_snprintf(target, maxsize, format, ...)
89 *
90 * Build 'target' according to 'format' and succesive
91 * arguments. This is equal to the sprintf() and
92 * snprintf() functions.
93 */
Daniel Veillard92ad2102001-03-27 12:47:33 +000094int trio_sprintf(char *buffer, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000095int trio_vsprintf(char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000096int trio_sprintfv(char *buffer, const char *format, void **args);
97
98int trio_snprintf(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000099int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
100 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000101int trio_snprintfv(char *buffer, size_t bufferSize, const char *format,
102 void **args);
103
104int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +0000105int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
106 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000107
Daniel Veillard92ad2102001-03-27 12:47:33 +0000108char *trio_aprintf(const char *format, ...);
109char *trio_vaprintf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000110
Daniel Veillard92ad2102001-03-27 12:47:33 +0000111int trio_asprintf(char **ret, const char *format, ...);
112int trio_vasprintf(char **ret, const char *format, va_list args);
113
Bjorn Reese70a9da52001-04-21 16:57:29 +0000114/*************************************************************************
115 * Scan Functions
116 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000117int trio_scanf(const char *format, ...);
118int trio_vscanf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000119int trio_scanfv(const char *format, void **args);
120
Daniel Veillard92ad2102001-03-27 12:47:33 +0000121int trio_fscanf(FILE *file, const char *format, ...);
122int trio_vfscanf(FILE *file, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000123int trio_fscanfv(FILE *file, const char *format, void **args);
124
Daniel Veillard92ad2102001-03-27 12:47:33 +0000125int trio_dscanf(int fd, const char *format, ...);
126int trio_vdscanf(int fd, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000127int trio_dscanfv(int fd, const char *format, void **args);
128
Daniel Veillard92ad2102001-03-27 12:47:33 +0000129int trio_sscanf(const char *buffer, const char *format, ...);
130int trio_vsscanf(const char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000131int trio_sscanfv(const char *buffer, const char *format, void **args);
Daniel Veillard92ad2102001-03-27 12:47:33 +0000132
Bjorn Reese70a9da52001-04-21 16:57:29 +0000133/*************************************************************************
134 * Renaming
135 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000136#ifdef TRIO_REPLACE_STDIO
137/* Replace the <stdio.h> functions */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000138#ifndef HAVE_PRINTF
139# define printf trio_printf
140#endif
141#ifndef HAVE_VPRINTF
142# define vprintf trio_vprintf
143#endif
144#ifndef HAVE_FPRINTF
145# define fprintf trio_fprintf
146#endif
147#ifndef HAVE_VFPRINTF
148# define vfprintf trio_vfprintf
149#endif
150#ifndef HAVE_SPRINTF
151# define sprintf trio_sprintf
152#endif
153#ifndef HAVE_VSPRINTF
154# define vsprintf trio_vsprintf
155#endif
156#ifndef HAVE_SNPRINTF
157# define snprintf trio_snprintf
158#endif
159#ifndef HAVE_VSNPRINTF
160# define vsnprintf trio_vsnprintf
161#endif
162#ifndef HAVE_SCANF
163# define scanf trio_scanf
164#endif
165#ifndef HAVE_VSCANF
166# define vscanf trio_vscanf
167#endif
168#ifndef HAVE_FSCANF
169# define fscanf trio_fscanf
170#endif
171#ifndef HAVE_VFSCANF
172# define vfscanf trio_vfscanf
173#endif
174#ifndef HAVE_SSCANF
175# define sscanf trio_sscanf
176#endif
177#ifndef HAVE_VSSCANF
178# define vsscanf trio_vsscanf
179#endif
Daniel Veillard92ad2102001-03-27 12:47:33 +0000180/* These aren't stdio functions, but we make them look similar */
181#define dprintf trio_dprintf
182#define vdprintf trio_vdprintf
183#define aprintf trio_aprintf
184#define vaprintf trio_vaprintf
185#define asprintf trio_asprintf
186#define vasprintf trio_vasprintf
187#define dscanf trio_dscanf
188#define vdscanf trio_vdscanf
189#endif
190
Bjorn Reese906ec8a2001-06-05 12:46:33 +0000191#ifdef __cplusplus
192} /* extern "C" */
193#endif
194
195#endif /* WITHOUT_TRIO */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000196
197#endif /* TRIO_TRIO_H */