1 /* @(#)stdio.h 1.14 16/11/06 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 #ifndef _SCHILY_TYPES_H 95 #include <schily/types.h> /* Needed for ssize_t */ 96 #endif 97 98 /* 99 * This is how the 64 bit FILE * begins on Solaris. 100 */ 101 struct SCHILY__FILE_TAG { 102 unsigned char *_ptr; /* next character from/to here in buffer */ 103 unsigned char *_base; /* the buffer */ 104 unsigned char *_end; /* the end of the buffer */ 105 ssize_t _cnt; /* number of available characters in buffer */ 106 }; 107 108 #define __getc_unlocked(p) (--(p)->_cnt < 0 \ 109 ? __filbuf((FILE *)p) \ 110 : (int)*(p)->_ptr++) 111 112 #define getc_unlocked(p) __getc_unlocked((struct SCHILY__FILE_TAG *)p) 113 114 #define __putc_unlocked(x, p) (--(p)->_cnt < 0 \ 115 ? __flsbuf((x), (FILE *)(p)) \ 116 : (int)(*(p)->_ptr++ = \ 117 (unsigned char) (x))) 118 119 #define putc_unlocked(x, p) __putc_unlocked(x, (struct SCHILY__FILE_TAG *)p) 120 121 extern int __filbuf __PR((FILE *)); 122 extern int __flsbuf __PR((int, FILE *)); 123 124 #else /* !defined(__SVR4) && defined(__sun) && defined(_LP64) */ 125 #undef FAST_GETC_PUTC 126 #endif /* !defined(__SVR4) && defined(__sun) && defined(_LP64) */ 127 #endif /* FAST_GETC_PUTC */ 128 129 #ifdef __cplusplus 130 } 131 #endif 132 133 #else /* !NO_SCHILY_STDIO_H */ 134 #undef _SCHILY_STDIO_H /* #undef here to pass "hdrchk" */ 135 #endif /* NO_SCHILY_STDIO_H */ 136 #endif /* _SCHILY_STDIO_H */ 137