stdio.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:11k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* stdio.h - stdio header file */
  2. /* Copyright 1992-1999 Wind River Systems, Inc. */
  3. /* Copyright (c) 1990 The Regents of the University of California */
  4. /*
  5. modification history
  6. --------------------
  7. 02l,17feb99,mrs  Add C++ support for NULL, (SPR #25079).
  8. 02k,10dec93,smb  added include  of private/classLibP.h for OBJ_VERIFY
  9. 02j,14nov92,jcf  added prototype for stdioShowInit().
  10. 02i,13nov92,dnw  changed defns of stdin,out,err to be assignable (SPR #1770)
  11.  removed include of taskLib.h (SPR #1768)
  12.  made include of stdarg.h conditional on __STDC__
  13. 02h,24sep92,smb  removed POSIX extensions.
  14. 02g,22sep92,rrr  added support for c++
  15. 02f,10sep92,rfs  removed FAST from stdioShow prototype
  16. 02e,08sep92,smb  added #ifndef around EOF definition.
  17. 02d,07sep92,smb  added prototypes for stdioShow() and stdioInit().
  18. 02c,02aug92,jcf  added _swbuf()/_srget() prototypes.
  19. 02b,31jul92,rrr  changed __sclearerr() definition.
  20. 02a,29jul92,smb  rewritten based on UCB stdio.
  21.    This code is derived from software contributed to Berkeley by
  22.    Chris Torek.
  23. 01p,04jul92,jcf  cleaned up.
  24. 01o,26may92,rrr  the tree shuffle
  25. 01n,05dec91,rrr  added missings routines to !__STDC__ section
  26. 01m,26nov91,llk  added include of stdarg.h as per Marc Ullman.
  27. 01l,07oct91,rrr  fixed fread and fwrite.
  28. 01k,04oct91,rrr  passed through the ansification filter
  29.   -fixed #else and #endif
  30.   -changed VOID to void
  31.   -changed copyright notice
  32. 01j,10jun91.del  added pragma for gnu960 alignment.
  33. 01i,21may91,kdl  added non-ANSI def's for stdioFillBuf() and stdioFlushBuf().
  34. 01h,10jan91,shl  fixed stdioFillBuf() type int, fixed stdioFlushBuf
  35.  argument type.  changed remove() and rename() to have
  36.  same type as in ioLib.h
  37. 01g,19oct90,shl  added #include of stddef.h and stdarg.h.
  38. 01f,05oct90,dnw  added definitions for ANSI compatibility.
  39. 01e,05oct90,shl  added ANSI function prototypes.
  40.                  made #endif ANSI style.
  41.                  added copyright notice.
  42. 01d,07aug90,shl  added function declarations comment.
  43. 01c,18mar90,jcf  made stdin/stdout/stderr macros thru taskIdCurrent.
  44. 01b,30jan90,dab  changed declaration of sprintf() from char ptr to int.
  45. 01a,28mar88,gae  created.
  46. */
  47. #ifndef __INCstdioh
  48. #define __INCstdioh
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. #include "types/vxANSI.h" /* includes size_t and fpos_t types */
  53. #include "classLib.h"
  54. #include "errno.h"
  55. #include "private/objLibP.h"
  56. #include "private/classLibP.h"
  57. #if defined(__STDC__) || defined(__cplusplus)
  58. #include "stdarg.h"
  59. #endif /* __STDC__ */
  60. #ifndef NULL
  61. #if defined __GNUG__
  62. #define NULL (__null)
  63. #else
  64. #if !defined(__cplusplus) && 0
  65. #define NULL ((void*)0)
  66. #else
  67. #define NULL (0)
  68. #endif
  69. #endif
  70. #endif
  71. /* types */
  72. struct __sbuf  /* stdio buffers */
  73.     {
  74.     uchar_t * _base; /* base address of {std,unget,line} buffer */
  75.     int       _size; /* size of the buffer */
  76.     };
  77. typedef struct __sFILE
  78.     {
  79.     OBJ_CORE objCore; /* file pointer object core */
  80.     uchar_t * _p; /* current position in (some) buffer */
  81.     int _r; /* read space left for getc() */
  82.     int _w; /* write space left for putc() */
  83.     short _flags; /* flags, below;this FILE is free if 0*/
  84.     short _file; /* fileno, if Unix descriptor, else -1*/
  85.     struct __sbuf _bf; /* buffer (at least 1 byte,if !NULL) */
  86.     int _lbfsize; /* 0 or -_bf._size, for inline putc */
  87.     struct __sbuf _ub; /* ungetc buffer */
  88.     uchar_t * _up; /* old _p if _p is doing ungetc data */
  89.     int _ur; /* old _r if _r counting ungetc data */
  90.     uchar_t _ubuf[3]; /* guarantee an ungetc() buffer */
  91.     uchar_t _nbuf[1]; /* guarantee a getc() buffer */
  92.     struct __sbuf _lb; /* buffer for fgetline() */
  93.     int _blksize; /* stat.st_blksize (may be!=_bf._size)*/
  94.     int _offset; /* current lseek offset */
  95.     int taskId; /* task that owns this file pointer */
  96.     } FILE;
  97. /* class definition */
  98. extern CLASS_ID fpClassId; /* file pointer class id */
  99. /* __SRD and __SWR are never simultaneously asserted */
  100. #define __SLBF 0x0001 /* line buffered */
  101. #define __SNBF 0x0002 /* unbuffered */
  102. #define __SRD 0x0004 /* OK to read */
  103. #define __SWR 0x0008 /* OK to write */
  104. #define __SWRNBF (__SWR|__SNBF) /* write unbuffered */
  105. #define __SRW 0x0010 /* open for reading & writing */
  106. #define __SEOF 0x0020 /* found EOF */
  107. #define __SERR 0x0040 /* found error */
  108. #define __SMBF 0x0080 /* _buf is from malloc */
  109. #define __SAPP 0x0100 /* fdopen()ed in append mode */
  110. #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
  111. #define __SOPT 0x0400 /* do fseek() optimisation */
  112. #define __SNPT 0x0800 /* do not do fseek() optimisation */
  113. #define __SOFF 0x1000 /* set iff _offset is in fact correct */
  114. #define __SMOD 0x2000 /* true => fgetline modified _p text */
  115. #define _IOFBF 0 /* setvbuf should set fully buffered */
  116. #define _IOLBF 1 /* setvbuf should set line buffered */
  117. #define _IONBF 2 /* setvbuf should set unbuffered */
  118. #define BUFSIZ _PARM_BUFSIZ /* size of buffer used by setbuf */
  119. #define BUFSIZE BUFSIZ
  120. #ifndef EOF
  121. #define EOF (-1)
  122. #endif  /* EOF */
  123. #define FOPEN_MAX       _PARM_FOPEN_MAX
  124. #define FILENAME_MAX    _PARM_FILENAME_MAX
  125. #define L_tmpnam _PARM_L_tmpnam
  126. #define TMP_MAX _PARM_TMP_MAX
  127. #ifndef SEEK_SET
  128. #define SEEK_SET 0 /* set file offset to offset */
  129. #endif
  130. #ifndef SEEK_CUR
  131. #define SEEK_CUR 1 /* set file offset to current plus offset */
  132. #endif
  133. #ifndef SEEK_END
  134. #define SEEK_END 2 /* set file offset to EOF plus offset */
  135. #endif
  136. #if _EXTENSION_POSIX_1003
  137. #define L_cuserid _PARM_L_cuserid
  138. #define L_ctermid _PARM_L_ctermid
  139. #define STREAM_MAX      FOPEN_MAX
  140. #endif /* _EXTENSION_POSIX_1003 */
  141. #if defined(__STDC__) || defined(__cplusplus)
  142. extern void clearerr (FILE *);
  143. extern int fclose (FILE *);
  144. extern int feof (FILE *);
  145. extern int ferror (FILE *);
  146. extern int fflush (FILE *);
  147. extern int fgetc (FILE *);
  148. extern int fgetpos (FILE *, fpos_t *);
  149. extern char * fgets (char *, size_t, FILE *);
  150. extern FILE * fopen (const char *, const char *);
  151. extern int fprintf (FILE *, const char *, ...);
  152. extern int fputc (int, FILE *);
  153. extern int fputs (const char *, FILE *);
  154. extern int fread (void *, size_t, size_t, FILE *);
  155. extern FILE * freopen (const char *, const char *, FILE *);
  156. extern int fscanf (FILE *, const char *, ...);
  157. extern int fseek (FILE *, long, int);
  158. extern int fsetpos (FILE *, const fpos_t *);
  159. extern long ftell (FILE *);
  160. extern int fwrite (const void *, size_t, size_t, FILE *);
  161. extern int getc (FILE *);
  162. extern int getchar (void);
  163. extern char * gets (char *);
  164. extern void perror (const char *);
  165. extern int printf (const char *, ...);
  166. extern int putc (int, FILE *);
  167. extern int putchar (int);
  168. extern int puts (const char *);
  169. extern int remove (const char *);
  170. extern int rename  (const char *, const char *);
  171. extern void rewind (FILE *);
  172. extern int scanf (const char *, ...);
  173. extern void setbuf (FILE *, char *);
  174. extern int setvbuf (FILE *, char *, int, size_t);
  175. extern int sprintf (char *, const char *, ...);
  176. extern int sscanf (const char *, const char *, ...);
  177. extern FILE * tmpfile (void);
  178. extern char * tmpnam (char *);
  179. extern int ungetc (int, FILE *);
  180. extern int vfprintf (FILE *, const char *, va_list);
  181. extern int vprintf (const char *, va_list);
  182. extern int vsprintf (char *, const char *, va_list);
  183. extern int __srget (FILE *); /* for macro definition below */
  184. extern int __swbuf (int, FILE *); /* for macro definition below */
  185. /* _EXTENSION_POSIX_1003 */
  186. extern FILE * fdopen (int, const char *);
  187. extern int fileno (FILE *);
  188. /* _EXTENSION_POSIX_1003 */
  189. /* WRS stdio functions declarations */
  190. #if _EXTENSION_WRS /* undef for ANSI */
  191. extern int fdprintf (int fd, const char *fmt, ...);
  192. extern int vfdprintf (int fd, const char *fmt, va_list ap);
  193. extern int printErr (const char *fmt, ...);
  194. extern int getw (FILE *);
  195. extern int putw (int, FILE *);
  196. extern void setbuffer (FILE *, char *, int);
  197. extern int setlinebuf (FILE *);
  198. extern FILE *   stdioFp (int std);
  199. extern STATUS   stdioShow (FILE * fp, int level);
  200. extern STATUS   stdioShowInit (void);
  201. extern STATUS   stdioInit (void);
  202. #endif /* _EXTENSION_WRS */
  203. #else /* __STDC__ */
  204. extern void clearerr ();
  205. extern int fclose ();
  206. extern int feof ();
  207. extern int ferror ();
  208. extern int fflush ();
  209. extern int fgetc ();
  210. extern int fgetpos ();
  211. extern char * fgets ();
  212. extern FILE * fopen ();
  213. extern int fprintf ();
  214. extern int fputc ();
  215. extern int fputs ();
  216. extern int fread ();
  217. extern FILE * freopen ();
  218. extern int fscanf ();
  219. extern int fseek ();
  220. extern int fsetpos ();
  221. extern long ftell ();
  222. extern int fwrite ();
  223. extern int getc ();
  224. extern int getchar ();
  225. extern char * gets ();
  226. extern void perror ();
  227. extern int printf ();
  228. extern int putc ();
  229. extern int putchar ();
  230. extern int puts ();
  231. extern int remove ();
  232. extern int rename  ();
  233. extern void rewind ();
  234. extern int scanf ();
  235. extern void setbuf ();
  236. extern int setvbuf ();
  237. extern int sprintf ();
  238. extern int sscanf ();
  239. extern FILE * tmpfile ();
  240. extern char * tmpnam ();
  241. extern int ungetc ();
  242. extern int vfprintf ();
  243. extern int vprintf ();
  244. extern int vsprintf ();
  245. extern int __srget (); /* for macro definition below */
  246. extern int __swbuf (); /* for macro definition below */
  247. /* _EXTENSION_POSIX_1003 */
  248. extern FILE * fdopen ();
  249. extern int fileno ();
  250. /* _EXTENSION_POSIX_1003 */
  251. /* WRS stdio functions declarations */
  252. #if _EXTENSION_WRS /* undef for ANSI */
  253. extern int fdprintf ();
  254. extern int vfdprintf ();
  255. extern int printErr ();
  256. extern int getw ();
  257. extern int putw ();
  258. extern void setbuffer ();
  259. extern int setlinebuf ();
  260. extern FILE *   stdioFp ();
  261. extern STATUS   stdioShow ();
  262. extern STATUS   stdioShowInit ();
  263. extern STATUS   stdioInit ();
  264. #endif /* _EXTENSION_WRS */
  265. #endif /* __STDC__ */
  266. /* Definition of stdin, stdout, stderr */
  267. #if defined(__STDC__) || defined(__cplusplus)
  268. extern FILE ** __stdin(void); /* returns current task's stdin */
  269. extern FILE ** __stdout(void); /* returns current task's stdout */
  270. extern FILE ** __stderr(void); /* returns current task's stderr */
  271. #else
  272. extern FILE ** __stdin();
  273. extern FILE ** __stdout();
  274. extern FILE ** __stderr();
  275. #endif /* __STDC__ */
  276. #define stdin (*__stdin())
  277. #define stdout (*__stdout())
  278. #define stderr (*__stderr())
  279. /* definition of stdio macros */
  280. #define __sfileno(p) ((OBJ_VERIFY(p,fpClassId) != OK) ? (-1) : ((p)->_file))
  281. #define __sgetc(p) ((OBJ_VERIFY(p,fpClassId) != OK) ? (EOF) :
  282.  ((--(p)->_r < 0) ? (__srget(p)) : ((int)(*(p)->_p++))))
  283. #define __sputc(c, p)  ((OBJ_VERIFY(p,fpClassId) != OK) ? (EOF) :
  284.  (--(p)->_w < 0 ?
  285.      (p)->_w >= (p)->_lbfsize ?
  286.  (*(p)->_p = (c)), *(p)->_p != 'n' ?
  287.      (int)*(p)->_p++ :
  288.      __swbuf('n', p) :
  289.  __swbuf((int)(c), p) : 
  290.      (*(p)->_p = (c), (int)*(p)->_p++)))
  291. #define __sfeof(p) ((OBJ_VERIFY(p,fpClassId) != OK) ? 
  292.  (FALSE) : (((p)->_flags & __SEOF) != 0))
  293. #define __sferror(p) ((OBJ_VERIFY(p,fpClassId) != OK) ? 
  294.  (FALSE) : (((p)->_flags & __SERR) != 0))
  295. #define __sclearerr(p) ((void)((OBJ_VERIFY(p,fpClassId) != OK) ? 
  296. (0) : (((p)->_flags &= ~(__SERR|__SEOF)))))
  297. #define getchar() __sgetc(stdin)
  298. #define getc(p) __sgetc(p)
  299. #define putchar(c) (__sputc(c, (stdout)))
  300. #define putc(c,p) __sputc(c, p)
  301. #define feof(p) __sfeof(p)
  302. #define ferror(p) __sferror(p)
  303. #define clearerr(p) __sclearerr(p)
  304. #if _EXTENSION_POSIX_1003 /* undef for ANSI */
  305. #define fileno(p) __sfileno(p)
  306. #endif
  307. #ifdef __cplusplus
  308. }
  309. #endif
  310. #endif /* __INCstdioh */