stdio.h
来自「一个C源代码分析器」· C头文件 代码 · 共 675 行 · 第 1/2 页
H
675 行
/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.This file is part of the GNU C Library.The GNU C Library is free software; you can redistribute it and/ormodify it under the terms of the GNU Library General Public License aspublished by the Free Software Foundation; either version 2 of theLicense, or (at your option) any later version.The GNU C Library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULibrary General Public License for more details.You should have received a copy of the GNU Library General PublicLicense along with the GNU C Library; see the file COPYING.LIB. Ifnot, write to the Free Software Foundation, Inc., 675 Mass Ave,Cambridge, MA 02139, USA. *//* * ANSI Standard: 4.9 INPUT/OUTPUT <stdio.h> */#ifndef _STDIO_H#if !defined(__need_FILE)#define _STDIO_H 1#include <features.h>__BEGIN_DECLS#define __need_size_t#define __need_NULL#include <stddef.h>#define __need___va_list#include <stdarg.h>#ifndef __GNUC_VA_LIST#define __gnuc_va_list __ptr_t#endif#include <gnu/types.h>#endif /* Don't need FILE. */#undef __need_FILE#ifndef __FILE_defined/* The opaque type of streams. */typedef struct __stdio_file FILE;#define __FILE_defined 1#endif /* FILE not defined. */#ifdef _STDIO_H/* The type of the second argument to `fgetpos' and `fsetpos'. */typedef __off_t fpos_t;/* The mode of I/O, as given in the MODE argument to fopen, etc. */typedef struct{ unsigned int __read:1; /* Open for reading. */ unsigned int __write:1; /* Open for writing. */ unsigned int __append:1; /* Open for appending. */ unsigned int __binary:1; /* Opened binary. */ unsigned int __create:1; /* Create the file. */ unsigned int __exclusive:1; /* Error if it already exists. */ unsigned int __truncate:1; /* Truncate the file on opening. */} __io_mode;/* Functions to do I/O and file management for a stream. *//* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF. Return number of bytes read. */typedef __ssize_t __io_read_fn __P ((__ptr_t __cookie, char *__buf, size_t __nbytes));/* Write N bytes pointed to by BUF to COOKIE. Write all N bytes unless there is an error. Return number of bytes written, or -1 if there is an error without writing anything. If the file has been opened for append (__mode.__append set), then set the file pointer to the end of the file and then do the write; if not, just write at the current file pointer. */typedef __ssize_t __io_write_fn __P ((__ptr_t __cookie, __const char *__buf, size_t __n));/* Move COOKIE's file position to *POS bytes from the beginning of the file (if W is SEEK_SET), the current position (if W is SEEK_CUR), or the end of the file (if W is SEEK_END). Set *POS to the new file position. Returns zero if successful, nonzero if not. */typedef int __io_seek_fn __P ((__ptr_t __cookie, fpos_t *__pos, int __w));/* Close COOKIE. */typedef int __io_close_fn __P ((__ptr_t __cookie));/* Return the file descriptor associated with COOKIE, or -1 on error. There need not be any associated file descriptor. */typedef int __io_fileno_fn __P ((__ptr_t __cookie));#ifdef __USE_GNU/* User-visible names for the above. */typedef __io_read_fn cookie_read_function_t;typedef __io_write_fn cookie_write_function_t;typedef __io_seek_fn cookie_seek_function_t;typedef __io_close_fn cookie_close_function_t;typedef __io_fileno_fn cookie_fileno_function_t;#endif/* Low level interface, independent of FILE representation. */#if defined (__USE_GNU) && !defined (_LIBC)/* Define the user-visible type, with user-friendly member names. */typedef struct{ __io_read_fn *read; /* Read bytes. */ __io_write_fn *write; /* Write bytes. */ __io_seek_fn *seek; /* Seek/tell file position. */ __io_close_fn *close; /* Close file. */ __io_fileno_fn *fileno; /* Return file descriptor. */} cookie_io_functions_t;/* This name is still used in the prototypes in this file. */typedef cookie_io_functions_t __io_functions;#else/* Stick to ANSI-safe names. */typedef struct{ __io_read_fn *__read; /* Read bytes. */ __io_write_fn *__write; /* Write bytes. */ __io_seek_fn *__seek; /* Seek/tell file position. */ __io_close_fn *__close; /* Close file. */ __io_fileno_fn *__fileno; /* Return file descriptor. */} __io_functions;#endif/* Higher level interface, dependent on FILE representation. */typedef struct{ /* Make room in the input buffer. */ int (*__input) __P ((FILE *__stream)); /* Make room in the output buffer. */ void (*__output) __P ((FILE *__stream, int __c));} __room_functions;extern __const __io_functions __default_io_functions;extern __const __room_functions __default_room_functions;/* Default close function. */extern __io_close_fn __stdio_close;/* Open FILE with mode M, store cookie in *COOKIEPTR. */extern int __stdio_open __P ((__const char *__file, __io_mode __m, __ptr_t *__cookieptr));/* Put out an error message for when stdio needs to die. */extern void __stdio_errmsg __P ((__const char *__msg, size_t __len));/* Generate a unique file name (and possibly open it with mode "w+b"). */extern char *__stdio_gen_tempname __P ((__const char *__dir, __const char *__pfx, int __dir_search, size_t *__lenptr, FILE **__streamptr));/* Print out MESSAGE on the error output and abort. */extern __NORETURN void __libc_fatal __P ((__const char *__message));/* The FILE structure. */struct __stdio_file{ /* Magic number for validation. Must be negative in open streams for the glue to Unix stdio getc/putc to work. NOTE: stdio/glue.c has special knowledge of these first four members. */ int __magic;#define _IOMAGIC 0xfedabeeb /* Magic number to fill `__magic'. */#define _GLUEMAGIC 0xfeedbabe /* Magic for glued Unix streams. */ char *__bufp; /* Pointer into the buffer. */ char *__get_limit; /* Reading limit. */ char *__put_limit; /* Writing limit. */ char *__buffer; /* Base of buffer. */ size_t __bufsize; /* Size of the buffer. */ __ptr_t __cookie; /* Magic cookie. */ __io_mode __mode; /* File access mode. */ __io_functions __io_funcs; /* I/O functions. */ __room_functions __room_funcs;/* I/O buffer room functions. */ fpos_t __offset; /* Current file position. */ fpos_t __target; /* Target file position. */ FILE *__next; /* Next FILE in the linked list. */ char *__pushback_bufp; /* Old bufp if char pushed back. */ unsigned char __pushback; /* Pushed-back character. */ unsigned int __pushed_back:1; /* A char has been pushed back. */ unsigned int __eof:1; /* End of file encountered. */ unsigned int __error:1; /* Error encountered. */ unsigned int __userbuf:1; /* Buffer from user (should not be freed). */ unsigned int __linebuf:1; /* Flush on newline. */ unsigned int __linebuf_active:1; /* put_limit is not really in use. */ unsigned int __seen:1; /* This stream has been seen. */ unsigned int __ispipe:1; /* Nonzero if opened by popen. */};/* All macros used internally by other macros here and by stdio functions begin with `__'. All of these may evaluate their arguments more than once. *//* Nonzero if STREAM is a valid stream. STREAM must be a modifiable lvalue (wow, I got to use that term). See stdio/glue.c for what the confusing bit is about. */#define __validfp(stream) \ (stream != NULL && \ ((stream->__magic == _GLUEMAGIC && \ (stream = *(((struct { int __magic; FILE **__p; } *) stream)->__p))), \ (stream->__magic == _IOMAGIC)))/* Clear the error and EOF indicators of STREAM. */#define __clearerr(stream) ((stream)->__error = (stream)->__eof = 0)/* Nuke STREAM, making it unusable but available for reuse. */extern void __invalidate __P ((FILE *__stream));/* Make sure STREAM->__offset and STREAM->__target are initialized. Returns 0 if successful, or EOF on error (but doesn't set STREAM->__error). */extern int __stdio_check_offset __P ((FILE *__stream));/* The possibilities for the third argument to `setvbuf'. */#define _IOFBF 0x1 /* Full buffering. */#define _IOLBF 0x2 /* Line buffering. */#define _IONBF 0x4 /* No buffering. *//* Default buffer size. */#define BUFSIZ 1024/* End of file character. Some things throughout the library rely on this being -1. */#define EOF (-1)/* The possibilities for the third argument to `fseek'. These values should not be changed. */#define SEEK_SET 0 /* Seek from beginning of file. */#define SEEK_CUR 1 /* Seek from current position. */#define SEEK_END 2 /* Seek from end of file. */#ifdef __USE_SVID/* Default path prefix for `tempnam' and `tmpnam'. */#define P_tmpdir "/usr/tmp"#endif/* Get the values: L_tmpnam How long an array of chars must be to be passed to `tmpnam'. TMP_MAX The minimum number of unique filenames generated by tmpnam (and tempnam when it uses tmpnam's name space), or tempnam (the two are separate). L_ctermid How long an array to pass to `ctermid'. L_cuserid How long an array to pass to `cuserid'. FOPEN_MAX Mininum number of files that can be open at once. FILENAME_MAX Maximum length of a filename. */#include <stdio_lim.h>/* All the known streams are in a linked list linked by the `next' field of the FILE structure. */extern FILE *__stdio_head; /* Head of the list. *//* Standard streams. */extern FILE *stdin, *stdout, *stderr;/* Remove file FILENAME. */extern int remove __P ((__const char *__filename));/* Rename file OLD to NEW. */extern int rename __P ((__const char *__old, __const char *__new));/* Create a temporary file and open it read/write. */extern FILE *tmpfile __P ((void));/* Generate a temporary filename. */extern char *tmpnam __P ((char *__s));#ifdef __USE_SVID/* Generate a unique temporary filename using up to five characters of PFX if it is not NULL. The directory to put this file in is searched for as follows: First the environment variable "TMPDIR" is checked. If it contains the name of a writable directory, that directory is used. If not and if DIR is not NULL, that value is checked. If that fails, P_tmpdir is tried and finally "/tmp". The storage for the filename is allocated by `malloc'. */extern char *tempnam __P ((__const char *__dir, __const char *__pfx));#endif/* This performs actual output when necessary, flushing STREAM's buffer and optionally writing another character. */extern int __flshfp __P ((FILE *__stream, int __c));/* Close STREAM, or all streams if STREAM is NULL. */extern int fclose __P ((FILE *__stream));/* Flush STREAM, or all streams if STREAM is NULL. */extern int fflush __P ((FILE *__stream));/* Open a file and create a new stream for it. */extern FILE *fopen __P ((__const char *__filename, __const char *__modes));/* Open a file, replacing an existing stream with it. */extern FILE *freopen __P ((__const char *__filename, __const char *__modes, FILE *__stream));/* Return a new, zeroed, stream. You must set its cookie and io_mode. The first operation will give it a buffer unless you do. It will also give it the default functions unless you set the `seen' flag. The offset is set to -1, meaning it will be determined by doing a stationary seek. You can set it to avoid the initial tell call. The target is set to -1, meaning it will be set to the offset before the target is needed. Returns NULL if a stream can't be created. */extern FILE *__newstream __P ((void));#ifdef __USE_POSIX/* Create a new stream that refers to an existing system file descriptor. */extern FILE *fdopen __P ((int __fd, __const char *__modes));#endif#ifdef __USE_GNU/* Create a new stream that refers to the given magic cookie, and uses the given functions for input and output. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?