stdio.mh

来自「开放源码的编译器open watcom 1.6.0版的源代码」· MH 代码 · 共 738 行 · 第 1/2 页

MH
738
字号
/**************************************************************************
 * FILE: stdio.h/cstdio (Standard I/O functions)
 *
:include crwatqnx.sp
 *
 * Description: This header is part of the C/C++ standard library. It
 *              describes the I/O facilities provided by the C standard.
 **************************************************************************/
:segment CNAME
#ifndef _CSTDIO_INCLUDED
#define _CSTDIO_INCLUDED

#ifndef __cplusplus
#error the header cstdio requires C++
#endif
:elsesegment
#ifndef _STDIO_H_INCLUDED
#define _STDIO_H_INCLUDED
:endsegment

:include readonly.sp
::
:: The following somewhat long segment only appears in stdio.h.
:segment !CNAME
#ifdef __cplusplus
#include <cstdio>

// C99 types in stdio.h.
using std::FILE;
using std::fpos_t;
#ifndef _SIZE_T_DEFINED
#define _SIZE_T_DEFINED
#define _SIZE_T_DEFINED_
using std::size_t;
#endif

// C99 functions in stdio.h.
using std::clearerr;
using std::fclose;
using std::feof;
using std::ferror;
using std::fflush;
using std::fgetc;
using std::fgetpos;
using std::fgets;
using std::fopen;
using std::fprintf;
using std::fputc;
using std::fputs;
using std::fread;
using std::freopen;
using std::fscanf;
using std::fseek;
using std::fsetpos;
using std::ftell;
using std::fwrite;
using std::getc;
using std::getchar;
using std::gets;
using std::perror;
using std::printf;
using std::putc;
using std::putchar;
using std::puts;
using std::remove;
using std::rename;
using std::rewind;
using std::scanf;
using std::setbuf;
using std::setvbuf;
using std::sprintf;
using std::sscanf;
using std::tmpfile;
using std::tmpnam;
using std::ungetc;
using std::vfprintf;
using std::vprintf;
using std::vsprintf;

:: Now the extensions section.
:include ext.sp
// C99 types that are not specified for stdio.h
#ifndef _WCTYPE_T_DEFINED
#define _WCTYPE_T_DEFINED
#define _WCTYPE_T_DEFINED_
using std::wint_t;
using std::wctype_t;
#endif

// C99 functions in stdio.h that are currently considered extensions.
using std::snprintf;
using std::vfscanf;
using std::vscanf;
using std::vsnprintf;
using std::vsscanf;

:segment !SNAPDRV & !NO_WIDECHAR
// C99 functions that are not specified for stdio.h
using std::fgetwc;
using std::fgetws;
using std::fputwc;
using std::fputws;
using std::fwprintf;
using std::fwscanf;
using std::getwc;
using std::getwchar;
using std::putwc;
using std::putwchar;
#ifndef swprintf
using std::swprintf;
#endif
using std::swscanf;
using std::ungetwc;
using std::vfwprintf;
using std::vfwscanf;
using std::vswprintf;
using std::vswscanf;
using std::vwprintf;
using std::vwscanf;
using std::wprintf;
using std::wscanf;
:endsegment
#endif

#else /* __cplusplus not defined */
:: End of segment that is only in stdio.h
:endsegment

:: Only need extern "C" in cstdio
:segment CNAME
:include cpluspro.sp
:endsegment

#ifndef _COMDEF_H_INCLUDED
 #include <_comdef.h>
#endif

:include pshpackl.sp

:include sizet.sp

:include null.sp

:include valist.sp

:segment QNX | LINUX
#define BUFSIZ          4096        /*  Default buffer size                 */
#define _NFILES         16          /*  minimum guaranteed open files       */
#define FILENAME_MAX    255
:elsesegment
#if defined(__386__) || defined(__AXP__) || defined(__PPC__)
 #define BUFSIZ         4096
#else
 #define BUFSIZ         512
#endif
::
#define _NFILES         20      /* number of files that can be handled */
#if defined(__OS2__) || defined(__NT__)
 #define FILENAME_MAX   260
#else
 #define FILENAME_MAX   144
#endif
:endsegment

