blob: 63b7dbde61cdbab35da403142f9bbb6933d50ce7 [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 *
16 ************************************************************************/
17
Bjorn Reese70a9da52001-04-21 16:57:29 +000018#ifndef TRIO_TRIO_H
19#define TRIO_TRIO_H
Daniel Veillard92ad2102001-03-27 12:47:33 +000020
21#include <stdio.h>
22#include <stdarg.h>
23#include <stdlib.h>
24
25/*
Bjorn Reese70a9da52001-04-21 16:57:29 +000026 * Use autoconf defines if present. Packages using trio must define
27 * HAVE_CONFIG_H as a compiler option themselves.
28 */
29#if defined(HAVE_CONFIG_H)
30# include <config.h>
31#endif
32
33#if !defined(WITHOUT_TRIO)
34
35/*
Daniel Veillard92ad2102001-03-27 12:47:33 +000036 * Error codes.
37 *
38 * Remember to add a textual description to trio_strerror.
39 */
40enum {
41 TRIO_EOF = 1,
42 TRIO_EINVAL = 2,
43 TRIO_ETOOMANY = 3,
44 TRIO_EDBLREF = 4,
45 TRIO_EGAP = 5,
46 TRIO_ENOMEM = 6,
Bjorn Reese70a9da52001-04-21 16:57:29 +000047 TRIO_ERANGE = 7,
Daniel Veillard92ad2102001-03-27 12:47:33 +000048};
49
50/* Error macros */
51#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF)
52#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8)
53#define TRIO_ERROR_NAME(x) trio_strerror(x)
54
Bjorn Reese70a9da52001-04-21 16:57:29 +000055const char *trio_strerror(int);
56
57/*************************************************************************
58 * Print Functions
59 */
60
61int trio_printf(const char *format, ...);
62int trio_vprintf(const char *format, va_list args);
63int trio_printfv(const char *format, void **args);
64
65int trio_fprintf(FILE *file, const char *format, ...);
66int trio_vfprintf(FILE *file, const char *format, va_list args);
67int trio_fprintfv(FILE *file, const char *format, void **args);
68
69int trio_dprintf(int fd, const char *format, ...);
70int trio_vdprintf(int fd, const char *format, va_list args);
71int trio_dprintfv(int fd, const char *format, void **args);
72
73/* trio_sprintf(target, format, ...)
Daniel Veillard92ad2102001-03-27 12:47:33 +000074 * trio_snprintf(target, maxsize, format, ...)
75 *
76 * Build 'target' according to 'format' and succesive
77 * arguments. This is equal to the sprintf() and
78 * snprintf() functions.
79 */
Daniel Veillard92ad2102001-03-27 12:47:33 +000080int trio_sprintf(char *buffer, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000081int trio_vsprintf(char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000082int trio_sprintfv(char *buffer, const char *format, void **args);
83
84int trio_snprintf(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000085int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format,
86 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000087int trio_snprintfv(char *buffer, size_t bufferSize, const char *format,
88 void **args);
89
90int trio_snprintfcat(char *buffer, size_t max, const char *format, ...);
Daniel Veillard92ad2102001-03-27 12:47:33 +000091int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format,
92 va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000093
Daniel Veillard92ad2102001-03-27 12:47:33 +000094char *trio_aprintf(const char *format, ...);
95char *trio_vaprintf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +000096
Daniel Veillard92ad2102001-03-27 12:47:33 +000097int trio_asprintf(char **ret, const char *format, ...);
98int trio_vasprintf(char **ret, const char *format, va_list args);
99
Bjorn Reese70a9da52001-04-21 16:57:29 +0000100/*************************************************************************
101 * Scan Functions
102 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000103int trio_scanf(const char *format, ...);
104int trio_vscanf(const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000105int trio_scanfv(const char *format, void **args);
106
Daniel Veillard92ad2102001-03-27 12:47:33 +0000107int trio_fscanf(FILE *file, const char *format, ...);
108int trio_vfscanf(FILE *file, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000109int trio_fscanfv(FILE *file, const char *format, void **args);
110
Daniel Veillard92ad2102001-03-27 12:47:33 +0000111int trio_dscanf(int fd, const char *format, ...);
112int trio_vdscanf(int fd, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000113int trio_dscanfv(int fd, const char *format, void **args);
114
Daniel Veillard92ad2102001-03-27 12:47:33 +0000115int trio_sscanf(const char *buffer, const char *format, ...);
116int trio_vsscanf(const char *buffer, const char *format, va_list args);
Bjorn Reese70a9da52001-04-21 16:57:29 +0000117int trio_sscanfv(const char *buffer, const char *format, void **args);
Daniel Veillard92ad2102001-03-27 12:47:33 +0000118
Bjorn Reese70a9da52001-04-21 16:57:29 +0000119/*************************************************************************
120 * Renaming
121 */
Daniel Veillard92ad2102001-03-27 12:47:33 +0000122#ifdef TRIO_REPLACE_STDIO
123/* Replace the <stdio.h> functions */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000124#ifndef HAVE_PRINTF
125# define printf trio_printf
126#endif
127#ifndef HAVE_VPRINTF
128# define vprintf trio_vprintf
129#endif
130#ifndef HAVE_FPRINTF
131# define fprintf trio_fprintf
132#endif
133#ifndef HAVE_VFPRINTF
134# define vfprintf trio_vfprintf
135#endif
136#ifndef HAVE_SPRINTF
137# define sprintf trio_sprintf
138#endif
139#ifndef HAVE_VSPRINTF
140# define vsprintf trio_vsprintf
141#endif
142#ifndef HAVE_SNPRINTF
143# define snprintf trio_snprintf
144#endif
145#ifndef HAVE_VSNPRINTF
146# define vsnprintf trio_vsnprintf
147#endif
148#ifndef HAVE_SCANF
149# define scanf trio_scanf
150#endif
151#ifndef HAVE_VSCANF
152# define vscanf trio_vscanf
153#endif
154#ifndef HAVE_FSCANF
155# define fscanf trio_fscanf
156#endif
157#ifndef HAVE_VFSCANF
158# define vfscanf trio_vfscanf
159#endif
160#ifndef HAVE_SSCANF
161# define sscanf trio_sscanf
162#endif
163#ifndef HAVE_VSSCANF
164# define vsscanf trio_vsscanf
165#endif
Daniel Veillard92ad2102001-03-27 12:47:33 +0000166/* These aren't stdio functions, but we make them look similar */
167#define dprintf trio_dprintf
168#define vdprintf trio_vdprintf
169#define aprintf trio_aprintf
170#define vaprintf trio_vaprintf
171#define asprintf trio_asprintf
172#define vasprintf trio_vasprintf
173#define dscanf trio_dscanf
174#define vdscanf trio_vdscanf
175#endif
176
177/* strio compatible names */
Bjorn Reese70a9da52001-04-21 16:57:29 +0000178#define StrScan trio_sscanf
Daniel Veillard92ad2102001-03-27 12:47:33 +0000179#define StrFormat trio_sprintf
180#define StrFormatMax trio_snprintf
181#define StrFormatAlloc trio_aprintf
182#define StrFormatAppendMax trio_snprintfcat
183
Bjorn Reese70a9da52001-04-21 16:57:29 +0000184#endif /* TRIO_IGNORE */
185
186#endif /* TRIO_TRIO_H */