cb1b6a61c56888e86a914333fe4645f1c1d7f854
[reactos.git] / reactos / sdk / tools / mkisofs / schilytools / include / schily / stdio.h
1 /* @(#)stdio.h 1.12 16/09/11 Copyright 2009-2016 J. Schilling */
2 /*
3 * Abstraction from stdio.h
4 *
5 * Copyright (c) 2009-2016 J. Schilling
6 */
7 /*
8 * The contents of this file are subject to the terms of the
9 * Common Development and Distribution License, Version 1.0 only
10 * (the "License"). You may not use this file except in compliance
11 * with the License.
12 *
13 * See the file CDDL.Schily.txt in this distribution for details.
14 * A copy of the CDDL is also available via the Internet at
15 * http://www.opensource.org/licenses/cddl1.txt
16 *
17 * When distributing Covered Code, include this CDDL HEADER in each
18 * file and include the License file CDDL.Schily.txt from this distribution.
19 */
20
21 #ifndef _SCHILY_STDIO_H
22 #define _SCHILY_STDIO_H
23 #ifndef NO_SCHILY_STDIO_H /* We #undef _SCHILY_STDIO_H later because */
24 /* of the ill designed "hdrchk" program */
25
26 #ifndef _SCHILY_MCONFIG_H
27 #include <schily/mconfig.h>
28 #endif
29
30 #ifdef INCL_MYSTDIO
31 #ifndef _INCL_MYSTDIO_H
32 #include <mystdio.h>
33 #define _INCL_MYSTDIO_H
34 #endif
35
36 #else /* INCL_MYSTDIO */
37
38 #ifndef _INCL_STDIO_H
39 #include <stdio.h>
40 #define _INCL_STDIO_H
41 #endif
42 #endif /* INCL_MYSTDIO */
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #ifdef HAVE_LARGEFILES
49 /*
50 * If HAVE_LARGEFILES is defined, it is guaranteed that fseeko()/ftello()
51 * both are available.
52 */
53 #define fseek fseeko
54 #define ftell ftello
55 #else /* !HAVE_LARGEFILES */
56
57 /*
58 * If HAVE_LARGEFILES is not defined, we depend on specific tests for
59 * fseeko()/ftello() which must have been done before the tests for
60 * Large File support have been done.
61 * Note that this only works if the tests used below are really done before
62 * the Large File autoconf test is run. This is because autoconf does no
63 * clean testing but instead cumulatively modifes the envivonment used for
64 * testing.
65 */
66 #ifdef HAVE_FSEEKO
67 # define fseek fseeko
68 #endif
69 #ifdef HAVE_FTELLO
70 # define ftell ftello
71 #endif
72 #endif
73
74 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
75 #define popen(c, m) _popen((c), (m))
76 #endif
77
78 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
79 #define pclose(fp) _pclose(fp)
80 #endif
81
82 #ifdef FAST_GETC_PUTC
83 /*
84 * The following code partially allows libschily to access FILE * as fast as
85 * from inside libc on Solaris.
86 * This makes it possible to implement js_printf() from libschily aprox.
87 * 33% faster than printf() from libc on Solaris. To do this, we
88 * partially unhide the FILE structure in a 64 bit environment on Solaris
89 * to allow to run putc_unlocked() as a marcro.
90 *
91 * If you believe you can do this on onther platforms, send a note.
92 */
93 #if defined(__SVR4) && defined(__sun) && defined(_LP64)
94
95 /*
96 * This is how the 64 bit FILE * begins on Solaris.
97 */
98 struct SCHILY__FILE_TAG {
99 unsigned char *_ptr; /* next character from/to here in buffer */
100 unsigned char *_base; /* the buffer */
101 unsigned char *_end; /* the end of the buffer */
102 ssize_t _cnt; /* number of available characters in buffer */
103 };
104
105 #define __putc_unlocked(x, p) (--(p)->_cnt < 0 \
106 ? __flsbuf((x), (FILE *)(p)) \
107 : (int)(*(p)->_ptr++ = \
108 (unsigned char) (x)))
109
110 #define putc_unlocked(x, p) __putc_unlocked(x, (struct SCHILY__FILE_TAG *)p)
111
112 extern int __flsbuf __PR((int, FILE *));
113
114 #endif /* defined(__SVR4) && defined(__sun) && defined(_LP64) */
115 #endif /* FAST_GETC_PUTC */
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #else /* !NO_SCHILY_STDIO_H */
122 #undef _SCHILY_STDIO_H /* #undef here to pass "hdrchk" */
123 #endif /* NO_SCHILY_STDIO_H */
124 #endif /* _SCHILY_STDIO_H */