2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (C) 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
11 #ifndef UST_SNPRINTF_VARIOUS_H
12 #define UST_SNPRINTF_VARIOUS_H
19 #include "ust-helper.h"
21 struct __lttng_ust_sbuf
{
27 * stdio state variables.
29 * The following always hold:
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
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.)
41 * _lbfsize is used only to make the inline line-buffered output stream
42 * code as compact as possible.
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.
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 */
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);
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 */
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 */
76 /* separate buffer for fgetln() when line crosses buffer boundary */
77 struct __lttng_ust_sbuf _lb
; /* buffer for fgetln() */
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 */
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 */
101 #define __sferror(p) (((p)->_flags & __SERR) != 0)
104 extern int ust_safe_fflush(LTTNG_UST_LFILE
*fp
);
106 extern int ust_safe_vfprintf(LTTNG_UST_LFILE
*fp
, const char *fmt0
, va_list ap
);
109 extern size_t ust_safe_mbrtowc(wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
);
111 #endif /* UST_SNPRINTF_VARIOUS_H */
This page took 0.054145 seconds and 4 git commands to generate.