"UNIX Environment Advanced Programming" development environment Configuration: Apue.h header file __ Programming

Source: Internet
Author: User

"UNIX Environment Advanced Programming" has a lot of code in the process of learning, you need to actually write these code, debugging run. The author refers to the #include "apue.h" in the dock file, which contains the common header files and some custom functions, we have to be able to complete their configuration, the test machine in this paper is ubuntu16.04.

1, first download its source code:src.3e.tar.gz in http://www.apuebook.com/

2, decompression TAR-XVF src.3e.tar.gz



3, into the apue.3e,

$ > CD apue.3e

$ > Make

4, this time may be an error, can not find-lbsd, the solution:

$>sudo Apt-get Install Libbsd-dev


5, make again, then copy include/apue.h to/usr/include/folder, Lib/libapue.a copy to/usr/local/lib/directory

sudo cp include/apue.h/usr/include/

SUDP CP Lib/libapue.a/usr/local/lib


6, use GCC to compile, take the first example in the book as an example:





7, or use another method, or copy the Apue.3e/lib/error.c file to the/usr/include/below, and then modify the Apue.h file.

Then add a line to the back (at least after max_line), #include "error.c"

* * Our own headers, to is included before all standard system headers. * * #ifndef _apue_h #define _APUE_H #define _POSIX_C_SOURCE 200809L #if defined (SOLARIS)/Solaris */#define _xopen _source #else #define _xopen_source #endif #include <sys/types.h>/* Some systems still require this * * * #i Nclude <sys/stat.h> #include <sys/termios.h>/* for winsize */#if defined (MACOS) | | !defined (Tiocgwinsz) #include <sys/ioctl.h> #endif #include <stdio.h>/* for convenience */#include &LT;STD lib.h>/* For convenience */#include <stddef.h>/* for offsetof/* #include <string.h>/* for Convenien CE/#include <unistd.h>/* for convenience */#include <signal.h>/* for Sig_err/#define Maxline 409  6/MAX line length//*** * for "UNIX Environment Advanced Programming" * * * #include "error.c"/* Default file access permissions for
 New files. * * #define FILE_MODE (S_IRUSR | S_IWUSR | S_irgrp | S_iroth) * * Default PermissiONS for new directories. * * #define DIR_MODE (File_mode | S_IXUSR | S_ixgrp |	S_ixoth) typedef void Sigfunc (int); * For signal Handlers/* #define MIN (a,b) ((a) < (b)? (a): (b) #define MAX (A,b) ((a) > (b)?
 (a): (b))/* Prototypes for our own functions.				* * Char *path_alloc (size_t *);					/* {Prog Pathalloc} */Long Open_max (void);					/* {Prog OpenMAX} */int set_cloexec (int);
/* {Prog SETFD} */void Clr_fl (int, int);					void Set_fl (int, int);						/* {Prog SETFL} */void pr_exit (int);				/* {Prog prexit} */void Pr_mask (const char *);		/* {Prog prmask} * * Sigfunc *signal_intr (int, sigfunc *);			/* {Prog signal_intr_function} */void Daemonize (const char *);			/* {Prog daemoninit} */void Sleep_us (unsigned int);		/* {Ex Sleepus} */ssize_t readn (int, void *, size_t);	/* {Prog Readn_writen} */ssize_t writen (int, const void *, size_t);					/* {Prog Readn_writen} */int fd_pipe (int *); /* {Prog sock_fdpipe} */int recv_fd (int, ssize_t (*func) (iNT, const void *, size_t));					/* {Prog recvfd_sockets} */int send_fd (int, int);			/* {Prog sendfd_sockets} */int send_err (int, int, const char *);			/* {Prog Senderr} */int serv_listen (const char *);			/* {Prog servlisten_sockets} */int serv_accept (int, uid_t *);			/* {Prog servaccept_sockets} */int cli_conn (const char *);				/* {Prog cliconn_sockets} */int Buf_args (char *, int (*func) (int, char * *));					/* {Prog Bufargs} */int tty_cbreak (int);						/* {Prog RAW} */int tty_raw (int);					/* {Prog RAW} */int tty_reset (int);					/* {Prog raw} */void Tty_atexit (void);			/* {Prog Raw} */struct Termios *tty_termios (void);			/* {Prog RAW} */int ptym_open (char *, int);					/* {Prog Ptyopen} */int ptys_open (char *); /* {Prog Ptyopen} */#ifdef TIOCGWINSZ pid_t pty_fork (int *, char *, int, const struct Termios *, const STRUC	T winsize *); /* {Prog ptyfork} */#endif int lock_reg (int, int, int, off_t, int, off_t);  /* {Prog Lockreg} */#define READ_LOCK (FD, offset, whence, len) \ Lock_reg (FD), F_setlk, F_rdlck, (offset), (whence),
(len)) #define READW_LOCK (FD, offset, whence, len) \ Lock_reg (FD), f_setlkw, F_rdlck, (offset), (whence), (len) #define Writ E_lock (fd, offset, whence, len) \ Lock_reg (FD), F_setlk, F_wrlck, (offset), (whence), (len) #define Writew_lock (FD, O Ffset, whence, len) \ Lock_reg (FD), f_setlkw, F_wrlck, (offset), (whence), (len) #define UN_LOCK (FD, offset, whence,		Len) \ Lock_reg (FD), F_setlk, F_unlck, (offset), (whence), (len) pid_t lock_test (int, int, off_t, int, off_t); /* {Prog locktest} */#define IS_READ_LOCKABLE (FD, offset, whence, Len) \ (Lock_test (FD), F_rdlck, (offset), (whence) , (len) = = 0 #define IS_WRITE_LOCKABLE (FD, offset, whence, Len) \ (Lock_test (FD), F_wrlck, (offset), (whence), (Len)			= = 0) void err_msg (const char *, ...);
/* {APP Misc_source} */void Err_dump (const char *, ...) __attribute__ ((noreturn)); void ERR_quit (const char *, ...) __attribute__ ((noreturn));
void Err_cont (int, const char *, ...);
void Err_exit (int, const char *, ...) __attribute__ ((noreturn));
void Err_ret (const char *, ...);

void Err_sys (const char *, ...) __attribute__ ((noreturn));			void log_msg (const char *, ...);
/* {APP Misc_source} */void Log_open (const char *, int, int);
void Log_quit (const char *, ...) __attribute__ ((noreturn));
void Log_ret (const char *, ...);
void Log_sys (const char *, ...) __attribute__ ((noreturn));

void Log_exit (int, const char *, ...) __attribute__ ((noreturn));		void tell_wait (void);
/* Parent/child from {Sec race_conditions} */void Tell_parent (pid_t);
void Tell_child (pid_t);
void wait_parent (void);

void Wait_child (void);
 #endif/* _apue_h * *




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.