IO之Standard IO

时间:2022-07-23
本文章向大家介绍IO之Standard IO,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

VxWorks provides a standard I/O package (stdio.h) with full ANSI C support that is compatible with the UNIX and Windows standard I/O packages.

/* ANSI */

/* 
 * open a file specified by name
 * r  : open text file for reading
 * w  : truncate to zero length or create text file for writing
 * a  : append; open or create text file for writing at end-of-file
 * rb : open binary file for reading
 * wb : truncate to zero length or create binary file for writing
 * ab : append; open or create binary file for writing at end-of-file
 * r+ : open text file for update (reading and writing)
 * w+ : truncate to zero length or create text file for update.
 * a+ : append; open or create text file for update, writing at end-of-file
 * r+b:
 * rb+: open binary file for update (reading and writing)
 * w+b:
 * wb+: truncate to zero length or create binary file for update
 * a+b:
 * ab+: append; open or create binary file for update, writing at end-of-file
 */
FILE  *fopen(char *, char *mode);

/* used to attach the already-open streams to other files */
FILE  *freopen(char *, char *, FILE *);

/* close a stream */
int    fclose(FILE *);

/* read data into an array */
size_t fread(void *, size_t, size_t, FILE *);

/* return the next character from a stream */
int    fgetc(FILE *);
int    getc(FILE *);
/* return the next character from the standard input stream */
int    getchar();

/* read a specified number of characters from a stream */
char  *fgets(char *, int, FILE *);

/* read characters from the standard input stream */
char  *gets(char *);

/* write from a specified array */
size_t fwrite(void *, size_t, size_t, FILE *);

/* write a character to a stream */
int    fputc(int, FILE *);
int    putc(int, FILE *);
/* write a character to the standard output stream */
int    putchar(int);

/* write a string to a stream */
int    fputs(char *, FILE *);

/* write a string to the standard output stream */
int    puts(char *);

/* push a character back into an input stream */
int    ungetc(int, FILE *);

/* flush a stream */
int    fflush(FILE *);

/* set the file position indicator for a stream */
int    fseek(FILE *, long, int);

/* set the file position indicator to the beginning of a file */
void   rewind(FILE *);

/* return the current value of the file position indicator for a stream */
long   ftell(FILE *);

/* store the current value of the file position indicator for a stream */
int    fgetpos(FILE *, fpos_t *);

/* set the file position indicator for a stream */
int    fsetpos(FILE *, fpos_t *);

/* generate a temporary file name */
char  *tmpnam(char *);

/* test the end-of-file indicator for a stream */
int    feof(FILE *);

/* test the error indicator for a file pointer */
int    ferror(FILE *);

/* map an error number in `errno' to an error message */
void   perror(char *);

/* clear end-of-file and error flags for a stream */
void   clearerr(FILE *);

/*
 * specify buffering for a stream
 *
 * mode
 * _IOFBF : input/output is to be fully buffered.
 * _IOLBF :input/output is to be line buffered.
 * _IONBF :input/output is to be unbuffered.
 */
int    setvbuf(FILE *, char *, int mode, size_t);
/* specify the buffering for a stream */
void   setbuf(FILE *, char *);
/* POSIX 1003 */

/* open a file specified by a file descriptor */
FILE *fdopen(int, char *);

/* return the file descriptor for a stream */
int   fileno(FILE *);

/* change the name of a file */
int   rename (char *, char *);
/* WRS stdio functions declarations */

/* read the next word (32-bit integer) from a stream */
int     getw(FILE *);

/* write a word (32-bit integer) to a stream */
int     putw(int, FILE *);

/* specify buffering for a stream */
void    setbuffer(FILE *, char *, size_t);

/* set line buffering for standard output or standard error */
int     setlinebuf(FILE *);

/* return the standard input/output/error FILE of the current task */
FILE   *stdioFp(int std);

/* display file pointer internals */
STATUS  stdioShow(FILE * fp, int level);

我是泰山 专注VX 0x10年

一起学习 共同进步