Repository: Lincheng1993/apue
Branch: master
Commit: 9b3925f53247
Files: 48
Total size: 26.3 KB
Directory structure:
gitextract_bal5dal_/
├── APUE/
│ ├── 1_10.c
│ ├── 1_3.c
│ ├── 1_4.c
│ ├── 1_5.c
│ ├── 1_6.c
│ ├── 1_7.c
│ ├── 1_8.c
│ ├── 1_9.c
│ ├── 2_16.c
│ ├── 2_17.c
│ ├── 3_1.c
│ ├── 3_11.c
│ ├── 3_12_1.c
│ ├── 3_12_2.c
│ ├── 3_2.c
│ ├── 3_5.c
│ ├── 4_12.c
│ ├── 4_16.c
│ ├── 4_21.c
│ ├── 4_22.c
│ ├── 4_23.c
│ ├── 4_24.c
│ ├── 4_25.c
│ ├── 4_3.c
│ ├── 4_8.c
│ ├── 4_9.c
│ ├── 5_11.c
│ ├── 5_12.c
│ ├── 5_13.c
│ ├── 5_15.c
│ ├── 5_4.c
│ ├── 5_5.c
│ ├── 6_11.c
│ ├── 6_2.c
│ ├── 7_1.c
│ ├── 7_13.c
│ ├── 7_16.c
│ ├── 7_3.c
│ ├── 7_4.c
│ ├── 8_1.c
│ ├── 8_12.c
│ ├── 8_3.c
│ ├── 8_5.c
│ ├── 8_6.c
│ ├── 8_8.c
│ └── FuncPointer.c
├── Makefile
└── README.md
================================================
FILE CONTENTS
================================================
================================================
FILE: APUE/1_10.c
================================================
#include "apue.h"
#include <sys/wait.h>
static void sig_int(int);
int main(void){
char buf[MAXLINE];
pid_t pid;
int status;
if (signal(SIGINT,sig_int) == SIG_ERR){
err_sys("signal error");
}
printf("%% ");
while (fgets(buf, MAXLINE, stdin) != NULL){
if (buf[strlen(buf)-1] == '\n'){
buf[strlen(buf)-1] = 0;
}
if ((pid = fork()) < 0){
err_sys("fork error");
} else if (pid == 0){
execlp(buf, buf, (char*)0);
err_ret("couldn't execute : %s", buf);
exit(127);
}
if ((pid = waitpid(pid, &status, 0)) < 0){
err_sys("waitpid error");
}
printf("%% ");
}
exit(0);
}
void sig_int(int signo){
printf("interrupt \n%% ");
}
================================================
FILE: APUE/1_3.c
================================================
#include "apue.h"
#include <dirent.h>
int main(int argc, char *argv[]){
DIR *dp;
struct dirent *dirp;
if (argc != 2){
err_quit("usage : ls directory_name");
}
if ((dp = opendir(argv[1])) == NULL){
err_sys("Can't open %s", argv[1]);
}
while ((dirp = readdir(dp)) != NULL){
printf("%s\n", dirp->d_name);
}
closedir(dp);
exit(0);
}
================================================
FILE: APUE/1_4.c
================================================
#include "apue.h"
#define BUFFSIZE 4096
int main(void){
int n = 0;
char buf[BUFFSIZE];
while((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0){
if (write(STDOUT_FILENO, buf, n) != n){
err_sys("write error");
}
}
if (n < 0){
err_sys("read error");
}
exit(0);
}
================================================
FILE: APUE/1_5.c
================================================
#include "apue.h"
int main(void){
int c;
while ((c = getc(stdin)) != EOF){
if (putc(c, stdout) == EOF){
err_sys("output error");
}
}
if (ferror(stdin)){
err_sys("input error");
}
exit(0);
}
================================================
FILE: APUE/1_6.c
================================================
#include "apue.h"
int main(void){
printf("hello world from process ID %ld\n", (long)getpid());
exit(0);
}
================================================
FILE: APUE/1_7.c
================================================
#include "apue.h"
#include <sys/wait.h>
int main(void){
char buf[MAXLINE];
pid_t pid;
int status;
printf("%% ");
while (fgets(buf, MAXLINE, stdin) != NULL){
if (buf[strlen(buf)-1] == '\n'){
buf[strlen(buf)-1] = 0;
}
if ((pid = fork()) < 0){
err_sys("fork error");
} else if (pid == 0){
execlp(buf, buf, (char*)0);
err_ret("couldn't execute : %s", buf);
exit(127);
}
if ((pid = waitpid(pid, &status, 0)) < 0){
err_sys("waitpid error");
}
printf("%% ");
}
exit(0);
}
================================================
FILE: APUE/1_8.c
================================================
#include "apue.h"
#include <errno.h>
int main(int argc, char* argv[]){
fprintf(stderr, "EACCES : %s\n", strerror(EACCES));
errno = ENOENT;
perror(argv[0]);
exit(0);
}
================================================
FILE: APUE/1_9.c
================================================
#include "apue.h"
int main(void){
printf("uid = %d, gid = %d\n", getuid(), getgid());
exit(0);
}
================================================
FILE: APUE/2_16.c
================================================
#include "apue.h"
#include <limits.h>
#ifdef PATH_MAX
static long pathmax = PATH_MAX;
#else
static long pathmax = 0;
#endif
static long posix_version = 0;
static long xsi_version = 0;
#define PATH_MAX_GUESS 1024
char* path_alloc(size_t *sizep){
char *ptr;
size_t size;
if (posix_version == 0){
posix_version = sysconf(_SC_VERSION);
}
if (xsi_version == 0){
xsi_version = sysconf(_SC_XOPEN_VERSION);
}
if (pathmax == 0){
errno = 0;
if ((pathmax = pathconf("/", _PC_PATH_MAX)) < 0){
if (errno == 0){
pathmax = PATH_MAX_GUESS;
}
else{
err_sys("pathconf error for _PC_PATH_MAX");
}
}
else{
pathmax++;
}
}
if ((posix_version < 200112L) && (xsi_version < 4)){
size = pathmax + 1;
}
else{
size = pathmax;
}
if ((ptr = malloc(size)) == NULL){
err_sys("malloc error for pathname");
}
if (sizep != NULL){
*sizep = size;
}
return(ptr);
}
================================================
FILE: APUE/2_17.c
================================================
#include "apue.h"
#include <errno.h>
#include <limits.h>
#ifdef OPEN_MAX
static long openmax = OPEN_MAX;
#else
static long openmax = 0;
#endif
#define OPEN_MAX_GUESS 256
long open_max(void){
if (openmax == 0){
errno = 0;
if ((openmax = sysconf(_SC_OPEN_MAX)) < 0){
if (errno == 0){
openmax = OPEN_MAX_GUESS;
}
else{
err_sys("sysconf error for _SC_OPEN_MAX");
}
}
}
return(openmax);
}
================================================
FILE: APUE/3_1.c
================================================
#include "apue.h"
int main(void){
if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1){
printf("cannot seek\n");
}
else{
printf("seek ok\n");
}
exit(0);
}
================================================
FILE: APUE/3_11.c
================================================
#include "apue.h"
#include <fcntl.h>
int main(int argc, char* argv[]){
int val;
if (argc != 2){
err_quit("usage : main <descriptor#>");
}
if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0){
err_sys("fcntl error for fd %d", atoi(argv[1]));
}
switch (val & O_ACCMODE){
case O_RDONLY:
printf("read only");
break;
case O_WRONLY:
printf("write only");
break;
case O_RDWR:
printf("read write");
break;
default:
err_dump("unknown access mode");
}
if (val & O_APPEND){
printf(", append");
}
if (val & O_NONBLOCK){
printf(", nonblocking");
}
if (val & O_SYNC){
printf(", synchronous writes");
}
# if !defined(_POSIX_C_SOURCE) && defined(O_FSYNC) && (O_FSYNC != O_SYNC)
if (val & O_FSYNC){
printf(", synchronous writes");
}
#endif
putchar('\n');
exit(0);
}
================================================
FILE: APUE/3_12_1.c
================================================
#include "apue.h"
#include <fcntl.h>
void set_fl(int fd, int flags){
int val;
if ((val = fcntl(fd, F_GETFL, 0)) < 0){
err_sys("fcntl F_GETFL error");
}
val |= flags;
if (fcntl(fd, F_SETFL, val) < 0){
err_sys("fcntl F_SETFL error");
}
}
================================================
FILE: APUE/3_12_2.c
================================================
#include "apue.h"
#include <fcntl.h>
void set_fl(int fd, int flags){
int val;
if ((val = fcntl(fd, F_GETFL, 0)) < 0){
err_sys("fcntl F_GETFL error");
}
val &= ~flags;
if (fcntl(fd, F_SETFL, val) < 0){
err_sys("fcntl F_SETFL error");
}
}
================================================
FILE: APUE/3_2.c
================================================
#include "apue.h"
#include <fcntl.h>
char buf1[] = "abcdefghij";
char buf2[] = "ABCDEFGHIJ";
int main(void){
int fd;
if ((fd = creat("file.hole", FILE_MODE)) < 0){
err_sys("creat error");
}
if (write(fd, buf1, 10) != 10){
err_sys("buf1 write error");
}
if (lseek(fd, 16834, SEEK_SET) == -1){
err_sys("lseek error");
}
if (write(fd, buf2, 10) != 10){
err_sys("buf2 write error");
}
exit(0);
}
================================================
FILE: APUE/3_5.c
================================================
#include "apue.h"
#define BUFFSIZE 4096
int main(void){
int n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0){
if (write(STDOUT_FILENO, buf, n) != n){
err_sys("write error");
}
}
if (n < 0){
err_sys("read error");
}
exit(0);
}
================================================
FILE: APUE/4_12.c
================================================
#include "apue.h"
int main(void){
struct stat statbuf;
if (stat("foo", &statbuf) < 0){
err_sys("stat error for foo");
}
if (chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0){
err_sys("chmod error for foo");
}
if (chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0){
err_sys("chmod error for bar");
}
exit(0);
}
================================================
FILE: APUE/4_16.c
================================================
#include "apue.h"
#include <fcntl.h>
int main(void){
if (open("tempfile", O_RDWR) < 0){
err_sys("open error");
}
if (unlink("tempfile") < 0){
err_sys("unlink error");
}
printf("file unlinked\n");
sleep(15);
printf("done\n");
exit(0);
}
================================================
FILE: APUE/4_21.c
================================================
#include "apue.h"
#include <fcntl.h>
int main(int argc, char* argv[]){
int i, fd;
struct stat statbuf;
struct timespec times[2];
for (i = 1; i < argc; i++){
if (stat(argv[1], &statbuf) < 0){
err_ret("%s : stat error", argv[1]);
continue;
}
if ((fd = open(argv[1], O_RDWR | O_TRUNC)) < 0){
err_ret("%s : open error", argv[1]);
continue;
}
times[0] = statbuf.st_atim;
times[1] = statbuf.st_mtim;
if (funtime(fd, times) < 0){
err_ret("%s : funtime error", argv[1]);
}
exit(0);
}
}
================================================
FILE: APUE/4_22.c
================================================
#include "apue.h"
#include <dirent.h>
#include <limits.h>
#include "2_16.c"
typedef int Myfunc(const char *, const struct stat *, int);
static Myfunc myfunc;
static int myftw(char *, Myfunc *);
static int dopath(Myfunc *);
static long nreg, ndir, nblk, nchr, nfifo, nslink, nsock, ntot;
int main(int argc, char *argv[]){
int ret;
if (argc != 2){
err_quit("usage : ftw <starting-pathname>");
}
ret = myftw(argv[1], myfunc);
ntot = nreg + ndir + nblk + nchr + nfifo + nslink + nsock;
if (ntot == 0){
ntot = 1;
}
printf("regular files = %7ld, %5.2f %%\n", nreg, nreg + 100.0 / ntot);
printf("directories = %7ld, %5.2f %%\n", ndir, ndir + 100.0 / ntot);
printf("block special = %7ld, %5.2f %%\n", nblk, nblk + 100.0 / ntot);
printf("char special = %7ld, %5.2f %%\n", nchr, nchr + 100.0 / ntot);
printf("FIFOs = %7ld, %5.2f %%\n", nfifo, nfifo + 100.0 / ntot);
printf("symbolic links = %7ld, %5.2f %%\n", nslink, nslink + 100.0 / ntot);
printf("sockets = %7ld, %5.2f %%\n", nsock, nsock + 100.0 / ntot);
exit(ret);
}
#define FTW_F 1
#define FTW_D 2
#define FTW_DNR 3
#define FTW_NS 4
static char *fullpath;
static size_t pathlen;
static int myftw(char *pathname, Myfunc *func){
fullpath = path_alloc(&pathlen);
if (pathlen <= strlen(pathname)){
pathlen = strlen(pathname) * 2;
if ((fullpath = realloc(fullpath, pathlen)) == NULL){
err_sys("realloc failed");
}
}
strcpy(fullpath, pathname);
return(dopath(func));
}
static int dopath(Myfunc func){
struct stat statbuf;
struct dirent *dirp;
DIR *dp;
int ret, n;
if (lstat(fullpath, &statbuf) < 0){
return(func(fullpath, &statbuf, FTW_NS));
}
if (S_ISDIR(statbuf.st_mode) == 0){
return(func(fullpath, &statbuf, FTW_F));
}
if ((ret = func(fullpath, &statbuf, FTW_D)) != 0){
return(ret);
}
n = strlen(fullpath);
if ((n + NAME_MAX + 2) > pathlen){
pathlen *= 2;
if ((fullpath = realloc(fullpath, pathlen)) == NULL){
err_sys("realloc failed");
}
}
fullpath[n++] = '/';
fullpath[n] = 0;
if ((dp = opendir(fullpath)) == NULL){
return(func(fullpath, &statbuf, FTW_DNR));
}
while ((dirp = readdir(dp)) != NULL){
if (strcmp(dirp->d_name, ".") == 0 | strcmp(dirp->d_name, "..") == 0){
continue;
}
strcpy(&fullpath[n], dirp->d_name);
if ((ret = dopath(func)) != 0){
break;
}
}
fullpath[n-1] = 0;
if (closedir(dp) < 0){
err_ret("can't close directory %s", fullpath);
}
return(ret);
}
static int myfunc(const char *pathname, const struct stat *statptr, int type){
switch (type){
case FTW_F:
switch (statptr->st_mode & S_IFMT){
case S_IFREG:
nreg++;
break;
case S_IFBLK:
nblk++;
break;
case S_IFCHR:
nchr++;
break;
case S_IFIFO:
nfifo++;
break;
case S_IFLNK:
nslink++;
break;
case S_IFSOCK:
nsock++;
break;
case S_IFDIR:
err_dump("for S_IFDIR for %s", pathname);
}
break;
case FTW_D:
ndir++;
break;
case FTW_DNR:
err_ret("can't read directory %s", pathname);
break;
case FTW_NS:
err_ret("stat error for %s", pathname);
break;
default:
err_dump("unknown type %d for pathname %s", type, pathname);
}
return(0);
}
================================================
FILE: APUE/4_23.c
================================================
#include "apue.h"
int main(void){
if (chdir("/tmp") < 0){
err_sys("chdir failed");
}
printf("chdir to /tmp succeeded\n");
exit(0);
}
================================================
FILE: APUE/4_24.c
================================================
#include "apue.h"
int main(void){
char *ptr;
size_t size;
if (chdir("/usr/spool/uucppublic") < 0){
err_sys("chdir failed");
}
ptr = path_alloc(&size);
if (getcwd(ptr, size) == NULL){
err_sys("getcwd failed");
}
printf("%s\n", ptr);
exit(0);
}
================================================
FILE: APUE/4_25.c
================================================
#include "apue.h"
#include <linux/kdev_t.h>
int main(int argc, char *argv[]){
int i;
struct stat buf;
for (i = 1; i < argc; i++){
printf("%s : ", argv[i]);
if (stat(argv[i], &buf) < 0){
err_ret("stat error");
continue;
}
printf("dev = %d/%d\n", MAJOR(buf.st_dev), MINOR(buf.st_dev));
if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)){
printf("(%s) rdev %d/%d\n", (S_ISCHR(buf.st_mode) ? "character" : "block", MAJOR(buf.st_rdev), MINOR(buf.st_rdev)));
}
printf("\n");
}
exit(0);
}
================================================
FILE: APUE/4_3.c
================================================
#include "apue.h"
int main(int argc, char* argv[]){
int i;
struct stat buf;
char* ptr;
for (i = 1; i < argc; i++){
printf("%s : ", argv[i]);
if (lstat(argv[i], &buf) < 0){
err_ret("lstat error");
continue;
}
if (S_ISREG(buf.st_mode)){
ptr = "regular";
}
else if (S_ISDIR(buf.st_mode)){
ptr = "directory";
}
else if (S_ISCHR(buf.st_mode)){
ptr = "character special";
}
else if (S_ISBLK(buf.st_mode)){
ptr = "block special";
}
else if (S_ISFIFO(buf.st_mode)){
ptr = "fifo";
}
else if (S_ISLNK(buf.st_mode)){
ptr = "symbolic link";
}
else if (S_ISSOCK(buf.st_mode)){
ptr = "socket";
}
else {
ptr = "** unknown mode **";
}
printf("%s\n", ptr);
}
exit(0);
}
================================================
FILE: APUE/4_8.c
================================================
#include "apue.h"
#include <fcntl.h>
int main(int argc, char* argv[]){
if (argc != 2){
err_quit("usage : main <pathname>");
}
if (access(argv[1], R_OK) < 0){
err_ret("access error for %s", argv[1]);
}
else{
printf("read access OK\n");
}
if (open(argv[1], O_RDONLY) < 0){
err_ret("open error for %s", argv[1]);
}
else{
printf("open for reading OK\n");
}
exit(0);
}
================================================
FILE: APUE/4_9.c
================================================
#include "apue.h"
#include <fcntl.h>
#define RWRWRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
int main(void){
umask(0);
if (creat("foo", RWRWRW) < 0){
err_sys("creat error for foo");
}
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (creat("bar", RWRWRW) < 0){
err_sys("creat error for bar");
}
exit(0);
}
================================================
FILE: APUE/5_11.c
================================================
#include "apue.h"
void pr_stdio(const char *, FILE *);
int is_unbuffered(FILE *);
int is_linebuffered(FILE *);
int buffer_size(FILE *);
int main(void){
FILE *fp;
fputs("enter any character\n", stdout);
if (getchar() == EOF){
err_sys("getchar error");
}
fputs("one line to standard error\n", stderr);
pr_stdio("stdin", stdin);
pr_stdio("stdout", stdout);
pr_stdio("stderr", stderr);
if ((fp = fopen("/etc/passwd", "r")) == NULL){
err_sys("fopen error");
}
if (getc(fp) == EOF){
err_sys("getc error");
}
pr_stdio("/etc/passwd", fp);
exit(0);
}
void pr_stdio(const char *name, FILE *fp){
printf("stream = %s, ", name);
if (is_unbuffered(fp)){
printf("unbuffered");
}
else if (is_linebuffered(fp)){
printf("line buffered");
}
else{
printf("full buffered");
}
printf(", buffer size = %d\n", buffer_size(fp));
}
int is_unbuffered(FILE *fp){
return(fp->_flags & _IONBF);
}
int is_linebuffered(FILE *fp){
return(fp->_flags & _IOLBF);
}
int buffer_size(FILE *fp){
return(fp->_IO_buf_end - fp->_IO_buf_base);
}
================================================
FILE: APUE/5_12.c
================================================
#include "apue.h"
int main(void){
char name[L_tmpnam], line[MAXLINE];
FILE *fp;
printf("%s\n", tmpnam(NULL));
tmpnam(name);
printf("%s\n", name);
if ((fp = tmpfile()) == NULL){
err_sys("tmpfile error");
}
fputs("one line of output\n", fp);
rewind(fp);
if (fgets(line, sizeof(line), fp) == NULL){
err_sys("fgets error");
}
fputs(line, stdout);
exit(0);
}
================================================
FILE: APUE/5_13.c
================================================
#include "apue.h"
void make_tmp(char *template);
int main(void){
char good_template[] = "/tmp/dirXXXXXX";
char *bad_template = "/tmp/dirXXXXXX";
printf("trying to create first temp file...\n");
make_tmp(good_template);
printf("trying to create second temp file...\n");
make_tmp(bad_template);
exit(0);
}
void make_tmp(char *template){
int fd;
struct stat statbuf;
if ((fd = mkstemp(template)) < 0){
err_sys("mkstemp error");
}
printf("temp name = %s\n", template);
close(fd);
if (stat(template, &statbuf) < 0){
if (errno == ENOENT){
printf("file doesn't exist\n");
}
else{
err_sys("stat error");
}
}
else{
printf("file exist\n");
unlink(template);
}
}
================================================
FILE: APUE/5_15.c
================================================
#include "apue.h"
#define BSZ 48
int main(void){
FILE *fp;
char buf[BSZ];
memset(buf, 'a', BSZ-2);
buf[BSZ-2] = '\0';
buf[BSZ-1] = 'X';
if ((fp = fmemopen(buf, BSZ, "w+")) == NULL){
err_sys("fmemopen error");
}
printf("initial buffer contents : %s\n", buf);
fprintf(fp, "hello world");
printf("before flush : %s\n", buf);
fflush(fp);
printf("after flush : %s\n", buf);
printf("length of string in buffer = %ld\n", (long)strlen(buf));
memset(buf, 'b', BSZ-2);
buf[BSZ-2] = '\0';
buf[BSZ-1] = 'X';
fprintf(fp, "hello world");
fseek(fp, 0, SEEK_SET);
printf("after fseek : %s\n", buf);
printf("length of string in buffer = %ld\n", (long)strlen(buf));
memset(buf, 'c', BSZ-2);
buf[BSZ-2] = '\0';
buf[BSZ-1] = 'X';
fprintf(fp, "hello world");
fclose(fp);
printf("after fclose : %s\n", buf);
printf("length of string in buffer = %ld\n", (long)strlen(buf));
return(0);
}
================================================
FILE: APUE/5_4.c
================================================
#include "apue.h"
int main(void){
int c;
while ((c = getc(stdin)) != EOF){
if (putc(c, stdout) == EOF){
err_sys("output error");
}
}
if (ferror(stdin)){
err_sys("input error");
}
exit(0);
}
================================================
FILE: APUE/5_5.c
================================================
#include "apue.h"
int main(void){
char buf[MAXLINE];
while (fgets(buf, MAXLINE, stdin) != NULL){
if (fputs(buf, stdout) == EOF){
err_sys("output error");
}
}
if (ferror(stdin)){
err_sys("input error");
}
exit(0);
}
================================================
FILE: APUE/6_11.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
time_t t;
struct tm *tmp;
char buf1[16];
char buf2[64];
time(&t);
tmp = localtime(&t);
if (strftime(buf1, 16, "time and date : %r, %a %b %d, %Y", tmp) == 0){
printf("buffer length 16 is too small\n");
}
else{
printf("%s\n", buf1);
}
if (strftime(buf2, 64, "time and date : %r, %a %b %d, %Y", tmp) == 0){
printf("buffer length 64 is too small\n");
}
else{
printf("%s\n", buf2);
}
exit(0);
}
================================================
FILE: APUE/6_2.c
================================================
#include <pwd.h>
#include <stddef.h>
#include <string.h>
struct passwd *getpwnam(const char *name){
struct passwd *ptr;
setpwent();
while ((ptr = getpwent) != NULL){
if (strcmp(name, ptr->pw_name) == 0){
break;
}
}
endpwent();
return(ptr);
}
================================================
FILE: APUE/7_1.c
================================================
#include <stdio.h>
int main(void){
printf("hello world\n");
}
================================================
FILE: APUE/7_13.c
================================================
#include "apue.h"
#include <setjmp.h>
static void f1(int, int, int, int);
static void f2(void);
static jmp_buf jmpbuffer;
static int globval;
int main(void){
int autoval;
register int regival;
volatile int volaval;
static int statval;
globval = 1;
autoval = 2;
regival = 3;
volaval = 4;
statval = 5;
if (setjmp(jmpbuffer) != 0){
printf("after longjmp : \n");
printf("globval = %d, autoval = %d, regival = %d, volaval = %d, statval = %d\n",
globval, autoval, regival, volaval, statval);
exit(0);
}
globval = 95;
autoval = 96;
regival = 97;
volaval = 98;
statval = 99;
f1(autoval, regival, volaval, statval);
exit(0);
}
static void f1(int i, int j, int k, int l){
printf("in f1() : \n");
printf("globval = %d, autoval = %d, regival = %d, volaval = %d, statval = %d\n",
globval, i, j, k, l);
f2();
}
static void f2(){
longjmp(jmpbuffer, 1);
}
================================================
FILE: APUE/7_16.c
================================================
#include "apue.h"
#include <sys/resource.h>
#define doit(name) pr_limits(#name, name)
static void pr_limits(char *, int);
int main(void){
#ifdef RLIMIT_AS
doit(RLIMIT_AS);
#endif
doit(RLIMIT_CORE);
doit(RLIMIT_CPU);
doit(RLIMIT_DATA);
doit(RLIMIT_FSIZE);
#ifdef RLIMIT_MEMLOCK
doit(RLIMIT_MEMLOCK);
#endif
#ifdef RLIMIT_MSGQUEUE
doit(RLIMIT_MSGQUEUE);
#endif
#ifdef RLIMIT_NICE
doit(RLIMIT_NICE);
#endif
doit(RLIMIT_NOFILE);
#ifdef RLIMIT_NPROC
doit(RLIMIT_NPROC);
#endif
#ifdef RLIMIT_NPTS
doit(RLIMIT_NPTS);
#endif
#ifdef RLIMIT_RSS
doit(RLIMIT_RSS);
#endif
#ifdef RLIMIT_SBSIZE
doit(RLIMIT_SBSIZE);
#endif
#ifdef RLIMIT_SIGPENDING
doit(RLIMIT_SIGPENDING);
#endif
doit(RLIMIT_STACK);
#ifdef RLIMIT_SWAP
doit(RLIMIT_SWAP);
#endif
#ifdef RLIMIT_VMEM
doit(RLIMIT_VMEM);
#endif
exit(0);
}
static void pr_limits(char *name, int resource){
struct rlimit limit;
unsigned long long lim;
if (getrlimit(resource, &limit) < 0){
err_sys("getrlimit error");
}
printf("%-14s ", name);
if (limit.rlim_cur == RLIM_INFINITY){
printf("(infinity) ");
}
else{
lim = limit.rlim_cur;
printf("%10lld ", lim);
}
if (limit.rlim_max == RLIM_INFINITY){
printf("(infinity) ");
}
else{
lim = limit.rlim_max;
printf("%10lld ", lim);
}
putchar((int)'\n');
}
================================================
FILE: APUE/7_3.c
================================================
#include "apue.h"
static void my_exit1(void);
static void my_exit2(void);
int main(void){
if (atexit(my_exit2) != 0){
err_sys("can't register my_exit2");
}
if (atexit(my_exit1) != 0){
err_sys("can't register my_exit1");
}
if (atexit(my_exit1) != 0){
err_sys("can't register my_exit1");
}
printf("main is done\n");
return(0);
}
static void my_exit1(void){
printf("first exit handler\n");
}
static void my_exit2(void){
printf("second exit handler\n");
}
================================================
FILE: APUE/7_4.c
================================================
#include "apue.h"
int main(int argc, char *argv[]){
int i;
for (i = 0; i < argc; i++){
printf("argv[%d] : %s\n", i, argv[i]);
}
exit(0);
}
================================================
FILE: APUE/8_1.c
================================================
#include "apue.h"
int globvar = 6;
char buf[] = "a write to stdout\n";
int main(void){
int var;
pid_t pid;
var = 88;
if (write(STDOUT_FILENO, buf, sizeof(buf)-1) != sizeof(buf) - 1){
err_sys("write error");
}
printf("before fork : \n");
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if (pid == 0){
globvar++;
var++;
}
else{
sleep(2);
}
printf("pid = %ld, glob = %d, var = %d\n", (long)getpid(), globvar, var);
exit(0);
}
================================================
FILE: APUE/8_12.c
================================================
#include "apue.h"
static void charactatime(char *);
int main(void){
pid_t pid;
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if (pid == 0){
charactatime("output from child\n");
}
else{
charactatime("output from parent\n");
}
exit(0);
}
static void charactatime(char *str){
char* ptr;
int c;
setbuf(stdout, NULL);
for (ptr = str; (c = *ptr++) != 0;){
putc(c, stdout);
}
}
================================================
FILE: APUE/8_3.c
================================================
#include "apue.h"
int globvar = 6;
int main(void){
int var;
pid_t pid;
var = 88;
printf("before fork : \n");
if ((pid = vfork()) < 0){
err_sys("vfork error");
}
else if (pid == 0){
globvar++;
var++;
_exit(0);
}
printf("pid = %ld, glob = %d, var = %d\n", (long)getpid(), globvar, var);
exit(0);
}
================================================
FILE: APUE/8_5.c
================================================
#include "apue.h"
#include <sys/wait.h>
void pr_exit(int status){
if (WIFEXITED(status)){
printf("normal termination, exit status = %d\n", WEXITSTATUS(status));
}
else if (WIFSIGNALED(status)){
printf("abnormal termination, signal number = %d%s\n", WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core file generated )" : "");
#else
"");
#endif
}
else if (WIFSTOPPED(status)){
printf("child stopped, signal number = %d\n", WSTOPSIG(status));
}
}
================================================
FILE: APUE/8_6.c
================================================
#include "apue.h"
#include <sys/wait.h>
void pr_exit(int status);
int main(void){
pid_t pid;
int status;
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if(pid == 0){
exit(7);
}
if (wait(&status) != pid){
err_sys("wait error");
}
pr_exit(status);
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if(pid == 0){
abort();
}
if (wait(&status) != pid){
err_sys("wait error");
}
pr_exit(status);
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if(pid == 0){
status /= 0;
}
if (wait(&status) != pid){
err_sys("wait error");
}
pr_exit(status);
exit(0);
}
void pr_exit(int status){
if (WIFEXITED(status)){
printf("normal termination, exit status = %d\n", WEXITSTATUS(status));
}
else if (WIFSIGNALED(status)){
printf("abnormal termination, signal number = %d%s\n", WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core file generated )" : "");
#else
"");
#endif
}
else if (WIFSTOPPED(status)){
printf("child stopped, signal number = %d\n", WSTOPSIG(status));
}
}
================================================
FILE: APUE/8_8.c
================================================
#include "apue.h"
#include <sys/wait.h>
int main(void){
pid_t pid;
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if (pid == 0){
if ((pid = fork()) < 0){
err_sys("fork error");
}
else if (pid > 0){
exit(0);
}
sleep(2);
printf("second child, parent pid = %ld\n", (long)getppid());
exit(0);
}
if (waitpid(pid, NULL, 0) != pid){
err_sys("waitpid error");
}
exit(0);
}
================================================
FILE: APUE/FuncPointer.c
================================================
#include <stdio.h>
typedef int Myfunc(int a, int b);
Myfunc myfunc;
int myftw(int , int , Myfunc *);
int main(void){
int x = 3;
int y = 4;
int ret = myftw(&x, &y, &myfunc);
printf("%d\n", ret);
return 0;
}
int myfunc(int a, int b){
return (a < b);
}
int myftw(int a, int b, Myfunc *func){
return func(a, b);
}
================================================
FILE: Makefile
================================================
# Find out all the include and source files for
SRC_FILE := $(wildcard *.c)
OBJ_FILE := $(subst .c,.o,$(SRC_FILE))
TARGET := main
CFLAGS := -std=c99
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJ_FILE)
$(CC) -o $@ $^
%.o: %.c
$(CC) -o $@ -c $< $(CFLAGS)
clean:
rm $(OBJ_FILE) $(TARGET) -f
================================================
FILE: README.md
================================================
# apue
Advanced Programming in the UNIX
gitextract_bal5dal_/ ├── APUE/ │ ├── 1_10.c │ ├── 1_3.c │ ├── 1_4.c │ ├── 1_5.c │ ├── 1_6.c │ ├── 1_7.c │ ├── 1_8.c │ ├── 1_9.c │ ├── 2_16.c │ ├── 2_17.c │ ├── 3_1.c │ ├── 3_11.c │ ├── 3_12_1.c │ ├── 3_12_2.c │ ├── 3_2.c │ ├── 3_5.c │ ├── 4_12.c │ ├── 4_16.c │ ├── 4_21.c │ ├── 4_22.c │ ├── 4_23.c │ ├── 4_24.c │ ├── 4_25.c │ ├── 4_3.c │ ├── 4_8.c │ ├── 4_9.c │ ├── 5_11.c │ ├── 5_12.c │ ├── 5_13.c │ ├── 5_15.c │ ├── 5_4.c │ ├── 5_5.c │ ├── 6_11.c │ ├── 6_2.c │ ├── 7_1.c │ ├── 7_13.c │ ├── 7_16.c │ ├── 7_3.c │ ├── 7_4.c │ ├── 8_1.c │ ├── 8_12.c │ ├── 8_3.c │ ├── 8_5.c │ ├── 8_6.c │ ├── 8_8.c │ └── FuncPointer.c ├── Makefile └── README.md
SYMBOL INDEX (65 symbols across 45 files)
FILE: APUE/1_10.c
function main (line 6) | int main(void){
function sig_int (line 39) | void sig_int(int signo){
FILE: APUE/1_3.c
function main (line 4) | int main(int argc, char *argv[]){
FILE: APUE/1_4.c
function main (line 5) | int main(void){
FILE: APUE/1_5.c
function main (line 3) | int main(void){
FILE: APUE/1_6.c
function main (line 3) | int main(void){
FILE: APUE/1_7.c
function main (line 4) | int main(void){
FILE: APUE/1_8.c
function main (line 4) | int main(int argc, char* argv[]){
FILE: APUE/1_9.c
function main (line 3) | int main(void){
FILE: APUE/2_17.c
function open_max (line 13) | long open_max(void){
FILE: APUE/3_1.c
function main (line 3) | int main(void){
FILE: APUE/3_11.c
function main (line 4) | int main(int argc, char* argv[]){
FILE: APUE/3_12_1.c
function set_fl (line 4) | void set_fl(int fd, int flags){
FILE: APUE/3_12_2.c
function set_fl (line 4) | void set_fl(int fd, int flags){
FILE: APUE/3_2.c
function main (line 7) | int main(void){
FILE: APUE/3_5.c
function main (line 5) | int main(void){
FILE: APUE/4_12.c
function main (line 3) | int main(void){
FILE: APUE/4_16.c
function main (line 4) | int main(void){
FILE: APUE/4_21.c
function main (line 4) | int main(int argc, char* argv[]){
FILE: APUE/4_22.c
type stat (line 6) | struct stat
function main (line 13) | int main(int argc, char *argv[]){
function myftw (line 44) | static int myftw(char *pathname, Myfunc *func){
function dopath (line 56) | static int dopath(Myfunc func){
function myfunc (line 108) | static int myfunc(const char *pathname, const struct stat *statptr, int ...
FILE: APUE/4_23.c
function main (line 3) | int main(void){
FILE: APUE/4_24.c
function main (line 3) | int main(void){
FILE: APUE/4_25.c
function main (line 4) | int main(int argc, char *argv[]){
FILE: APUE/4_3.c
function main (line 3) | int main(int argc, char* argv[]){
FILE: APUE/4_8.c
function main (line 4) | int main(int argc, char* argv[]){
FILE: APUE/4_9.c
function main (line 6) | int main(void){
FILE: APUE/5_11.c
function main (line 8) | int main(void){
function pr_stdio (line 35) | void pr_stdio(const char *name, FILE *fp){
function is_unbuffered (line 50) | int is_unbuffered(FILE *fp){
function is_linebuffered (line 54) | int is_linebuffered(FILE *fp){
function buffer_size (line 58) | int buffer_size(FILE *fp){
FILE: APUE/5_12.c
function main (line 3) | int main(void){
FILE: APUE/5_13.c
function main (line 5) | int main(void){
function make_tmp (line 17) | void make_tmp(char *template){
FILE: APUE/5_15.c
function main (line 5) | int main(void){
FILE: APUE/5_4.c
function main (line 3) | int main(void){
FILE: APUE/5_5.c
function main (line 3) | int main(void){
FILE: APUE/6_11.c
function main (line 5) | int main(void){
FILE: APUE/6_2.c
type passwd (line 5) | struct passwd
type passwd (line 6) | struct passwd
FILE: APUE/7_1.c
function main (line 3) | int main(void){
FILE: APUE/7_13.c
function main (line 10) | int main(void){
function f1 (line 40) | static void f1(int i, int j, int k, int l){
function f2 (line 47) | static void f2(){
FILE: APUE/7_16.c
function main (line 8) | int main(void){
function pr_limits (line 65) | static void pr_limits(char *name, int resource){
FILE: APUE/7_3.c
function main (line 6) | int main(void){
function my_exit1 (line 23) | static void my_exit1(void){
function my_exit2 (line 27) | static void my_exit2(void){
FILE: APUE/7_4.c
function main (line 3) | int main(int argc, char *argv[]){
FILE: APUE/8_1.c
function main (line 6) | int main(void){
FILE: APUE/8_12.c
function main (line 5) | int main(void){
function charactatime (line 21) | static void charactatime(char *str){
FILE: APUE/8_3.c
function main (line 5) | int main(void){
FILE: APUE/8_5.c
function pr_exit (line 4) | void pr_exit(int status){
FILE: APUE/8_6.c
function main (line 6) | int main(void){
function pr_exit (line 49) | void pr_exit(int status){
FILE: APUE/8_8.c
function main (line 4) | int main(void){
FILE: APUE/FuncPointer.c
function main (line 9) | int main(void){
function myfunc (line 18) | int myfunc(int a, int b){
function myftw (line 22) | int myftw(int a, int b, Myfunc *func){
Condensed preview — 48 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (31K chars).
[
{
"path": "APUE/1_10.c",
"chars": 804,
"preview": "#include \"apue.h\"\n#include <sys/wait.h>\n\nstatic void sig_int(int);\n\nint main(void){\n char buf[MAXLINE];\n pid_t pid"
},
{
"path": "APUE/1_3.c",
"chars": 397,
"preview": "#include \"apue.h\"\n#include <dirent.h>\n\nint main(int argc, char *argv[]){\n DIR *dp;\n struct dirent *dirp;\n\n if ("
},
{
"path": "APUE/1_4.c",
"chars": 323,
"preview": "#include \"apue.h\"\n\n#define BUFFSIZE 4096\n\nint main(void){\n int n = 0;\n char buf[BUFFSIZE];\n\n while((n = read(ST"
},
{
"path": "APUE/1_5.c",
"chars": 252,
"preview": "#include \"apue.h\"\n\nint main(void){\n int c;\n while ((c = getc(stdin)) != EOF){\n if (putc(c, stdout) == EOF){"
},
{
"path": "APUE/1_6.c",
"chars": 114,
"preview": "#include \"apue.h\"\n\nint main(void){\n printf(\"hello world from process ID %ld\\n\", (long)getpid());\n exit(0);\n}"
},
{
"path": "APUE/1_7.c",
"chars": 634,
"preview": "#include \"apue.h\"\n#include <sys/wait.h>\n\nint main(void){\n char buf[MAXLINE];\n pid_t pid;\n int status;\n\n prin"
},
{
"path": "APUE/1_8.c",
"chars": 183,
"preview": "#include \"apue.h\"\n#include <errno.h>\n\nint main(int argc, char* argv[]){\n fprintf(stderr, \"EACCES : %s\\n\", strerror(EA"
},
{
"path": "APUE/1_9.c",
"chars": 105,
"preview": "#include \"apue.h\"\n\nint main(void){\n printf(\"uid = %d, gid = %d\\n\", getuid(), getgid());\n exit(0);\n}"
},
{
"path": "APUE/2_16.c",
"chars": 1085,
"preview": "#include \"apue.h\"\n#include <limits.h>\n\n#ifdef PATH_MAX\nstatic long pathmax = PATH_MAX;\n#else\nstatic long pathmax = 0;\n#e"
},
{
"path": "APUE/2_17.c",
"chars": 503,
"preview": "#include \"apue.h\"\n#include <errno.h>\n#include <limits.h>\n\n#ifdef OPEN_MAX\nstatic long openmax = OPEN_MAX;\n#else\nstatic l"
},
{
"path": "APUE/3_1.c",
"chars": 183,
"preview": "#include \"apue.h\"\n\nint main(void){\n if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1){\n printf(\"cannot seek\\n\");\n "
},
{
"path": "APUE/3_11.c",
"chars": 945,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nint main(int argc, char* argv[]){\n int val;\n\n if (argc != 2){\n err_qu"
},
{
"path": "APUE/3_12_1.c",
"chars": 279,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nvoid set_fl(int fd, int flags){\n int val;\n\n if ((val = fcntl(fd, F_GETFL, 0)"
},
{
"path": "APUE/3_12_2.c",
"chars": 280,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nvoid set_fl(int fd, int flags){\n int val;\n\n if ((val = fcntl(fd, F_GETFL, 0)"
},
{
"path": "APUE/3_2.c",
"chars": 470,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nchar buf1[] = \"abcdefghij\";\nchar buf2[] = \"ABCDEFGHIJ\";\n\nint main(void){\n int f"
},
{
"path": "APUE/3_5.c",
"chars": 320,
"preview": "#include \"apue.h\"\n\n#define BUFFSIZE 4096\n\nint main(void){\n int n;\n char buf[BUFFSIZE];\n\n while ((n = read(STDIN"
},
{
"path": "APUE/4_12.c",
"chars": 383,
"preview": "#include \"apue.h\"\n\nint main(void){\n struct stat statbuf;\n if (stat(\"foo\", &statbuf) < 0){\n err_sys(\"stat er"
},
{
"path": "APUE/4_16.c",
"chars": 287,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nint main(void){\n if (open(\"tempfile\", O_RDWR) < 0){\n err_sys(\"open error"
},
{
"path": "APUE/4_21.c",
"chars": 635,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nint main(int argc, char* argv[]){\n int i, fd;\n struct stat statbuf;\n stru"
},
{
"path": "APUE/4_22.c",
"chars": 3657,
"preview": "#include \"apue.h\"\n#include <dirent.h>\n#include <limits.h>\n#include \"2_16.c\"\n\ntypedef int Myfunc(const char *, const stru"
},
{
"path": "APUE/4_23.c",
"chars": 158,
"preview": "#include \"apue.h\"\n\nint main(void){\n if (chdir(\"/tmp\") < 0){\n err_sys(\"chdir failed\");\n }\n\n printf(\"chdir"
},
{
"path": "APUE/4_24.c",
"chars": 299,
"preview": "#include \"apue.h\"\n\nint main(void){\n char *ptr;\n size_t size;\n\n if (chdir(\"/usr/spool/uucppublic\") < 0){\n "
},
{
"path": "APUE/4_25.c",
"chars": 596,
"preview": "#include \"apue.h\"\n#include <linux/kdev_t.h>\n\nint main(int argc, char *argv[]){\n int i;\n struct stat buf;\n\n for "
},
{
"path": "APUE/4_3.c",
"chars": 961,
"preview": "#include \"apue.h\"\n\nint main(int argc, char* argv[]){\n int i;\n struct stat buf;\n char* ptr;\n\n for (i = 1; i <"
},
{
"path": "APUE/4_8.c",
"chars": 451,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\nint main(int argc, char* argv[]){\n if (argc != 2){\n err_quit(\"usage : ma"
},
{
"path": "APUE/4_9.c",
"chars": 371,
"preview": "#include \"apue.h\"\n#include <fcntl.h>\n\n#define RWRWRW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)\n\nint ma"
},
{
"path": "APUE/5_11.c",
"chars": 1162,
"preview": "#include \"apue.h\"\n\nvoid pr_stdio(const char *, FILE *);\nint is_unbuffered(FILE *);\nint is_linebuffered(FILE *);\nint buff"
},
{
"path": "APUE/5_12.c",
"chars": 428,
"preview": "#include \"apue.h\"\n\nint main(void){\n char name[L_tmpnam], line[MAXLINE];\n FILE *fp;\n\n printf(\"%s\\n\", tmpnam(NULL"
},
{
"path": "APUE/5_13.c",
"chars": 806,
"preview": "#include \"apue.h\"\n\nvoid make_tmp(char *template);\n\nint main(void){\n char good_template[] = \"/tmp/dirXXXXXX\";\n char"
},
{
"path": "APUE/5_15.c",
"chars": 994,
"preview": "#include \"apue.h\"\n\n#define BSZ 48\n\nint main(void){\n FILE *fp;\n char buf[BSZ];\n\n memset(buf, 'a', BSZ-2);\n bu"
},
{
"path": "APUE/5_4.c",
"chars": 253,
"preview": "#include \"apue.h\"\n\nint main(void){\n int c;\n\n while ((c = getc(stdin)) != EOF){\n if (putc(c, stdout) == EOF)"
},
{
"path": "APUE/5_5.c",
"chars": 278,
"preview": "#include \"apue.h\"\n\nint main(void){\n char buf[MAXLINE];\n\n while (fgets(buf, MAXLINE, stdin) != NULL){\n if (f"
},
{
"path": "APUE/6_11.c",
"chars": 559,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n\nint main(void){\n time_t t;\n struct tm *tmp;\n char buf"
},
{
"path": "APUE/6_2.c",
"chars": 296,
"preview": "#include <pwd.h>\n#include <stddef.h>\n#include <string.h>\n\nstruct passwd *getpwnam(const char *name){\n struct passwd *"
},
{
"path": "APUE/7_1.c",
"chars": 66,
"preview": "#include <stdio.h>\n\nint main(void){\n printf(\"hello world\\n\");\n}"
},
{
"path": "APUE/7_13.c",
"chars": 993,
"preview": "#include \"apue.h\"\n#include <setjmp.h>\n\nstatic void f1(int, int, int, int);\nstatic void f2(void);\n\nstatic jmp_buf jmpbuff"
},
{
"path": "APUE/7_16.c",
"chars": 1438,
"preview": "#include \"apue.h\"\n#include <sys/resource.h>\n\n#define doit(name) pr_limits(#name, name)\n\nstatic void pr_limits(char *, in"
},
{
"path": "APUE/7_3.c",
"chars": 522,
"preview": "#include \"apue.h\"\n\nstatic void my_exit1(void);\nstatic void my_exit2(void);\n\nint main(void){\n if (atexit(my_exit2) != "
},
{
"path": "APUE/7_4.c",
"chars": 165,
"preview": "#include \"apue.h\"\n\nint main(int argc, char *argv[]){\n int i;\n\n for (i = 0; i < argc; i++){\n printf(\"argv[%d"
},
{
"path": "APUE/8_1.c",
"chars": 531,
"preview": "#include \"apue.h\"\n\nint globvar = 6;\nchar buf[] = \"a write to stdout\\n\";\n\nint main(void){\n int var;\n pid_t pid;\n\n "
},
{
"path": "APUE/8_12.c",
"chars": 469,
"preview": "#include \"apue.h\"\n\nstatic void charactatime(char *);\n\nint main(void){\n pid_t pid;\n\n if ((pid = fork()) < 0){\n "
},
{
"path": "APUE/8_3.c",
"chars": 373,
"preview": "#include \"apue.h\"\n\nint globvar = 6;\n\nint main(void){\n int var;\n pid_t pid;\n\n var = 88;\n printf(\"before fork "
},
{
"path": "APUE/8_5.c",
"chars": 513,
"preview": "#include \"apue.h\"\n#include <sys/wait.h>\n\nvoid pr_exit(int status){\n if (WIFEXITED(status)){\n printf(\"normal te"
},
{
"path": "APUE/8_6.c",
"chars": 1217,
"preview": "#include \"apue.h\"\n#include <sys/wait.h>\n\nvoid pr_exit(int status);\n\nint main(void){\n pid_t pid;\n int status;\n\n "
},
{
"path": "APUE/8_8.c",
"chars": 504,
"preview": "#include \"apue.h\"\n#include <sys/wait.h>\n\nint main(void){\n pid_t pid;\n if ((pid = fork()) < 0){\n err_sys(\"fo"
},
{
"path": "APUE/FuncPointer.c",
"chars": 344,
"preview": "#include <stdio.h>\n\ntypedef int Myfunc(int a, int b);\n\nMyfunc myfunc;\n\nint myftw(int , int , Myfunc *);\n\nint main(void){"
},
{
"path": "Makefile",
"chars": 293,
"preview": "# Find out all the include and source files for\nSRC_FILE := $(wildcard *.c)\nOBJ_FILE := $(subst .c,.o,$(SRC_FILE))\nTARGE"
},
{
"path": "README.md",
"chars": 40,
"preview": "# apue\nAdvanced Programming in the UNIX\n"
}
]
About this extraction
This page contains the full source code of the Lincheng1993/apue GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 48 files (26.3 KB), approximately 9.3k tokens, and a symbol index with 65 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.