Hide private snprintf symbols
[lttng-ust.git] / snprintf / various.h
1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (C) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Chris Torek.
9 */
10
11 #ifndef UST_SNPRINTF_VARIOUS_H
12 #define UST_SNPRINTF_VARIOUS_H
13
14 #include <stdarg.h>
15 #include <stddef.h>
16 #include <stdio.h>
17 #include <wchar.h>
18
19 #include "ust-helper.h"
20
21 struct __lttng_ust_sbuf {
22 unsigned char *_base;
23 int _size;
24 };
25
26 /*
27 * stdio state variables.
28 *
29 * The following always hold:
30 *
31 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
32 * _lbfsize is -_bf._size, else _lbfsize is 0
33 * if _flags&__SRD, _w is 0
34 * if _flags&__SWR, _r is 0
35 *
36 * This ensures that the getc and putc macros (or inline functions) never
37 * try to write or read from a file that is in `read' or `write' mode.
38 * (Moreover, they can, and do, automatically switch from read mode to
39 * write mode, and back, on "r+" and "w+" files.)
40 *
41 * _lbfsize is used only to make the inline line-buffered output stream
42 * code as compact as possible.
43 *
44 * _ub, _up, and _ur are used when ungetc() pushes back more characters
45 * than fit in the current _bf, or when ungetc() pushes back a character
46 * that does not match the previous one in _bf. When this happens,
47 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
48 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
49 */
50 typedef struct __lttng_ust_sFILE {
51 unsigned char *_p; /* current position in (some) buffer */
52 int _r; /* read space left for getc() */
53 int _w; /* write space left for putc() */
54 short _flags; /* flags, below; this FILE is free if 0 */
55 short _file; /* fileno, if Unix descriptor, else -1 */
56 struct __lttng_ust_sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
57 int _lbfsize; /* 0 or -_bf._size, for inline putc */
58
59 /* operations */
60 void *_cookie; /* cookie passed to io functions */
61 int (*_close)(void *);
62 int (*_read)(void *, char *, int);
63 fpos_t (*_seek)(void *, fpos_t, int);
64 int (*_write)(void *, const char *, int);
65
66 /* extension data, to avoid further ABI breakage */
67 struct __lttng_ust_sbuf _ext;
68 /* data for long sequences of ungetc() */
69 unsigned char *_up; /* saved _p when _p is doing ungetc data */
70 int _ur; /* saved _r when _r is counting ungetc data */
71
72 /* tricks to meet minimum requirements even when malloc() fails */
73 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
74 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
75
76 /* separate buffer for fgetln() when line crosses buffer boundary */
77 struct __lttng_ust_sbuf _lb; /* buffer for fgetln() */
78
79 /* Unix stdio files get aligned to block boundaries on fseek() */
80 int _blksize; /* stat.st_blksize (may be != _bf._size) */
81 fpos_t _offset; /* current lseek offset */
82 } LTTNG_UST_LFILE;
83
84 #define __SLBF 0x0001 /* line buffered */
85 #define __SNBF 0x0002 /* unbuffered */
86 #define __SRD 0x0004 /* OK to read */
87 #define __SWR 0x0008 /* OK to write */
88 /* RD and WR are never simultaneously asserted */
89 #define __SRW 0x0010 /* open for reading & writing */
90 #define __SEOF 0x0020 /* found EOF */
91 #define __SERR 0x0040 /* found error */
92 #define __SMBF 0x0080 /* _buf is from malloc */
93 #define __SAPP 0x0100 /* fdopen()ed in append mode */
94 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
95 #define __SOPT 0x0400 /* do fseek() optimisation */
96 #define __SNPT 0x0800 /* do not do fseek() optimisation */
97 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
98 #define __SMOD 0x2000 /* true => fgetln modified _p text */
99 #define __SALC 0x4000 /* allocate string space dynamically */
100
101 #define __sferror(p) (((p)->_flags & __SERR) != 0)
102
103 LTTNG_HIDDEN
104 extern int ust_safe_fflush(LTTNG_UST_LFILE *fp);
105 LTTNG_HIDDEN
106 extern int ust_safe_vfprintf(LTTNG_UST_LFILE *fp, const char *fmt0, va_list ap);
107
108 LTTNG_HIDDEN
109 extern size_t ust_safe_mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
110
111 #endif /* UST_SNPRINTF_VARIOUS_H */
This page took 0.030986 seconds and 4 git commands to generate.