]> git.saurik.com Git - apple/libc.git/blob - gen/_simple.h
62182d5a3867ac781e344618001339be0075dbcc
[apple/libc.git] / gen / _simple.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 #include <sys/cdefs.h>
24 #include <stdarg.h>
25 #include <asl.h>
26
27 typedef void *_SIMPLE_STRING;
28 typedef const char *_esc_func(unsigned char);
29
30 __BEGIN_DECLS
31 /*
32 * A simplified vfprintf variant. The format string is interpreted with
33 * arguments from the va_list, and the results are written to the given
34 * file descriptor.
35 */
36 void _simple_vdprintf(int __fd, const char *__fmt, va_list __ap);
37
38 /*
39 * A simplified fprintf variant. The format string is interpreted with
40 * arguments from the variable argument list, and the results are written
41 * to the given file descriptor.
42 */
43 void _simple_dprintf(int __fd, const char *__fmt, ...);
44
45 /*
46 * A simplified string allocate routine. Pass the opaque pointer to structure
47 * to _simple_*sprintf() routines. Use _simple_string() to retrieve the
48 * current string (the string is guaranteed to be null terminated only on
49 * the call to _simple_string()). Use _simple_sfree() to free the structure
50 * and string memory.
51 */
52 _SIMPLE_STRING _simple_salloc(void);
53
54 /*
55 * The format string is interpreted with arguments from the va_list, and the
56 * results are appended to the string maintained by the opaque structure, as
57 * returned by a previous call to _simple_salloc(). Non-zero is returned on
58 * out-of-memory error.
59 */
60 int _simple_vsprintf(_SIMPLE_STRING __b, const char *__fmt, va_list __ap);
61
62 /*
63 * The format string is interpreted with arguments from the variable argument
64 * list, and the results are appended to the string maintained by the opaque
65 * structure, as returned by a previous call to _simple_salloc(). Non-zero is
66 * returned on out-of-memory error.
67 */
68 int _simple_sprintf(_SIMPLE_STRING __b, const char *__fmt, ...);
69
70 /*
71 * Like _simple_vsprintf(), except __esc is a function to call on each
72 * character; the function returns NULL if the character should be passed
73 * as is, otherwise, the returned character string is used instead.
74 */
75 int _simple_vesprintf(_SIMPLE_STRING __b, _esc_func __esc, const char *__fmt, va_list __ap);
76
77 /*
78 * Like _simple_sprintf(), except __esc is a function to call on each
79 * character; the function returns NULL if the character should be passed
80 * as is, otherwise, the returned character string is used instead.
81 */
82 int _simple_esprintf(_SIMPLE_STRING __b, _esc_func __esc, const char *__fmt, ...);
83
84 /*
85 * Return the null terminated string from the opaque structure, as returned
86 * by a previous call to _simple_salloc().
87 */
88 char *_simple_string(_SIMPLE_STRING __b);
89
90 /*
91 * Reposition the pointer to the first null in the buffer. After a call to
92 * _simple_string, the buffer can be modified, and shrunk.
93 */
94 void _simple_sresize(_SIMPLE_STRING __b);
95
96 /*
97 * Append the null-terminated string to the string associated with the opaque
98 * structure. Non-zero is returned on out-of-memory error.
99 */
100 int _simple_sappend(_SIMPLE_STRING __b, const char *__str);
101
102 /*
103 * Like _simple_sappend(), except __esc is a function to call on each
104 * character; the function returns NULL if the character should be passed
105 * as is, otherwise, the returned character string is used instead.
106 */
107 int _simple_esappend(_SIMPLE_STRING __b, _esc_func __esc, const char *__str);
108
109 /*
110 * Write the string associated with the opaque structure to the file descriptor.
111 */
112 void _simple_put(_SIMPLE_STRING __b, int __fd);
113
114 /*
115 * Write the string associated with the opaque structure and a trailing newline,
116 * to the file descriptor.
117 */
118 void _simple_putline(_SIMPLE_STRING __b, int __fd);
119
120 /*
121 * Free the opaque structure, and the associated string.
122 */
123 void _simple_sfree(_SIMPLE_STRING __b);
124
125 /*
126 * Simplified ASL log interface; does not use malloc. Unfortunately, this
127 * requires knowledge of the format used by ASL.
128 */
129 void _simple_asl_log(int __level, const char *__facility, const char *__message);