40 this problem is a drill to help you understand the

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: turn code is useful to applications, the wrapper passes it back to the caller, as shown in Figure A.5. 668 APPENDIX A. ERROR HANDLING code/src/csapp.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 void unix_error(char *msg) /* unix-style error */ { fprintf(stderr, "%s: %s\n", msg, strerror(errno)); exit(0); } void posix_error(int code, char *msg) /* posix-style error */ { fprintf(stderr, "%s: %s\n", msg, strerror(code)); exit(0); } void dns_error(char *msg) /* dns-style error */ { fprintf(stderr, "%s: %s\n", msg, hstrerror(h_errno)); exit(0); } void app_error(char *msg) /* application error */ { fprintf(stderr, "%s\n", msg); exit(0); } code/src/csapp.c Figure A.1: Error-reporting functions. code/src/csapp.c 1 2 3 4 5 6 7 8 pid_t Wait(int *status) { pid_t pid; if ((pid = wait(status)) < 0) unix_error("Wait error"); return pid; } code/src/csapp.c Figure A.2: Wrapper for Unix-style wait function. A.3. ERROR-HANDLING WRAPPERS 669 code/src/csapp.c 1 2 3 4 5 6 7 voi...
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