2011-02-12 05:22:29 +00:00
|
|
|
#ifndef _STDIO_H
|
|
|
|
#define _STDIO_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-09-08 03:13:55 +00:00
|
|
|
#include <features.h>
|
2012-09-07 02:44:55 +00:00
|
|
|
|
2011-02-12 05:22:29 +00:00
|
|
|
#define __NEED_FILE
|
2013-06-26 02:26:20 +00:00
|
|
|
#define __NEED___isoc_va_list
|
2011-02-12 05:22:29 +00:00
|
|
|
#define __NEED_size_t
|
2011-02-14 10:10:10 +00:00
|
|
|
|
2019-03-12 19:24:00 +00:00
|
|
|
#if __STDC_VERSION__ < 201112L
|
|
|
|
#define __NEED_struct__IO_FILE
|
|
|
|
#endif
|
|
|
|
|
2011-02-14 10:10:10 +00:00
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
2012-05-23 01:52:08 +00:00
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2011-02-12 05:22:29 +00:00
|
|
|
#define __NEED_ssize_t
|
|
|
|
#define __NEED_off_t
|
2013-06-26 02:26:20 +00:00
|
|
|
#define __NEED_va_list
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#include <bits/alltypes.h>
|
|
|
|
|
2013-11-25 02:42:55 +00:00
|
|
|
#ifdef __cplusplus
|
use a common definition of NULL as 0L for C and C++
the historical mess of having different definitions for C and C++
comes from the historical C definition as (void *)0 and the fact that
(void *)0 can't be used in C++ because it does not convert to other
pointer types implicitly. however, using plain 0 in C++ exposed bugs
in C++ programs that call variadic functions with NULL as an argument
and (wrongly; this is UB) expect it to arrive as a null pointer. on
64-bit machines, the high bits end up containing junk. glibc dodges
the issue by using a GCC extension __null to define NULL; this is
observably non-conforming because a conforming application could
observe the definition of NULL via stringizing and see that it is
neither an integer constant expression with value zero nor such an
expression cast to void.
switching to 0L eliminates the issue and provides compatibility with
broken applications, since on all musl targets, long and pointers have
the same size, representation, and argument-passing convention. we
could maintain separate C and C++ definitions of NULL (i.e. just use
0L on C++ and use (void *)0 on C) but after careful analysis, it seems
extremely difficult for a C program to even determine whether NULL has
integer or pointer type, much less depend in subtle, unintentional
ways, on whether it does. C89 seems to have no way to make the
distinction. on C99, the fact that (int)(void *)0 is not an integer
constant expression, along with subtle VLA/sizeof semantics, can be
used to make the distinction, but many compilers are non-conforming
and give the wrong result to this test anyway. on C11, _Generic can
trivially make the distinction, but it seems unlikely that code
targetting C11 would be so backwards in caring which definition of
NULL an implementation uses.
as such, the simplest path of using the same definition for NULL in
both C and C++ was chosen. the #undef directive was also removed so
that the compiler can catch and give a warning or error on
redefinition if buggy programs have defined their own versions of
NULL prior to inclusion of standard headers.
2013-01-19 01:35:26 +00:00
|
|
|
#define NULL 0L
|
2013-11-25 02:42:55 +00:00
|
|
|
#else
|
|
|
|
#define NULL ((void*)0)
|
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#undef EOF
|
|
|
|
#define EOF (-1)
|
|
|
|
|
|
|
|
#undef SEEK_SET
|
|
|
|
#undef SEEK_CUR
|
|
|
|
#undef SEEK_END
|
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
|
|
|
|
#define _IOFBF 0
|
|
|
|
#define _IOLBF 1
|
|
|
|
#define _IONBF 2
|
|
|
|
|
2011-02-16 00:47:22 +00:00
|
|
|
#define BUFSIZ 1024
|
2013-07-18 18:15:48 +00:00
|
|
|
#define FILENAME_MAX 4096
|
2011-02-16 00:47:22 +00:00
|
|
|
#define FOPEN_MAX 1000
|
|
|
|
#define TMP_MAX 10000
|
|
|
|
#define L_tmpnam 20
|
2011-02-12 05:22:29 +00:00
|
|
|
|
refactor headers, especially alltypes.h, and improve C++ ABI compat
the arch-specific bits/alltypes.h.sh has been replaced with a generic
alltypes.h.in and minimal arch-specific bits/alltypes.h.in.
this commit is intended to have no functional changes except:
- exposing additional symbols that POSIX allows but does not require
- changing the C++ name mangling for some types
- fixing the signedness of blksize_t on powerpc (POSIX requires signed)
- fixing the limit macros for sig_atomic_t on x86_64
- making dev_t an unsigned type (ABI matching goal, and more logical)
in addition, some types that were wrongly defined with long on 32-bit
archs were changed to int, and vice versa; this change is
non-functional except for the possibility of making pointer types
mismatch, and only affects programs that were using them incorrectly,
and only at build-time, not runtime.
the following changes were made in the interest of moving
non-arch-specific types out of the alltypes system and into the
headers they're associated with, and also will tend to improve
application compatibility:
- netdb.h now includes netinet/in.h (for socklen_t and uint32_t)
- netinet/in.h now includes sys/socket.h and inttypes.h
- sys/resource.h now includes sys/time.h (for struct timeval)
- sys/wait.h now includes signal.h (for siginfo_t)
- langinfo.h now includes nl_types.h (for nl_item)
for the types in stdint.h:
- types which are of no interest to other headers were moved out of
the alltypes system.
- fast types for 8- and 64-bit are hard-coded (at least for now); only
the 16- and 32-bit ones have reason to vary by arch.
and the following types have been changed for C++ ABI purposes;
- mbstate_t now has a struct tag, __mbstate_t
- FILE's struct tag has been changed to _IO_FILE
- DIR's struct tag has been changed to __dirstream
- locale_t's struct tag has been changed to __locale_struct
- pthread_t is defined as unsigned long in C++ mode only
- fpos_t now has a struct tag, _G_fpos64_t
- fsid_t's struct tag has been changed to __fsid_t
- idtype_t has been made an enum type (also required by POSIX)
- nl_catd has been changed from long to void *
- siginfo_t's struct tag has been removed
- sigset_t's has been given a struct tag, __sigset_t
- stack_t has been given a struct tag, sigaltstack
- suseconds_t has been changed to long on 32-bit archs
- [u]intptr_t have been changed from long to int rank on 32-bit archs
- dev_t has been made unsigned
summary of tests that have been performed against these changes:
- nsz's libc-test (diff -u before and after)
- C++ ABI check symbol dump (diff -u before, after, glibc)
- grepped for __NEED, made sure types needed are still in alltypes
- built gcc 3.4.6
2013-07-22 15:22:36 +00:00
|
|
|
typedef union _G_fpos64_t {
|
2011-02-12 05:22:29 +00:00
|
|
|
char __opaque[16];
|
2018-02-24 21:45:33 +00:00
|
|
|
long long __lldata;
|
2011-02-12 05:22:29 +00:00
|
|
|
double __align;
|
|
|
|
} fpos_t;
|
|
|
|
|
|
|
|
extern FILE *const stdin;
|
|
|
|
extern FILE *const stdout;
|
|
|
|
extern FILE *const stderr;
|
|
|
|
|
|
|
|
#define stdin (stdin)
|
|
|
|
#define stdout (stdout)
|
|
|
|
#define stderr (stderr)
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
FILE *fopen(const char *__restrict, const char *__restrict);
|
|
|
|
FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
int fclose(FILE *);
|
|
|
|
|
|
|
|
int remove(const char *);
|
|
|
|
int rename(const char *, const char *);
|
|
|
|
|
|
|
|
int feof(FILE *);
|
|
|
|
int ferror(FILE *);
|
|
|
|
int fflush(FILE *);
|
|
|
|
void clearerr(FILE *);
|
|
|
|
|
|
|
|
int fseek(FILE *, long, int);
|
|
|
|
long ftell(FILE *);
|
|
|
|
void rewind(FILE *);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
int fgetpos(FILE *__restrict, fpos_t *__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
int fsetpos(FILE *, const fpos_t *);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
size_t fread(void *__restrict, size_t, size_t, FILE *__restrict);
|
|
|
|
size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
int fgetc(FILE *);
|
|
|
|
int getc(FILE *);
|
|
|
|
int getchar(void);
|
|
|
|
int ungetc(int, FILE *);
|
|
|
|
|
|
|
|
int fputc(int, FILE *);
|
|
|
|
int putc(int, FILE *);
|
|
|
|
int putchar(int);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
char *fgets(char *__restrict, int, FILE *__restrict);
|
2012-08-26 03:15:13 +00:00
|
|
|
#if __STDC_VERSION__ < 201112L
|
2011-02-12 05:22:29 +00:00
|
|
|
char *gets(char *);
|
2012-08-26 03:15:13 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
int fputs(const char *__restrict, FILE *__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
int puts(const char *);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
int printf(const char *__restrict, ...);
|
|
|
|
int fprintf(FILE *__restrict, const char *__restrict, ...);
|
|
|
|
int sprintf(char *__restrict, const char *__restrict, ...);
|
|
|
|
int snprintf(char *__restrict, size_t, const char *__restrict, ...);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2013-06-26 02:26:20 +00:00
|
|
|
int vprintf(const char *__restrict, __isoc_va_list);
|
|
|
|
int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list);
|
|
|
|
int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list);
|
|
|
|
int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
int scanf(const char *__restrict, ...);
|
|
|
|
int fscanf(FILE *__restrict, const char *__restrict, ...);
|
|
|
|
int sscanf(const char *__restrict, const char *__restrict, ...);
|
2013-06-26 02:26:20 +00:00
|
|
|
int vscanf(const char *__restrict, __isoc_va_list);
|
|
|
|
int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list);
|
|
|
|
int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
void perror(const char *);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
|
|
|
|
void setbuf(FILE *__restrict, char *__restrict);
|
2011-02-14 10:10:10 +00:00
|
|
|
|
|
|
|
char *tmpnam(char *);
|
|
|
|
FILE *tmpfile(void);
|
|
|
|
|
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
2012-05-23 01:52:08 +00:00
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2012-09-07 02:44:55 +00:00
|
|
|
FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
|
2011-09-03 04:45:21 +00:00
|
|
|
FILE *open_memstream(char **, size_t *);
|
2011-02-14 10:10:10 +00:00
|
|
|
FILE *fdopen(int, const char *);
|
|
|
|
FILE *popen(const char *, const char *);
|
|
|
|
int pclose(FILE *);
|
|
|
|
int fileno(FILE *);
|
|
|
|
int fseeko(FILE *, off_t, int);
|
|
|
|
off_t ftello(FILE *);
|
2012-09-07 02:44:55 +00:00
|
|
|
int dprintf(int, const char *__restrict, ...);
|
2013-06-26 02:26:20 +00:00
|
|
|
int vdprintf(int, const char *__restrict, __isoc_va_list);
|
2011-02-12 05:22:29 +00:00
|
|
|
void flockfile(FILE *);
|
|
|
|
int ftrylockfile(FILE *);
|
|
|
|
void funlockfile(FILE *);
|
|
|
|
int getc_unlocked(FILE *);
|
|
|
|
int getchar_unlocked(void);
|
|
|
|
int putc_unlocked(int, FILE *);
|
|
|
|
int putchar_unlocked(int);
|
2012-09-07 02:44:55 +00:00
|
|
|
ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
|
|
|
|
ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
|
2011-02-14 10:10:10 +00:00
|
|
|
int renameat(int, const char *, int, const char *);
|
|
|
|
char *ctermid(char *);
|
2011-02-16 00:47:22 +00:00
|
|
|
#define L_ctermid 20
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2011-02-16 00:47:22 +00:00
|
|
|
#define P_tmpdir "/tmp"
|
2011-02-12 05:22:29 +00:00
|
|
|
char *tempnam(const char *, const char *);
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
2011-02-16 00:47:22 +00:00
|
|
|
#define L_cuserid 20
|
|
|
|
char *cuserid(char *);
|
2011-04-05 16:25:31 +00:00
|
|
|
void setlinebuf(FILE *);
|
|
|
|
void setbuffer(FILE *, char *, size_t);
|
2011-09-12 02:50:02 +00:00
|
|
|
int fgetc_unlocked(FILE *);
|
|
|
|
int fputc_unlocked(int, FILE *);
|
2012-05-29 02:53:24 +00:00
|
|
|
int fflush_unlocked(FILE *);
|
|
|
|
size_t fread_unlocked(void *, size_t, size_t, FILE *);
|
|
|
|
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *);
|
|
|
|
void clearerr_unlocked(FILE *);
|
|
|
|
int feof_unlocked(FILE *);
|
|
|
|
int ferror_unlocked(FILE *);
|
|
|
|
int fileno_unlocked(FILE *);
|
2012-07-04 16:18:04 +00:00
|
|
|
int getw(FILE *);
|
|
|
|
int putw(int, FILE *);
|
2012-08-11 22:10:38 +00:00
|
|
|
char *fgetln(FILE *, size_t *);
|
2012-12-28 20:39:33 +00:00
|
|
|
int asprintf(char **, const char *, ...);
|
2013-06-26 02:26:20 +00:00
|
|
|
int vasprintf(char **, const char *, __isoc_va_list);
|
2012-08-11 22:10:38 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-29 02:53:24 +00:00
|
|
|
#ifdef _GNU_SOURCE
|
2011-09-12 02:50:02 +00:00
|
|
|
char *fgets_unlocked(char *, int, FILE *);
|
|
|
|
int fputs_unlocked(const char *, FILE *);
|
2017-12-05 21:04:43 +00:00
|
|
|
|
|
|
|
typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
|
|
|
|
typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
|
|
|
|
typedef int (cookie_seek_function_t)(void *, off_t *, int);
|
|
|
|
typedef int (cookie_close_function_t)(void *);
|
|
|
|
|
2017-12-06 18:14:22 +00:00
|
|
|
typedef struct _IO_cookie_io_functions_t {
|
2017-12-05 21:04:43 +00:00
|
|
|
cookie_read_function_t *read;
|
|
|
|
cookie_write_function_t *write;
|
|
|
|
cookie_seek_function_t *seek;
|
|
|
|
cookie_close_function_t *close;
|
|
|
|
} cookie_io_functions_t;
|
|
|
|
|
|
|
|
FILE *fopencookie(void *, const char *, cookie_io_functions_t);
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-06-04 12:03:56 +00:00
|
|
|
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
|
2012-05-04 04:13:23 +00:00
|
|
|
#define tmpfile64 tmpfile
|
|
|
|
#define fopen64 fopen
|
|
|
|
#define freopen64 freopen
|
|
|
|
#define fseeko64 fseeko
|
|
|
|
#define ftello64 ftello
|
|
|
|
#define fgetpos64 fgetpos
|
|
|
|
#define fsetpos64 fsetpos
|
|
|
|
#define fpos64_t fpos_t
|
|
|
|
#define off64_t off_t
|
|
|
|
#endif
|
|
|
|
|
2011-02-12 05:22:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|