For a real server that might be expected to service

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: hould use the readline function [77] whenever you input a text line. #include "csapp.h" ssize t readline(int fd, void *buf, size t maxlen); returns: number of bytes read (0 if EOF), -1 on error The readline function has the same semantics as the fgets function in the C Standard I/O library. It reads the next text line from file fd (including the terminating newline character), copies it to memory location buf, and terminates the text line with the null character. Readline reads at most maxlen1 bytes, leaving room for the terminating zero. If the text line is longer than maxlen-1 bytes, then readline simply returns the first maxlen-1 bytes of the line. Figure 12.16 shows the code for the readline package. It is somewhat subtle and needs to be studied carefully. The my read function copies the next character in the file to location ptr. It returns ½ on error (with errno) set appropriately, 0 on EOF, and 1 otherwise. Notice that my read is a static function, and thus is not visible to applications. To improve efficiency, my read maintains a static buffer...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online