Daniel Veillard | 92ad210 | 2001-03-27 12:47:33 +0000 | [diff] [blame^] | 1 | /************************************************************************* |
| 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 | |
| 18 | #ifndef H_TRIO |
| 19 | #define H_TRIO |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdarg.h> |
| 23 | #include <stdlib.h> |
| 24 | |
| 25 | /* |
| 26 | * Error codes. |
| 27 | * |
| 28 | * Remember to add a textual description to trio_strerror. |
| 29 | */ |
| 30 | enum { |
| 31 | TRIO_EOF = 1, |
| 32 | TRIO_EINVAL = 2, |
| 33 | TRIO_ETOOMANY = 3, |
| 34 | TRIO_EDBLREF = 4, |
| 35 | TRIO_EGAP = 5, |
| 36 | TRIO_ENOMEM = 6, |
| 37 | TRIO_ERANGE = 7 |
| 38 | }; |
| 39 | |
| 40 | /* Error macros */ |
| 41 | #define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF) |
| 42 | #define TRIO_ERROR_POSITION(x) ((-(x)) >> 8) |
| 43 | #define TRIO_ERROR_NAME(x) trio_strerror(x) |
| 44 | |
| 45 | /* |
| 46 | * trio_sprintf(target, format, ...) |
| 47 | * trio_snprintf(target, maxsize, format, ...) |
| 48 | * |
| 49 | * Build 'target' according to 'format' and succesive |
| 50 | * arguments. This is equal to the sprintf() and |
| 51 | * snprintf() functions. |
| 52 | */ |
| 53 | |
| 54 | int trio_printf(const char *format, ...); |
| 55 | int trio_vprintf(const char *format, va_list args); |
| 56 | int trio_fprintf(FILE *file, const char *format, ...); |
| 57 | int trio_vfprintf(FILE *file, const char *format, va_list args); |
| 58 | int trio_dprintf(int fd, const char *format, ...); |
| 59 | int trio_vdprintf(int fd, const char *format, va_list args); |
| 60 | int trio_sprintf(char *buffer, const char *format, ...); |
| 61 | int trio_snprintf(char *buffer, size_t max, const char *format, ...); |
| 62 | int trio_snprintfcat(char *buffer, size_t max, const char *format, ...); |
| 63 | int trio_vsprintf(char *buffer, const char *format, va_list args); |
| 64 | int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format, |
| 65 | va_list args); |
| 66 | int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format, |
| 67 | va_list args); |
| 68 | char *trio_aprintf(const char *format, ...); |
| 69 | char *trio_vaprintf(const char *format, va_list args); |
| 70 | int trio_asprintf(char **ret, const char *format, ...); |
| 71 | int trio_vasprintf(char **ret, const char *format, va_list args); |
| 72 | |
| 73 | int trio_scanf(const char *format, ...); |
| 74 | int trio_vscanf(const char *format, va_list args); |
| 75 | int trio_fscanf(FILE *file, const char *format, ...); |
| 76 | int trio_vfscanf(FILE *file, const char *format, va_list args); |
| 77 | int trio_dscanf(int fd, const char *format, ...); |
| 78 | int trio_vdscanf(int fd, const char *format, va_list args); |
| 79 | int trio_sscanf(const char *buffer, const char *format, ...); |
| 80 | int trio_vsscanf(const char *buffer, const char *format, va_list args); |
| 81 | |
| 82 | const char *trio_strerror(int); |
| 83 | |
| 84 | #ifdef TRIO_REPLACE_STDIO |
| 85 | /* Replace the <stdio.h> functions */ |
| 86 | #define printf trio_printf |
| 87 | #define vprintf trio_vprintf |
| 88 | #define fprintf trio_fprintf |
| 89 | #define vfprintf trio_vfprintf |
| 90 | #define sprintf trio_sprintf |
| 91 | #define vsprintf trio_vsprintf |
| 92 | #define snprintf trio_snprintf |
| 93 | #define vsnprintf trio_vsnprintf |
| 94 | #define scanf trio_scanf |
| 95 | #define vscanf trio_vscanf |
| 96 | #define fscanf trio_fscanf |
| 97 | #define vfscanf trio_vfscanf |
| 98 | #define sscanf trio_sscanf |
| 99 | #define vsscanf trio_vsscanf |
| 100 | /* These aren't stdio functions, but we make them look similar */ |
| 101 | #define dprintf trio_dprintf |
| 102 | #define vdprintf trio_vdprintf |
| 103 | #define aprintf trio_aprintf |
| 104 | #define vaprintf trio_vaprintf |
| 105 | #define asprintf trio_asprintf |
| 106 | #define vasprintf trio_vasprintf |
| 107 | #define dscanf trio_dscanf |
| 108 | #define vdscanf trio_vdscanf |
| 109 | #endif |
| 110 | |
| 111 | /* strio compatible names */ |
| 112 | #define StrScan sscanf /* FIXME: must be trio_sscanf */ |
| 113 | #define StrFormat trio_sprintf |
| 114 | #define StrFormatMax trio_snprintf |
| 115 | #define StrFormatAlloc trio_aprintf |
| 116 | #define StrFormatAppendMax trio_snprintfcat |
| 117 | |
| 118 | #endif /* H_TRIO */ |