The author claims that his awk script will print out all the limits for a POSIX.1 and XSI compliant system. I am using Red Hat Enterprise Linux Server release 6.0 (Santiago). When I run his awk script it does not seem to be printing out the #ifdef portion of the C program. My thoughts are that sysconf.sym do not exist on this distribution, therefore the while loops never run. Could someone please confirm that? If this is the case what changes would I need to make to the awk script to get it to print out the #ifdef portion of the code? The awk script is:
# Run with awk -f <awk_script>
BEGIN {
printf("#include \"apue.h\"\n")
printf("#include <errno.h>\n")
printf("#include <limits.h>\n")
printf("#include <stdio.h>\n")
printf("\n")
printf("int log_to_stderr = 0;\n")
printf("static void pr_sysconf(char *, int);\n")
printf("static void pr_pathconf(char *, char *, int);\n")
printf("\n")
printf("int\n")
printf("main(int argc, char *argv[])\n")
printf("{\n")
printf(" if (argc != 2)\n")
printf(" err_quit(\"usage: a.out <dirname>\");\n\n")
FS="\t+"
while (getline <"sysconf.sym" > 0) {
printf("#ifdef %s\n", $1)
printf(" printf(\"%s defined to be %%d\\n\", %s+0);\n", $1, $1)
printf("#else\n")
printf(" printf(\"no symbol for %s\\n\");\n", $1)
printf("#endif\n")
printf("#ifdef %s\n", $2)
printf(" pr_sysconf(\"%s =\", %s);\n", $1, $2)
printf("#else\n")
printf(" printf(\"no symbol for %s\\n\");\n", $2)
printf("#endif\n")
}
close("sysconf.sym")
while (getline <"pathconf.sym" > 0) {
printf("#ifdef %s\n", $1)
printf(" printf(\"%s defined to be %%d\\n\", %s+0);\n", $1, $1)
printf("#else\n")
printf(" printf(\"no symbol for %s\\n\");\n", $1)
printf("#endif\n")
printf("#ifdef %s\n", $2)
printf(" pr_pathconf(\"%s =\", argv[1], %s);\n", $1, $2)
printf("#else\n")
printf(" printf(\"no symbol for %s\\n\");\n", $2)
printf("#endif\n")
}
close("pathconf.sym")
exit
}
END {
printf(" exit(0);\n")
printf("}\n\n")
printf("static void\n")
printf("pr_sysconf(char *mesg, int name)\n")
printf("{\n")
printf(" long val;\n\n")
printf(" fputs(mesg, stdout);\n")
printf(" errno = 0;\n")
printf(" if ((val = sysconf(name)) < 0) {\n")
printf(" if (errno != 0) {\n")
printf(" if (errno == EINVAL)\n")
printf(" fputs(\" (not supported)\\n\", stdout);\n")
printf(" else\n")
printf(" err_sys(\"sysconf error\");\n")
printf(" } else {\n")
printf(" fputs(\" (no limit)\\n\", stdout);\n")
printf(" }\n")
printf(" } else {\n")
printf(" printf(\" %%ld\\n\", val);\n")
printf(" }\n")
printf("}\n\n")
printf("static void\n")
printf("pr_pathconf(char *mesg, char *path, int name)\n")
printf("{\n")
printf(" long val;\n")
printf("\n")
printf(" fputs(mesg, stdout);\n")
printf(" errno = 0;\n")
printf(" if ((val = pathconf(path, name)) < 0) {\n")
printf(" if (errno != 0) {\n")
printf(" if (errno == EINVAL)\n")
printf(" fputs(\" (not supported)\\n\", stdout);\n")
printf(" else\n")
printf(" err_sys(\"pathconf error, path = %%s\", path);\n")
printf(" } else {\n")
printf(" fputs(\" (no limit)\\n\", stdout);\n")
printf(" }\n")
printf(" } else {\n")
printf(" printf(\" %%ld\\n\", val);\n")
printf(" }\n")
printf("}\n")
}
Update
If you would like the apue.h header so you can compile the C program that can be found at.
apue.h
I believe that sysconf.sym and pathconf.sym had to be written or were supplied on disk or something. It’s been a while since I read APUE.
Update: google turned up the following link http://www.cs.karelia.ru/~vadim/sp2009/apue.2e/std/