1 / 5

stdio

stdio. Henning Schulzrinne Columbia University. stream model. Low-level Unix (and Windows) I/O: numeric file descriptor (file handle) first for Unix, now ANSI C handles buffer allocation: read into large buffer, dump to OS in fixed units performs I/O in optimal-sized chunks

johntkelly
Download Presentation

stdio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. stdio Henning Schulzrinne Columbia University Advanced Programming Spring 2002

  2. stream model • Low-level Unix (and Windows) I/O: numeric file descriptor (file handle) • first for Unix, now ANSI C • handles • buffer allocation: read into large buffer, dump to OS in fixed units • performs I/O in optimal-sized chunks • usually, much more efficient than system calls (read, write) • fewer system calls Advanced Programming Spring 2002

  3. Streams • stdio library manipulates streams • “associate stream with file” • works for files, but also interprocess communications • fopen returns pointer to FILE object (file pointer) • file descriptor • pointer to buffer Advanced Programming Spring 2002

  4. Buffering • minimal number of read() and write() • fully buffered: I/O buffer is filled • line-buffered: newline character • unbuffered: as soon as possible void setbuf(FILE *fp, char *buf); // BUFSIZE or NULL void setvbuf(FILE *fp, char *buf, int mode, size_t size); int fflush(FILE *fp); Advanced Programming Spring 2002

  5. Positioning a stream • ftell() and fseek(): 32-bit offset long ftell(FILE *fp); int fseek(FILE *fp, long offset, int whence); // SEEK_SET, SEEK_CUR, SEEK_END void rewind(FILE *fp); • get and set (opaque position!) int fgetpos(FILE *fp, fpos_t *pos); int fsetpos(FILE *fp, const fpos_t *pos); Advanced Programming Spring 2002

More Related