:: This (strange?) technique keeps the name '__iobuf' in the global namespace.
struct __stream_link;
struct __iobuf;
#if !defined(__OBSCURE_STREAM_INTERNALS)
struct __iobuf {
    unsigned char        *_ptr;         /* next character position */
    int                   _cnt;         /* number of characters left */
    struct __stream_link *_link;        /* location of associated struct */
    unsigned              _flag;        /* mode of file access */
    int                   _handle;      /* file handle */
    unsigned              _bufsize;     /* size of buffer */
    unsigned short        _ungotten;    /* used by ungetc and ungetwc */
:segment QNX
    struct __iobuf       *_unused;      /* spare entry */
:endsegment
};
#endif

:segment CNAME
namespace std {
:endsegment
typedef struct __iobuf FILE;
typedef long           fpos_t;
:segment CNAME
}
:endsegment

:segment QNX | LINUX
#define FOPEN_MAX   _NFILES
:elsesegment
:include ext.sp
 #define FOPEN_MAX      _NFILES
 #define OPEN_MAX       FOPEN_MAX
 #if defined(__OS2__) || defined(__NT__)
  #define PATH_MAX      259 /* maximum length of full pathname excl. '\0' */
 #else
  #define PATH_MAX      143 /* maximum length of full pathname excl. '\0' */
 #endif
#else                   /* extensions not enabled */
 #define FOPEN_MAX      (_NFILES-2)
#endif
:endsegment

:segment CNAME
_WCRTLINK extern std::FILE  *__get_iob_ptr( void );
:elsesegment
_WCRTLINK extern FILE       *__get_iob_ptr( void );
:endsegment
#if defined(__FUNCTION_DATA_ACCESS)
 #define __iob          (*__get_iob_ptr())
#elif defined(__SW_BR) || defined(_RTDLL)
 #define __iob          __iob_br
#endif

#if !defined(__OBSCURE_STREAM_INTERNALS)
:segment CNAME
_WCRTDATA extern std::FILE _WCNEAR __iob[];
/*
 *  Define macros to access the three default file pointer (and descriptors)
 *  provided to each process by default. They will always occupy the
 *  first three file pointers in each processes' table.
 */
#define stdin   ((std::FILE *)&__iob[0])     /* standard input file  */
#define stdout  ((std::FILE *)&__iob[1])     /* standard output file */
#define stderr  ((std::FILE *)&__iob[2])     /* standard error file  */
:elsesegment
_WCRTDATA extern FILE _WCNEAR __iob[];
/*
 *  Define macros to access the three default file pointer (and descriptors)
 *  provided to each process by default. They will always occupy the
 *  first three file pointers in each processes' table.
 */
#define stdin   ((FILE *)&__iob[0])     /* standard input file  */
#define stdout  ((FILE *)&__iob[1])     /* standard output file */
#define stderr  ((FILE *)&__iob[2])     /* standard error file  */
:endsegment
:segment DOS
#ifndef NO_EXT_KEYS     /* extensions enabled */
#if defined(__DOS__) || defined(__WINDOWS__) || defined(__OSI__)
:segment CNAME
#define stdaux  ((std::FILE *)&__iob[3])     /* standard auxiliary file  */
#define stdprn  ((std::FILE *)&__iob[4])     /* standard printer file  */
:elsesegment
#define stdaux  ((FILE *)&__iob[3])     /* standard auxiliary file  */
#define stdprn  ((FILE *)&__iob[4])     /* standard printer file  */
:endsegment
#endif
#endif
:endsegment

#else /* __OBSCURE_STREAM_INTERNALS is defined */

:segment CNAME
_WCRTLINK extern std::FILE *__get_std_file(unsigned handle);
:elsesegment
_WCRTLINK extern FILE *__get_std_file(unsigned handle);
:endsegment

#define stdin   (__get_std_file(0))     /* standard input file  */
#define stdout  (__get_std_file(1))     /* standard output file */
#define stderr  (__get_std_file(2))     /* standard error file  */
:segment DOS
#ifndef NO_EXT_KEYS     /* extensions enabled */
#if defined(__DOS__) || defined(__WINDOWS__)
#define stdaux  (__get_std_file(3))     /* standard auxiliary file  */
#define stdprn  (__get_std_file(4))     /* standard printer file  */
#endif
#endif
:endsegment

#endif /* __OBSCURE_STREAM_INTERNALS */

:segment QNX | LINUX
/* values for _flag field in FILE struct */
:elsesegment
/* values for _flag field in FILE struct and _iomode array */
:endsegment

