]> git.saurik.com Git - apple/libplatform.git/blame - private/_simple.h
libplatform-161.50.1.tar.gz
[apple/libplatform.git] / private / _simple.h
CommitLineData
ada7c492
A
1/*
2 * Copyright (c) 2006, 2010, 2013 Apple 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
24#ifndef _SYSTEM_SIMPLE_H_
25#define _SYSTEM_SIMPLE_H_
26
27#include <sys/cdefs.h>
28#include <stdarg.h>
29
30#include <Availability.h>
31
32typedef void *_SIMPLE_STRING;
33typedef const char *_esc_func(unsigned char);
34
35__BEGIN_DECLS
36/*
37 * A simplified vfprintf variant. The format string is interpreted with
38 * arguments from the va_list, and the results are written to the given
39 * file descriptor.
40 */
e45b4692 41void _simple_vdprintf(int __fd, const char *__fmt, va_list __ap) __printflike(2, 0);
ada7c492
A
42
43/*
44 * A simplified fprintf variant. The format string is interpreted with
45 * arguments from the variable argument list, and the results are written
46 * to the given file descriptor.
47 */
e45b4692 48void _simple_dprintf(int __fd, const char *__fmt, ...) __printflike(2, 3);
ada7c492
A
49
50/*
51 * A simplified string allocate routine. Pass the opaque pointer to structure
52 * to _simple_*sprintf() routines. Use _simple_string() to retrieve the
53 * current string (the string is guaranteed to be null terminated only on
54 * the call to _simple_string()). Use _simple_sfree() to free the structure
55 * and string memory.
56 */
57_SIMPLE_STRING _simple_salloc(void);
58
59/*
60 * The format string is interpreted with arguments from the va_list, and the
61 * results are appended to the string maintained by the opaque structure, as
e45b4692
A
62 * returned by a previous call to _simple_salloc(). Non-zero is returned on
63 * out-of-memory error.
ada7c492 64 */
e45b4692 65int _simple_vsprintf(_SIMPLE_STRING __b, const char *__fmt, va_list __ap) __printflike(2, 0);
ada7c492
A
66
67/*
68 * The format string is interpreted with arguments from the variable argument
69 * list, and the results are appended to the string maintained by the opaque
e45b4692
A
70 * structure, as returned by a previous call to _simple_salloc(). Non-zero is
71 * returned on out-of-memory error.
ada7c492 72 */
e45b4692 73int _simple_sprintf(_SIMPLE_STRING __b, const char *__fmt, ...) __printflike(2, 3);
ada7c492
A
74
75/*
76 * Like _simple_vsprintf(), except __esc is a function to call on each
77 * character; the function returns NULL if the character should be passed
78 * as is, otherwise, the returned character string is used instead.
79 */
e45b4692 80int _simple_vesprintf(_SIMPLE_STRING __b, _esc_func __esc, const char *__fmt, va_list __ap) __printflike(3, 0);
ada7c492
A
81
82/*
83 * Like _simple_sprintf(), except __esc is a function to call on each
84 * character; the function returns NULL if the character should be passed
85 * as is, otherwise, the returned character string is used instead.
86 */
e45b4692 87int _simple_esprintf(_SIMPLE_STRING __b, _esc_func __esc, const char *__fmt, ...) __printflike(3, 4);
ada7c492
A
88
89/*
90 * Return the null terminated string from the opaque structure, as returned
91 * by a previous call to _simple_salloc().
92 */
93char *_simple_string(_SIMPLE_STRING __b);
94
95/*
96 * Reposition the pointer to the first null in the buffer. After a call to
97 * _simple_string, the buffer can be modified, and shrunk.
98 */
99void _simple_sresize(_SIMPLE_STRING __b);
100
101/*
102 * Append the null-terminated string to the string associated with the opaque
e45b4692 103 * structure. Non-zero is returned on out-of-memory error.
ada7c492
A
104 */
105int _simple_sappend(_SIMPLE_STRING __b, const char *__str);
106
107/*
108 * Like _simple_sappend(), except __esc is a function to call on each
109 * character; the function returns NULL if the character should be passed
110 * as is, otherwise, the returned character string is used instead.
111 */
112int _simple_esappend(_SIMPLE_STRING __b, _esc_func __esc, const char *__str);
113
114/*
115 * Write the string associated with the opaque structure to the file descriptor.
116 */
117void _simple_put(_SIMPLE_STRING __b, int __fd);
118
119/*
120 * Write the string associated with the opaque structure and a trailing newline,
121 * to the file descriptor.
122 */
123void _simple_putline(_SIMPLE_STRING __b, int __fd);
124
125/*
126 * Free the opaque structure, and the associated string.
127 */
128void _simple_sfree(_SIMPLE_STRING __b);
129
130/*
131 * Simplified ASL log interface; does not use malloc. Unfortunately, this
132 * requires knowledge of the format used by ASL.
133 */
134#ifndef ASL_LEVEL_DEBUG
135#define ASL_LEVEL_EMERG 0
136#define ASL_LEVEL_ALERT 1
137#define ASL_LEVEL_CRIT 2
138#define ASL_LEVEL_ERR 3
139#define ASL_LEVEL_WARNING 4
140#define ASL_LEVEL_NOTICE 5
141#define ASL_LEVEL_INFO 6
142#define ASL_LEVEL_DEBUG 7
143#endif
144
145void _simple_asl_log(int __level, const char *__facility, const char *__message);
146void _simple_asl_log_prog(int level, const char *facility, const char *message, const char *progname);
147
148__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
149_SIMPLE_STRING _simple_asl_msg_new(void);
150
151__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
152void _simple_asl_msg_set(_SIMPLE_STRING __b, const char *__key, const char *__val);
153
154__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
155void _simple_asl_send(_SIMPLE_STRING __b);
156
157__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
158const char *_simple_getenv(const char *envp[], const char *var);
159
160__END_DECLS
161
162#endif /* _SYSTEM_SIMPLE_H_ */