Apue.h#ifndef apue_sunyj#define apue_sunyjvoid err_quit (const char *fmt, ...); void Err_sys (const char *fmt, ...); #endif
Error.cpp#include <stdarg.h> #include <errno.h> #include <stdio.h> #include <string.h># Include <stdlib.h> #include <stdint.h>int64_t const MAXLINE = 4096; Max Line length/* * * Print a message and return to caller. * * Caller Specifies "Errnoflag". * */static void Err_doit (int errnoflag, int error, const char *FMT, va_list ap) {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 */}/* * * 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); Process terminate, not just like return, totally different}/* * * 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);}
Primary purpose, in centos6.3 64-bit machines, use Eclipse to learn Apue third edition, And this study does not use the book apue.h, and some libraries under the LIB, or, is the last time the study, encountered the library is directly used, this time I put forward, an adaptation, careful of a function of learning, and use g++ compiler
UNIX Environment Advanced programming Eclipse environment configuration plus error.cc