#define _READ   0x0001  /* file opened for reading */
#define _WRITE  0x0002  /* file opened for writing */
:segment QNX | LINUX
#define _UNGET  0x0100  /* ungetc has been done */
:elsesegment
#define _UNGET  0x0004  /* ungetc has been done */
:endsegment
#define _BIGBUF 0x0008  /* big buffer allocated */
#define _EOF    0x0010  /* EOF has occurred */
#define _SFERR  0x0020  /* error has occurred on this file */
#define _APPEND 0x0080  /* file opened for append */
:segment QNX | LINUX
#define _BINARY 0x0000  /* not required for POSIX QNX       */
#define _IOFBF  0x0000  /*  full buffering                  */
#define _IOLBF  0x0040  /*  line buffering                  */
#define _IONBF  0x0004  /*  no buffering                    */
:elsesegment
#define _BINARY 0x0040  /* file is binary, skip CRLF processing */
#define _IOFBF  0x0100  /* full buffering */
#define _IOLBF  0x0200  /* line buffering */
#define _IONBF  0x0400  /* no buffering */
:endsegment
#define _TMPFIL 0x0800  /* this is a temporary file */
#define _DIRTY  0x1000  /* buffer has been modified */
#define _ISTTY  0x2000  /* is console device */
#define _DYNAMIC 0x4000 /* FILE is dynamically allocated   */
#define _FILEEXT 0x8000 /* lseek with positive offset has been done */
#define _COMMIT 0x0001  /* extended flag: commit OS buffers on flush */

#define EOF         (-1)                /*  End of File/Error return code   */

#define SEEK_SET    0                   /*  Seek relative to start of file  */
#define SEEK_CUR    1                   /*  Seek relative to current positn */
#define SEEK_END    2                   /*  Seek relative to end of file    */

#define _NOT_ORIENTED   0               /* stream not yet oriented */
#define _BYTE_ORIENTED  1               /* byte-oriented stream */
#define _WIDE_ORIENTED  2               /* wide-oriented stream */

:segment QNX | LINUX
:include unixext.sp
#define L_cuserid   14                  /*  Max length of login names       */
#define L_ctermid   16                  /*  Max length of terminal names    */
#define P_tmpdir    "/usr/tmp"          /*  Temporary file directory        */
#endif
#define L_tmpnam    255                 /*  Max length of tmp file names    */
:elsesegment
#define L_tmpnam    13
#define _P_tmpdir   "\\"                /* used by _tempnam */
#define _wP_tmpdir  L"\\"               /* used by _wtempnam */
:endsegment
#define TMP_MAX     (26*26*26)          /*  Max times tmpnam can be called  */

:: Declarations of standard C99 functions (but see below for more information).
:segment CNAME
namespace std {
:endsegment
_WCRTLINK extern void   clearerr( FILE *__fp );
_WCRTLINK extern int    fclose( FILE *__fp );
_WCRTLINK extern int    feof( FILE *__fp );
_WCRTLINK extern int    ferror( FILE *__fp );
_WCRTLINK extern int    fflush( FILE *__fp );
_WCRTLINK extern int    fgetc( FILE *__fp );
_WCRTLINK extern int    fgetpos( FILE *__fp, fpos_t *__pos );
_WCRTLINK extern char   *fgets( char *__s, int __n, FILE *__fp );
_WCRTLINK extern FILE   *fopen( const char *__filename, const char *__mode );
_WCRTLINK extern int    fprintf( FILE *__fp, const char *__format, ... );
_WCRTLINK extern int    fputc( int __c, FILE *__fp );
_WCRTLINK extern int    fputs( const char *__s, FILE *__fp );
_WCRTLINK extern size_t fread( void *__ptr, size_t __size, size_t __n,
                               FILE *__fp );
_WCRTLINK extern FILE   *freopen( const char *__filename, const char *__mode,
                                 FILE *__fp );
_WCRTLINK extern int    fscanf( FILE*__fp, const char *__format, ... );
_WCRTLINK extern int    fseek( FILE *__fp, long int __offset, int __whence );
_WCRTLINK extern int    fsetpos( FILE *__fp, const fpos_t *__pos );
_WCRTLINK extern long   ftell( FILE *__fp );
_WCRTLINK extern size_t fwrite( const void *__ptr, size_t __size, size_t __n,
                                FILE *__fp );
_WCRTLINK extern int    getc( FILE *__fp );
_WCRTLINK extern int    getchar( void );
_WCRTLINK extern char   *gets( char *__s );
_WCRTLINK extern void   perror( const char *__s );
_WCRTLINK extern int    printf( const char *__format, ... );
_WCRTLINK extern int    putc( int __c, FILE *__fp );
_WCRTLINK extern int    putchar( int __c );
_WCRTLINK extern int    puts( const char *__s );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?