UNIX编程(2)-UNIX标准化

1.ISO c
2.IEEE POSIX
3.Single UNIX Specification (XSI)
4.查看系统限制的函数

#include <unistd.h>

long sysconf(int name);

long pathconf(const char *pathname, int name);

long fpathconf(int filedes, int name);


例:打印所有可能的sysconf和pathconf的值

#include "apue.h"
#include <errno.h>
#include <limits.h>

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 <dirname>");

#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)) < 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)) < 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);
}
}




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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值