作者声称他的awk脚本将打印出POSIX.1和XSI兼容系统的所有限制。我正在使用Red Hat Enterprise Linux Server 6.0版(圣地亚哥)。当我运行他的awk脚本时,似乎并没有打印出C程序的#ifdef
部分。我的想法是sysconf.sym在此发行版上不存在,因此while循环永远不会运行。有人可以确认吗?如果是这种情况,我需要对awk脚本进行哪些更改才能使其打印出代码的#ifdef
部分? awk脚本是:
# 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")
}
更新
如果您希望使用apue.h header ,则可以编译可以在以下位置找到的C程序。
apue.h
最佳答案
我相信必须写入sysconf.sym和pathconf.sym或将其提供在磁盘等上。自从我读APUE已经有一段时间了。
更新:谷歌打开了以下链接http://www.cs.karelia.ru/~vadim/sp2009/apue.2e/std/
关于c - Unix环境中的高级编程: Get Configuration Limits Figure 2.12 “Build C Program to print all supported configuration limits” ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8539510/