---
title: "UNIX编程(2)-UNIX标准化"
author: "brxonline"
date: "2011-06-15T11:41:40Z"
tags: ["C", "C++", "REST", "Unix", "编程"]
categories: ["操作系统"]
slug: "unix-2-unix"
draft: false
lastmod: "2011-06-15T11:41:40Z"
id: 1090222
url: "https://brxonline.iteye.com/blog/1090222"
---

1.ISO c 2.IEEE POSIX 3.Single UNIX Specification (XSI) 4.查看系统限制的函数 #include long sysconf(int name); long pathconf(const char \*pathname, int name); long fpathconf(int filedes, int name); 例：打印所有可能的sysconf和pathconf的值 \[code="c"] #include "apue.h" #include #include static void pr\_sysconf(char \*, int); static void pr\_pathconf(char \*, char \*, int); int main(int argc, char \*argv\[]) { if (argc != 2) err\_quit("usage: a.out "); #ifdef ARG\_MAX printf("ARG\_MAX defined to be %d\\n", ARG\_MAX+0); #else printf("no symbol for ARG\_MAX\\n"); #endif #ifdef \_SC\_ARG\_MAX pr\_sysconf("ARG\_MAX =", \_SC\_ARG\_MAX); #else printf("no symbol for \_SC\_ARG\_MAX\\n"); #endif /* similar processing for all the rest of the sysconf symbols... \*/ #ifdef MAX\_CANON printf("MAX\_CANON defined to be %d\\n", MAX\_CANON+0); #else printf("no symbol for MAX\_CANON\\n"); #endif #ifdef \_PC\_MAX\_CANON pr\_pathconf("MAX\_CANON =", argv\[1], \_PC\_MAX\_CANON); #else printf("no symbol for \_PC\_MAX\_CANON\\n"); #endif /* similar processing for all the rest of the pathconf symbols... \*/ exit(0); } static void pr\_sysconf(char \*mesg, int name) { long val; fputs(mesg, stdout); errno = 0; if ((val = sysconf(name)) &lt; 0) { if (errno != 0) { if (errno == EINVAL) fputs(" (not supported)\\n", stdout); else err\_sys("sysconf error"); } else { fputs(" (no limit)\\n", stdout); } } else { printf(" %ld\\n", val); } } static void pr\_pathconf(char \*mesg, char \*path, int name) { long val; fputs(mesg, stdout); errno = 0; if ((val = pathconf(path, name)) &lt; 0) { if (errno != 0) { if (errno == EINVAL) fputs(" (not supported)\\n", stdout); else err\_sys("pathconf error, path = %s", path); } else { fputs(" (no limit)\\n", stdout); } } else { printf(" %ld\\n", val); } } \[/code] 5.基本系统数据类型 caddr\_t core address clock\_t counter of clock ticks (process time) comp\_t compressed clock ticks dev\_t device numbers (major and minor) fd\_set file descriptor sets fpos\_t file position gid\_t numeric group IDs ino\_t i-node numbers mode\_t file type, file creation mode nlink\_t link counts for directory entries off\_t file sizes and offsets (signed) pid\_t process IDs and process group IDs (signed) ptrdiff\_t result of subtracting two pointers (signed) rlim\_t resource limits sig\_atomic\_t data type that can be accessed atomically sigset\_t signal set size\_t sizes of objects (such as strings) (unsigned) ssize\_t functions that return a count of bytes (signed) (read, write) time\_t counter of seconds of calendar time uid\_t numeric user IDs wchar\_t can represent all distinct character codes