Line 15 opens filename for reading and gets its

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: members correspond to the static variables that my read uses for buffering. code/include/csapp.h 1 2 3 4 5 6 7 8 9 10 typedef struct { int read_fd; /* caller’s descriptor to read from */ char *read_ptr; /* caller’s buffer to read into */ size_t read_maxlen; /* max bytes to read */ /* next three are used int rl_cnt; /* char *rl_bufptr; /* char rl_buf[MAXBUF];/* } Rline; internally by the function */ initialize to 0 */ initialize to rl_buf */ internal buffer */ code/include/csapp.h Figure 12.36: Rline structure used by readline r and initialized by readline rinit. The Rline structure is initialized by the readline rinit function in Figure 12.37, which saves the user arguments and initializes the internal buffering information. code/src/csapp.c 1 2 3 4 5 6 7 8 9 void readline_rinit(int fd, void *ptr, size_t maxlen, Rline *rptr) { rptr->read_fd = fd; /* save caller’s arguments */ rptr->read_ptr = ptr; rptr->read_maxlen = maxlen; rptr->rl_cnt = 0; /* and init our counter & pointer */ rptr->rl_bufptr = rp...
View Full Document

Ask a homework question - tutors are online