This article was reproduced from: http://blog.csdn.net/hadas_wang/article/details/43203795
1. Download code:http://www.apuebook.com/code3e.html
2. Install dependent libraries:sudo apt-get install Libbsd-dev
3. Go to the download directory make
4. Copying header files and dynamic link libraries
[Plain]View Plaincopy
- sudo cp./include/apue.h/usr/include/
- sudo cp./lib/libapue.a/usr/local/lib/
- sudo cp./lib/libapue.a/usr/lib/
5. Setting the error file Error.h
[CPP]View Plaincopy
- #include "apue.h"
- #include <errno.h> * for definition of errno */
- #include <stdarg.h>/* ISO C variable aruments */
- static void Err_doit (int, int, const char *, va_list);
- /*
- * Nonfatal error related to a system call.
- * Print a message and return.
- */
- void Err_ret (const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (1, errno, FMT, AP);
- Va_end (AP);
- }
- /*
- * Fatal error related to a system call.
- * Print a message and terminate.
- */
- void Err_sys (const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (1, errno, FMT, AP);
- Va_end (AP);
- Exit (1);
- }
- /*
- * Fatal error unrelated to a system call.
- * Error code passed as explict parameter.
- * Print a message and terminate.
- */
- void Err_exit (int error, const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (1, error, FMT, AP);
- Va_end (AP);
- Exit (1);
- }
- /*
- * Fatal error related to a system call.
- * Print a message, dump core, and terminate.
- */
- void Err_dump (const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (1, errno, FMT, AP);
- Va_end (AP);
- Abort (); / * Dump core and Terminate * /
- Exit (1); / * shouldn ' t get here * /
- }
- /*
- * Nonfatal error unrelated to a system call.
- * Print a message and return.
- */
- void Err_msg (const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (0, 0, FMT, AP);
- Va_end (AP);
- }
- /*
- * Fatal error unrelated to a system call.
- * Print a message and terminate.
- */
- void Err_quit (const char *fmt, ...)
- {
- va_list ap;
- Va_start (AP, FMT);
- Err_doit (0, 0, FMT, AP);
- Va_end (AP);
- Exit (1);
- }
- /*
- * Print a message and return to caller.
- * Caller Specifies "Errnoflag".
- */
- static void Err_doit (int errnoflag, int error, const char *fmt, va_list ap) /c2>
- {
- Char Buf[maxline];
- vsnprintf (buf, MAXLINE, FMT, AP);
- if (errnoflag)
- snprintf (Buf+strlen (BUF), Maxline-strlen (BUF), ":%s",
- Strerror (Error));
- strcat (buf, "\ n");
- Fflush (stdout); /* In case stdout and stderr is the same * /
- Fputs (buf, stderr);
- Fflush (NULL); / * Flushes all stdio output streams * /
- }
6. Logout, restart
7. Code files
[CPP]View Plaincopy
- #include "apue.h"
- #include "Error.h"
Linux-unix Advanced Programming (third edition) source code compilation (that is, header file apue.h How to use the problem) "Go"