61阅读

192.168.1.1登录页面-deallocvt 中文man页面(1)

发布时间:2018-02-07 所属栏目:192.168.1.1登录页面

一 : deallocvt 中文man页面(1)

NAME(名称)

deallocvt - 释放未使用的虚拟终端

SYNOPSIS(总览)

deallocvt [N1 N2... ]

DESCRIPTION(描述)

如果不指定参数,deallocvt程序会释放所有未使用的虚拟终端的核心内存和数据结构. 如果给定了参数Ni那么就只释放TTY /dev/ttyNi.

如果一个虚拟终端不是前台控制台,而且没有在上面打开进程执行读或写操作,又没有在该屏幕上选择文本,那么认为该终端是未使用的.

SEE ALSO(另见)

chvt(1),openvt(1).

deallocvt 中文man页面(1)_dealloc

NAME

deallocvt - deallocate unused virtual consoles

SYNOPSIS

deallocvt[N...]

DESCRIPTION

The commanddeallocvtdeallocates kernel memory and data structures for all unused virtual consoles. If one or more argumentsN... are given, only the corresponding consoles/dev/ttyNare deallocated.

A virtual console is unused if it is not the foreground console, and no process has it open for reading or writing, and no text has been selected on its screen.

SEE ALSO

chvt(1),openvt(1)

二 : arp 中文man页面(1)

NAME

arp - Linux的ARP核心模块

描述

这个核心协议模块实现RFC826中定义的 Address Resolution Protocol [译注:即TCP/IP的第三层到第一层的地址转换协议],用于在直接相连的网络中换第二层硬件地址和 Ipv4 协议地址之间的转换。用户除非想对其进行配置,否则一般不会直接操作这个模块。

实际上,它提供对核心中其它协议的服务。

用户进程可以使用packet(7) 的 sockets,收到 ARP 包(译注:一译分组)。还有一种机制是使用netlink(7) sockets,在用户空间管理 ARP 缓存的机制。我们也可以通过ioctl (2)控制任意PF_INETsocket上的 ARP 表

ARP 模块维护一个硬件地址到协议地址映射的缓存。这个缓存有大小限制,所以不常用的和旧的记录(Entry)将被垃圾收集器清除(garbage-collected),垃圾收集器永远不能删除标为永久的记录。我们可以使用ioctls直接操纵缓冲,并且其性状可以用下面定义的 sysctl 调节。

如果在限定的时间(见下面的sysctl)内,一条现存映射没有肯定反馈时,则认为相邻层的缓存记录失效。为了再次向目标发送数据,ARP将首先试着询问本地arp进程app_solicit次,获取更新了的 MAC(介质访问控制)地址。如果失败,并且旧的MAC地址是已知的,则发送ucast_solicit次的 unicast probe。如果仍然失败,则将向网络广播一个新的ARP请求,此时要有待发送数据的队列

如果 Linux 接到一个地址请求,而且该地址指向 Linux 转发的地址,并且接收接口打开了代理 arp 时,Linux 将自动添加一条非永久的代理 arp 记录;如果存在拒绝到目标的路由,则不添加代理 arp 记录。

IOCTLS

有三个 ioctl 可以用于所有PF_INET的 sockets 中。它们以一个指向struct arpreq的指针作为它们的参数。

struct arpreq{struct sockaddr arp_pa; /* 协议地址(protocol address)*/struct sockaddr arp_ha; /* 硬件地址(hardware address) */int arp_flags; /* 标志(flags) */struct sockaddr arp_netmask; /* 协议地址的网络掩码(netmask of protocol address)*/char arp_dev[16];};

SIOCSARP,SIOCDARPSIOCGARP可分贝设置、删除和获取 ARP 映射。设置和删除 ARP 映射是特许操作,只有拥有CAP_NET_ADMIN权限的进程或有效UID为0的进程可以执行。

arp_pa必须是AF_INETsocket,并且arp_ha必须有和arp_dev. 指定的设备相同的类型。arp_dev是个以null结束的设备名字符串。

arp_flags
标志(flag)含义(meaning)
ATF_COM查找完成(Lookup complete)
ATF_PERM永久记录(Permanent entry)
ATF_PUBL张贴记录(Publish entry)
ATF_USETRAILERS要求使用后缀(Trailers requested)
ATF_NETMASK使用网络掩码(Use a netmask)
ATF_DONTPUB不回复(Don't answer)

如果设置了ATF_NETMASK标志,那么arp_netmask必须有效。 Linux 2.2 不支持代理网络 ARP 记录,因此,要设成0xffffffff或者0,以删除现存代理arp记录。这里不使用现存代理arp记录。ATF_USETRAILERS已经过时了,不应该继续使用。

SYSCTLS

ARP 支持一个 sysctl 接口,可以用以配置全局参数或逐个网络接口地进行配制。该 sysctl 可以通过/proc/sys/net/ipv4/neigh/*/*文件或者使用sysctl(2) 接口来访问。系统中每个接口都在 /proc/sys/net/ipv4/neigh/. 中有自己的目录。`default'目录中的设置用于所有新建的设备。 sysctl 相关的时间是以秒为单位,除非特别声明过.

anycast_delay
对 IPv6 相邻请求信息的回复的最大延迟时间;目前还不支持 anycast。缺省值为1秒。
app_solicit
这是在使用多路广播探测(multicast probe)前,经过网络连接送到用户间隙ARP端口监控程序的探测(probe)最大数目(见mcast_solicit)。缺省值为0。
base_reachable_time
一旦发现相邻记录,至少在一段介于base_reachable_time/2和3*base_reachable_time/2 之间的随机时间内,该记录是有效的。如果收到上层协议的肯定反馈,那么记录的有效期将延长。缺省值是30秒。
delay_first_probe_time
发现某个相邻层记录无效(stale)后,发出第一个探测要等待的时间。 缺省值是5秒。
gc_interval
收集相邻层记录的无用记录的垃圾收集程序的运行周期,缺省为30秒。
gc_stale_time
决定检查一次相邻层记录的有效性的周期。当相邻层记录失效时,将在给它发送数据前,再解析一次。缺省值是60秒。
gc_thresh1
存在于ARP高速缓存中的最少层数,如果少于这个数,垃圾收集器将不会运行。缺省值是128。
gc_thresh2
保存在 ARP 高速缓存中的最多的记录软限制。垃圾收集器在开始收集前,允许记录数超过这个数字 5 秒。缺省值是 512。
gc_thresh3
保存在 ARP 高速缓存中的最多记录的硬限制,一旦高速缓存中的数目高于此,垃圾收集器将马上运行。缺省值是1024。
locktime
ARP 记录保存在高速缓存内的最短时间(jiffy数),以防止存在多个可能的映射(potential mapping)时, ARP 高速缓存系统的颠簸 (经常是由于网络的错误配置而引起)。缺省值是 1 秒。
mcast_solicit
在把记录标记为不可抵达的之前,用多路广播/广播(multicast/broadcast)方式解析地址的最大次数。缺省值是3。
proxy_delay
当接收到有一个请求已知的代理 ARP 地址的 ARP 请求时,在回应前可以延迟的 jiffy(时间单位,见BUG)数目。这样,以防止网络风暴。缺省值是0.8秒。
proxy_qlen
能放入代理 ARP 地址队列(proxy-ARP addresses)的数据包最大数目。缺省值是64。
retrans_time
重发一个请求前的等待 jiffy(时间单位,见BUG)的数目。缺省值是1秒。
ucast_solicit
询问ARP端口监控程序前,试图发送单探测(unicast probe)的次数。 (见app_solicit). 缺省值是3秒。
unres_qlen
每个没有被其它网络层解析的地址,在队列中可存放包的最大数目。缺省值是3.

BUGS

时钟设置的时间单位 jiffy,跟硬件体系有关。在 Alpha 上,一个 jiffy 是 1/1024 秒,而在其它机器上,是 1/100 秒。

目前还没有办法从用户空间发送肯定反馈。这意味着在用户空间实现的面向连接的协议(connection oriented protocols)将产生大量的 ARP 通讯。因为ndisc将重新探测MAC地址。内核 NFS 的实现也存在同样的问题。

这个手册页主要讲 IPv4 规范并且共享 IPv4 和 IPv6 的功能.

版本

Linux 2.0中的struct arpreq,添加了arp_dev,同时 ioctl 数目也改变了。在 Linux 2.2 中将不再支持旧的ioctl。

在 Linux 2.2 中,取消了对网络代理 arp 记录(网络掩码不是0xffffffff)的支持。这个功能被内核设置的一个自动代理 arp 取代,这个自动代理 arp 用于所有位于其它接上的可到达的主机(如果该接口的转发和代理 arp 打开了)。

另见

ip(7)

arp 中文man页面(1)_arp

NAME

arp - Linux ARP kernel module.

DESCRIPTION

This kernel protocol module implements the Address Resolution Protocol defined in RFC 826. It is used to convert between Layer2 hardware addresses and IPv4 protocol addresses on directly connected networks. The user normally doesn't interact directly with this module except to configure it; instead it provides a service for other protocols in the kernel.

A user process can receive ARP packets by usingpacket(7) sockets. There is also a mechanism for managing the ARP cache in user-space by usingnetlink(7) sockets. The ARP table can also be controlled viaioctl (2)on anyPF_INETsocket.

The ARP module maintains a cache of mappings between hardware addresses and protocol addresses. The cache has a limited size so old and less frequently used entries are garbage-collected. Entries which are marked as permanent are never deleted by the garbage-collector. The cache can be directly manipulated by the use of ioctls and its behaviour can be tuned by the sysctls defined below.

When there is no positive feedback for an existing mapping after some time (see the sysctls below) a neighbour cache entry is considered stale. Positive feedback can be gotten from a higher layer; for example from a successful TCP ACK. Other protocols can signal forward progress using theMSG_CONFIRMflag tosendmsg(2). When there is no forward progress ARP tries to reprobe. It first tries to ask a local arp daemonapp_solicittimes for an updated MAC address. If that fails and an old MAC address is known an unicast probe is senducast_solicittimes. If that fails too it will broadcast a new ARP request to the network. Requests are only send when there is data queued for sending.

Linux will automatically add a non-permanent proxy arp entry when it receives a request for an address it forwards to and proxy arp is enabled on the receiving interface. When there is a reject route for the target no proxy arp entry is added.

IOCTLS

Three ioctls are available on allPF_INETsockets. They take a pointer to astruct arpreqas their parameter.

struct arpreq{ struct sockaddr arp_pa; /* protocol address */ struct sockaddr arp_ha; /* hardware address */ int arp_flags; /* flags */ struct sockaddr arp_netmask; /* netmask of protocol address */ char arp_dev[16];};

SIOCSARP,SIOCDARPandSIOCGARPrespectively set, delete and get an ARP mapping. Setting & deleting ARP maps are privileged operations and may only be performed by a process with theCAP_NET_ADMINcapability or an effective UID of 0.

arp_pamust be anAF_INETsocket andarp_hamust have the same type as the device which is specified inarp_dev.arp_devis a zero-terminated string which names a device.

arp_flags
flagmeaning
ATF_COMLookup complete
ATF_PERMPermanent entry
ATF_PUBLPublish entry
ATF_USETRAILERSTrailers requested
ATF_NETMASKUse a netmask
ATF_DONTPUBDon't answer

If theATF_NETMASKflag is set, thenarp_netmaskshould be valid. Linux 2.2 does not support proxy network ARP entries, so this should be set to 0xffffffff, or 0 to remove an existing proxy arp entry.ATF_USETRAILERSis obsolete and should not be used.

SYSCTLS

ARP supports a sysctl interface to configure parameters on a global or per-interface basis. The sysctls can be accessed by reading or writing the/proc/sys/net/ipv4/neigh/*/*files or with thesysctl(2) interface. Each interface in the system has its own directory in /proc/sys/net/ipv4/neigh/. The setting in the `default' directory is used for all newly created devices. Unless otherwise specified time related sysctls are specified in seconds.

anycast_delay
The maximum number of jiffies to delay before replying to a IPv6 neighbour solicitation message. Anycast support is not yet implemented. Defaults to 1 second.
app_solicit
The maximum number of probes to send to the user space ARP daemon via netlink before dropping back to multicast probes (seemcast_solicit). Defaults to 0.
base_reachable_time
Once a neighbour has been found, the entry is considered to be valid for at least a random value betweenbase_reachable_time/2 and 3*base_reachable_time/2. An entry's validity will be extended if it receives positive feedback from higher level protocols. Defaults to 30 seconds.
delay_first_probe_time
Delay before first probe after it has been decided that a neighbour is stale. Defaults to 5 seconds.
gc_interval
How frequently the garbage collector for neighbour entries should attempt to run. Defaults to 30 seconds.
gc_stale_time
Determines how often to check for stale neighbour entries. When a neighbour entry is considered stale it is resolved again before sending data to it. Defaults to 60 seconds.
gc_thresh1
The minimum number of entries to keep in the ARP cache. The garbage collector will not run if there are fewer than this number of entries in the cache. Defaults to 128.
gc_thresh2
The soft maximum number of entries to keep in the ARP cache. The garbage collector will allow the number of entries to exceed this for 5 seconds before collection will be performed. Defaults to 512.
gc_thresh3
The hard maximum number of entries to keep in the ARP cache. The garbage collector will always run if there are more than this number of entries in the cache. Defaults to 1024.
locktime
The minimum number of jiffies to keep an ARP entry in the cache. This prevents ARP cache thrashing if there is more than one potential mapping (generally due to network misconfiguration). Defaults to 1 second.
mcast_solicit
The maximum number of attempts to resolve an address by multicast/broadcast before marking the entry as unreachable. Defaults to 3.
proxy_delay
When an ARP request for a known proxy-ARP address is received, delay up toproxy_delayjiffies before replying. This is used to prevent network flooding in some cases. Defaults to 0.8 seconds.
proxy_qlen
The maximum number of packets which may be queued to proxy-ARP addresses. Defaults to 64.
retrans_time
The number of jiffies to delay before retransmitting a request. Defaults to 1 second.
ucast_solicit
The maximum number of attempts to send unicast probes before asking the ARP daemon (seeapp_solicit). Defaults to 3.
unres_qlen
The maximum number of packets which may be queued for each unresolved address by other network layers. Defaults to 3.

BUGS

Some timer settings are specified in jiffies, which is architecture related. On the Alpha a jiffy is 1/1024 of a second, on most other architectures it is 1/100s.

There is no way to signal positive feedback from user space. This means connection oriented protocols implemented in user space will generate excessive ARP traffic, because ndisc will regularly reprobe the MAC address. The same problem applies for some kernel protocols (e.g. NFS over UDP).

This man page mashes IPv4 specific and shared between IPv4 and IPv6 functionality together.

VERSIONS

Thestruct arpreqchanged in Linux 2.0 to include thearp_devmember and the ioctl numbers changed at the same time. Support for the old ioctls was dropped in Linux 2.2.

Support for proxy arp entries for networks (netmask not equal 0xffffffff) was dropped in Linux 2.2. It is replaced by automatic proxy arp setup by the kernel for all reachable hosts on other interfaces (when forwarding and proxy arp is enabled for the interface).

The neigh/* sysctls did not exist before Linux 2.2.

SEE ALSO

ip(7)

三 : sprintf 中文man页面(1)

NAME

printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换

总览 (SYNOPSIS)

#include <stdio.h>

int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_tsize, const char *format, ...);

#include <stdarg.h>

int vprintf(const char *format, va_listap);
int vfprintf(FILE *stream, const char *format, va_listap);
int vsprintf(char *str, const char *format, va_listap);
int vsnprintf(char *str, size_tsize, const char *format, va_listap);

描述 (DESCRIPTION)

printf系列 函数 根据 下述的format参数 生成 输出内容.printfvprintf函数 把 输出内容 写到stdout, 即 标准输出流;fprintfvfprintf函数 把 输出内容 写到 给定的stream流;sprintf,snprintf,vsprintfvsnprintf函数 把 输出内容 存放到 字符串str中.

这些 函数 由 格式字符串format参数 控制 输出内容, 它 指出 怎么样 把 后面的 参数 (或 通过stdarg(3) 的 变长参数机制 访问的 参数) 转换成 输出内容.

这些 函数 返回 打印的 字符 数量 (不包括 字符串 结尾用的 `\0').snprintfvsnprintf的 输出 不会 超过size字节 (包括了 结尾的 `\0'), 如果 因为 这个 限制 导致 输出内容 被截断, 则 函数 返回 -1.

格式字符串 (format 参数) 由 零到多个 指令 组成: 普通字符 (除%外), 它们 被 原封不动的 送到 输出流; 以及 格式转换说明 (conversion specification), 每个 格式转换说明 都会 从后面 提取 零到多个 参数. 格式转换说明 由%字符 引导开始. 参数 必须 正确的 对应到 格式转换符 (conversion specifier) 上. 下述 字符 按顺序 列在%后面:

*
零个 或 多个 下列 标志:
#
指出 数值 应该 转换成 "其他形式". 对于c,d,i,n,p,s, 和u格式转换, 这个选项 没有 影响. 对于o格式转换, 数值的 精度 被提高, 使 输出字符串的 第一个 字符 为零 (除非 打印 一个零值 时, 明确 定义 精度 为零). 对于xX格式转换, 非零数值 前面 会添加 `0x' 字符串 (或X格式转换 的 `0X' 字符串). 对于e,E,f,g, 和G格式转换, 其结果 始终 含有一个 十进制小数点, 即使 后面 没有 数字 (一般说来, 只有当 格式转换 后, 小数点 后面 有数字时 才显示 小数点). 对于gG格式转换, 将不删去 结果末尾的 零, 其他情况下 这些 零 应该 删掉.
0
指出 用零 填充 结果. 所有的 格式转换, 除了n, 转换结果 的 左边 用零 填充, 而不是 空格. 如果 数值转换 时 给定了 精度, (d,i,o,u,i,x, 和X), 则 忽略0标志.
-
(负位宽标志) 指出 转换结果 必须 在 位边界 上 向左边 对齐. 除了n格式转换, 转换结果 的 右边 用空格 填充, 而不是 在左边 填充 空格或零. 如果 同时 给出了-0 ,-覆盖0 .
' '
(空格) 指出 在 通过 有符号数(signed) 格式转换 (d,e,E,f,g,G, 或i) 产生的 正数 前面 留一个 空格.
+
指出 有符号数 格式转换 产生的 结果 前面 始终 有一个 正负符号. 如果 同时 给出了+和 空格, 则+覆盖 空格.
'
指出 在 数字 参数 中, 如果 locale 给出 相关信息, 输出结果 将被 分组. 注意, 许多 版本 的gcc不能 理解 这个选项, 因而会 产生 一个警告.
*
一个 可选的 十进制数, 指出 最小的 位宽. 如果 格式转换后 产生的 字符数少于 位宽, 则 左边 用 空格 填充 (或者 填充 右边, 如果 给出了 向左对齐标志), 直到 填满 指定的 位宽.
*
一个 可选的 精度, 格式是 一个 句号(`.') 后面 跟着 一个 可选的 数字. 如果 没有 给出 这个 数字, 则 精度 取为 零. 这样就 指定了d,i,o,u,x, 和X格式转换 显示的 最小位数,e,E, 和f格式转换 小数点 后面 显示的 位数,gG格式转换 显示的 最大有效位数(significant digits), 或s格式转换 打印 某个 字符串的 最多 字符数目.
*
可选的 字符h, 指出 后面的d,i,o,u,x, 或X格式转换 对应为short intunsigned short int的 参数, 或者是 后面的n格式转换 对应为 指向short int参数 的 指针.
*
可选的 字符l(ell) 指出 后面的d,i,o,u,x, 或X格式转换 应用到 指向long intunsigned long int参数 的 指针, 或者 后面的n格式转换 对应为 指向long int参数 的 指针. Linux 提供 和 ANSI 不兼容 的 双l标志, 作为qL的 同义词. 因此ll可以 结合 浮点格式转换 使用. 但是 强烈 反对 这个 用法.
*
字符L指出 后面的e,E,f,g, 或G格式转换 对应long double参数, 或者 让 后面的d,i,o,u,x, 或X格式转换 对应long long参数. 注意long long没有在ANSI C中 声明, 因此 不能够 移植到 所有的 体系平台 上.
*
可选的 字符q等于L. 参考 STANDARDS 和 BUGS 节 关于ll,L, 和q的 叙述.
*
字符Z指出 后面的 整数 (d,i,o,u,x, 或X) 格式转换 对应size_t参数.
*
指出 采用 格式转换类型 的 字符.

可以 用 星号 `*' 代替 数字 指定 域宽 或 精度, 也可以 两者 同时 指定. 这种情况下 要求 用一个int参数 指出 域宽 或 精度. 负域宽 被认为是 正域宽 跟在 向左对齐标志 后面; 负精度 被认为是 精度 丢失.

格式转换符(specifier) 及其 含义 如下:

diouxX
int形 (或 合适的 变量) 参数 转换输出为 有符号十进制数 (di), 无符号八进制数 (o), 无符号十进制数 (u), 或者 无符号十六进制数 (xX).x格式转换 用 小写字母abcdef ;X格式转换 用 大写字母ABCDEF .精度值 (如果给出) 指出 必须显示的 最少 数字; 如果 转换结果 少于 这个 要求, 则用 零 填补 转换结果 的 左边.
eE
double参数 舍入后 转换为 [-]d.ddde\*(Pmdd 的 格式, 这个格式 的 小数点 前面 有 一位 数字, 后面 表示 精度; 如果没有 指出 精度, 则意味着 精度是 6; 如果 精度 是 0, 则不显示 小数点.E格式转换 使用 字母E(而不是e) 要求 引入 指数. 指数 至少 包含 两个 数字; 如果 值 是 零, 则 指数 是 00.
f
double参数 舍入后 转换为 [-]ddd.ddd 的 十进制 表达式, 这个格式 小数点 后面 的 数字 表示 精度. 如果 没有 指出 精度, 则意味着 精度是 6; 如果 显式 给出 精度 是 0, 则不显示 小数点. 如果 显示了 小数点, 则 小数点 前面 至少有 一位 数字.
g
double参数 以fe(或者G格式转换的E标志) 的 形式 转换. 其精度 指出 有符号数字 的 数目. 如果 没有 指出精度, 则默认为 6; 如果 精度 是 零, 则按 1 处理. 如果 格式转换后 其 指数 小于 -4 或者 大于等于 其精度, 则 使用e形式. 转换结果 消除了 分数部分 末尾的 零; 小数点 前面 至少有 一位 十进制数字.
c
int参数 转换为unsigned char, 然后 输出 对应的 字符.
s
认为 ``char *'' 参数 是 指向 字符形数组 的 指针 (指向 字符串). Printf 输出 数组内的 字符, 直到 遇上 (但不包括) 结束字符NUL ;如果 给出了 精度值, printf 不会 输出 多于 这个值 的 字符, 也不需要 提供NUL结束符; 如果 没有 给出 精度值, 或 精度值 大于 数组长度, 则 数组内一定要 包括 一个NUL字符.
p
将以 十六进制数 打印 ``void *'' 指针参数 (就象是%#x%#lx).
n
将 目前 已经 输出的 字符数目 存储在 ``int *'' (或变量) 指针参数 指向的 地址. 不转换 任何参数.
%
输出 一个 '%'. 不转换 任何参数. 完整的 写法 是 `%%'.

不指定 域宽 或 偏小的 域宽 不会 导致 内容 被截断; 如果 转换结果 的 长度超过 其域宽, 则 域宽 会 扩大到 容下 完整的 结果.

示例 (EXAMPLES)


以 `Sunday, July 3, 10:02' 格式 显示 日期, 其中weekdaymonth是 字符串指针:

#include <stdio.h>fprintf(stdout, "%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min);

显示 五位 十进制数:

#include <math.h>#include <stdio.h>fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));

分配 128 个 字节 的 字符串 空间 保存 打印 结果:

#include <stdio.h>#include <stdlib.h>#include <stdarg.h>char *newfmt(const char *fmt, ...){ char *p; va_list ap; if ((p = malloc(128)) == NULL) return (NULL); va_start(ap, fmt); (void) vsnprintf(p, 128, fmt, ap); va_end(ap); return (p);}

另见 (SEE ALSO)

printf(1),scanf(3)

sprintf 中文man页面(1)_sprintf

NAME

printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - formatted output conversion

SYNOPSIS

#include <stdio.h>

int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_tsize, const char *format, ...);

#include <stdarg.h>

int vprintf(const char *format, va_listap);
int vfprintf(FILE *stream, const char *format, va_listap);
int vsprintf(char *str, const char *format, va_listap);
int vsnprintf(char *str, size_tsize, const char *format, va_listap);

DESCRIPTION

The functions in theprintffamily produce output according to aformatas described below. The functionsprintfandvprintfwrite output tostdout, the standard output stream;fprintfandvfprintfwrite output to the given outputstream;sprintf,snprintf,vsprintfandvsnprintfwrite to the character stringstr.

The functionsvprintf,vfprintf,vsprintf,vsnprintfare equivalent to the functionsprintf,fprintf,sprintf,snprintf, respectively, except that they are called with a va_list instead of a variable number of arguments. These functions do not call theva_endmacro. Consequently, the value ofapis undefined after the call. The application should callva_end(ap)itself afterwards.

These eight functions write the output under the control of aformatstring that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities ofstdarg(3)) are converted for output.

Return value

Upon successful return, these functions return the number of characters printed (not including the trailing '\0' used to end output to strings). The functionssnprintfandvsnprintfdo not write more thansizebytes (including the trailing '\0'). If the output was truncated due to this limit then the return value is the number of characters (not including the trailing '\0') which would have been written to the final string if enough space had been available. Thus, a return value ofsizeor more means that the output was truncated. (See also below under NOTES.) If an output error is encountered, a negative value is returned.

Format of the format string

The format string is a character string, beginning and ending in its initial shift state, if any. The format string is composed of zero or more directives: ordinary characters (not%), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the character%, and ends with aconversion specifier. In between there may be (in this order) zero or moreflags, an optional minimumfield width, an optionalprecisionand an optionallength modifier.

The arguments must correspond properly (after type promotion) with the conversion specifier. By default, the arguments are used in the order given, where each `*' and each conversion specifier asks for the next argument (and it is an error if insufficiently many arguments are given). One can also specify explicitly which argument is taken, at each place where an argument is required, by writing `%m$' instead of `%' and `*m$' instead of `*', where the decimal integer m denotes the position in the argument list of the desired argument, indexed starting from 1. Thus,

printf("%*d", width, num);

and

printf("%2$*1$d", width, num);

are equivalent. The second style allows repeated references to the same argument. The C99 standard does not include the style using `$', which comes from the Single Unix Specification. If the style using `$' is used, it must be used throughout for all conversions taking an argument and all width and precision arguments, but it may be mixed with `%%' formats which do not consume an argument. There may be no gaps in the numbers of arguments specified using `$'; for example, if arguments 1 and 3 are specified, argument 2 must also be specified somewhere in the format string.

For some numeric conversions a radix character (`decimal point') or thousands' grouping character is used. The actual character used depends on the LC_NUMERIC part of the locale. The POSIX locale uses `.' as radix character, and does not have a grouping character. Thus,

printf("%'.2f", 1234567.89);

results in `1234567.89' in the POSIX locale, in `1234567,89' in the nl_NL locale, and in `1.234.567,89' in the da_DK locale.

The flag characters

The character % is followed by zero or more of the following flags:

#
The value should be converted to an ``alternate form''. Foroconversions, the first character of the output string is made zero (by prefixing a 0 if it was not zero already). ForxandXconversions, a non-zero result has the string `0x' (or `0X' forXconversions) prepended to it. Fora,A,e,E,f,F,g, andGconversions, the result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). ForgandGconversions, trailing zeros are not removed from the result as they would otherwise be. For other conversions, the result is undefined.
0
The value should be zero padded. Ford,i,o,u,x,X,a,A,e,E,f,F,g, andGconversions, the converted value is padded on the left with zeros rather than blanks. If the0and-flags both appear, the0flag is ignored. If a precision is given with a numeric conversion (d,i,o,u,x, andX), the0flag is ignored. For other conversions, the behavior is undefined.
-
The converted value is to be left adjusted on the field boundary. (The default is right justification.) Except fornconversions, the converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A-overrides a0if both are given.
' '
(a space) A blank should be left before a positive number (or empty string) produced by a signed conversion.
+
A sign (+ or -) always be placed before a number produced by a signed conversion. By default a sign is used only for negative numbers. A+overrides a space if both are used.

The five flag characters above are defined in the C standard. The SUSv2 specifies one further flag character.

'
For decimal conversion (i,d,u,f,F,g,G) the output is to be grouped with thousands' grouping characters if the locale information indicates any. Note that many versions ofgcccannot parse this option and will issue a warning. SUSv2 does not include %'F.

glibc 2.2 adds one further flag character.

I
For decimal integer conversion (i,d,u) the output uses the locale's alternative output digits, if any. For example, since glibc 2.2.3 this will give Arabic-Indic digits in the Persian (`fa_IR') locale.

The field width

An optional decimal digit string (with nonzero first digit) specifying a minimum field width. If the converted value has fewer characters than the field width, it will be padded with spaces on the left (or right, if the left-adjustment flag has been given). Instead of a decimal digit string one may write `*' or `*m$' (for some decimal integer m) to specify that the field width is given in the next argument, or in the m-th argument, respectively, which must be of typeint. A negative field width is taken as a `-' flag followed by a positive field width. In no case does a non-existent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result.

The precision

An optional precision, in the form of a period (`.') followed by an optional decimal digit string. Instead of a decimal digit string one may write `*' or `*m$' (for some decimal integer m) to specify that the precision is given in the next argument, or in the m-th argument, respectively, which must be of typeint. If the precision is given as just `.', or the precision is negative, the precision is taken to be zero. This gives the minimum number of digits to appear ford,i,o,u,x, andXconversions, the number of digits to appear after the radix character fora,A,e,E,f, andFconversions, the maximum number of significant digits forgandGconversions, or the maximum number of characters to be printed from a string forsandSconversions.

The length modifier

Here, `integer conversion' stands ford,i,o,u,x, orXconversion.

hh
A following integer conversion corresponds to asigned charorunsigned charargument, or a followingnconversion corresponds to a pointer to asigned charargument.
h
A following integer conversion corresponds to ashort intorunsigned short intargument, or a followingnconversion corresponds to a pointer to ashort intargument.
l
(ell) A following integer conversion corresponds to along intorunsigned long intargument, or a followingnconversion corresponds to a pointer to along intargument, or a followingcconversion corresponds to awint_targument, or a followingsconversion corresponds to a pointer towchar_targument.
ll
(ell-ell). A following integer conversion corresponds to along long intorunsigned long long intargument, or a followingnconversion corresponds to a pointer to along long intargument.
L
A followinga,A,e,E,f,F,g, orGconversion corresponds to along doubleargument. (C99 allows %LF, but SUSv2 does not.)
q
(`quad'. BSD 4.4 and Linux libc5 only. Don't use.) This is a synonym forll.
j
A following integer conversion corresponds to anintmax_toruintmax_targument.
z
A following integer conversion corresponds to asize_torssize_targument. (Linux libc5 hasZwith this meaning. Don't use it.)
t
A following integer conversion corresponds to aptrdiff_targument.

The SUSv2 only knows about the length modifiersh(inhd,hi,ho,hx,hX,hn) andl(inld,li,lo,lx,lX,ln,lc,ls) andL(inLe,LE,Lf,Lg,LG).

The conversion specifier

A character that specifies the type of conversion to be applied. The conversion specifiers and their meanings are:

d,i
Theintargument is converted to signed decimal notation. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros. The default precision is 1. When 0 is printed with an explicit precision 0, the output is empty.
o,u,x,X
Theunsigned intargument is converted to unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal (xandX) notation. The lettersabcdefare used forxconversions; the lettersABCDEFare used forXconversions. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros. The default precision is 1. When 0 is printed with an explicit precision 0, the output is empty.
e,E
Thedoubleargument is rounded and converted in the style [-]d.ddde\*(Pmdd where there is one digit before the decimal-point character and the number of digits after it is equal to the precision; if the precision is missing, it is taken as 6; if the precision is zero, no decimal-point character appears. AnEconversion uses the letterE(rather thane) to introduce the exponent. The exponent always contains at least two digits; if the value is zero, the exponent is 00.
f,F
Thedoubleargument is rounded and converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly zero, no decimal-point character appears. If a decimal point appears, at least one digit appears before it.

(The SUSv2 does not know aboutFand says that character string representations for infinity and NaN may be made available. The C99 standard specifies `[-]inf' or `[-]infinity' for infinity, and a string starting with `nan' for NaN, in the case offconversion, and `[-]INF' or `[-]INFINITY' or `NAN*' in the case ofFconversion.)

g,G
Thedoubleargument is converted in stylefore(orForEforGconversions). The precision specifies the number of significant digits. If the precision is missing, 6 digits are given; if the precision is zero, it is treated as 1. Styleeis used if the exponent from its conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.
a,A
(C99; not in SUSv2) Foraconversion, thedoubleargument is converted to hexadecimal notation (using the letters abcdef) in the style [-]0xh.hhhhp\*(Pmd; forAconversion the prefix0X, the letters ABCDEF, and the exponent separatorPis used. There is one hexadecimal digit before the decimal point, and the number of digits after it is equal to the precision. The default precision suffices for an exact representation of the value if an exact representation in base 2 exists and otherwise is sufficiently large to distinguish values of typedouble. The digit before the decimal point is unspecified for non-normalized numbers, and nonzero but otherwise unspecified for normalized numbers.
c
If nolmodifier is present, theintargument is converted to anunsigned char, and the resulting character is written. If anlmodifier is present, thewint_t(wide character) argument is converted to a multibyte sequence by a call to thewcrtombfunction, with a conversion state starting in the initial state, and the resulting multibyte string is written.
s
If nolmodifier is present: Theconst char *argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminatingNULcharacter; if a precision is specified, no more than the number specified are written. If a precision is given, no null character need be present; if the precision is not specified, or is greater than the size of the array, the array must contain a terminatingNULcharacter.

If anlmodifier is present: Theconst wchar_t *argument is expected to be a pointer to an array of wide characters. Wide characters from the array are converted to multibyte characters (each by a call to thewcrtombfunction, with a conversion state starting in the initial state before the first wide character), up to and including a terminating null wide character. The resulting multibyte characters are written up to (but not including) the terminating null byte. If a precision is specified, no more bytes than the number specified are written, but no partial multibyte characters are written. Note that the precision determines the number ofbyteswritten, not the number ofwide charactersorscreen positions. The array must contain a terminating null wide character, unless a precision is given and it is so small that the number of bytes written exceeds it before the end of the array is reached.

C
(Not in C99, but in SUSv2.) Synonym forlc. Don't use.
S
(Not in C99, but in SUSv2.) Synonym forls. Don't use.
p
Thevoid *pointer argument is printed in hexadecimal (as if by%#xor%#lx).
n
The number of characters written so far is stored into the integer indicated by theint *(or variant) pointer argument. No argument is converted.
%
A `%' is written. No argument is converted. The complete conversion specification is `%%'.

EXAMPLES


To print to five decimal places:

#include <math.h>#include <stdio.h>fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));

To print a date and time in the form `Sunday, July 3, 10:02', whereweekdayandmonthare pointers to strings:

#include <stdio.h>fprintf(stdout, "%s, %s %d, %.2d:%.2d\n", weekday, month, day, hour, min);

Many countries use the day-month-year order. Hence, an internationalized version must be able to print the arguments in an order specified by the format:

#include <stdio.h>fprintf(stdout, format, weekday, month, day, hour, min);

whereformatdepends on locale, and may permute the arguments. With the value

"%1$s, %3$d. %2$s, %4$d:%5$.2d\n"

one might obtain `Sonntag, 3. Juli, 10:02'.

To allocate a sufficiently large string and print into it (code correct for both glibc 2.0 and glibc 2.1):

#include <stdio.h>#include <stdlib.h>#include <stdarg.h>char *make_message(const char *fmt, ...) { /* Guess we need no more than 100 bytes. */ int n, size = 100; char *p; va_list ap; if ((p = malloc (size)) == NULL) return NULL; while (1) { /* Try to print in the allocated space. */ va_start(ap, fmt); n = vsnprintf (p, size, fmt, ap); va_end(ap); /* If that worked, return the string. */ if (n > -1 && n < size) return p; /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ size = n+1; /* precisely what is needed */ else /* glibc 2.0 */ size *= 2; /* twice the old size */ if ((p = realloc (p, size)) == NULL) return NULL; }}

NOTES

The glibc implementation of the functionssnprintfandvsnprintfconforms to the C99 standard, i.e., behaves as described above, since glibc version 2.1. Until glibc 2.0.6 they would return -1 when the output was truncated.

CONFORMING TO

Thefprintf,printf,sprintf,vprintf,vfprintf, andvsprintffunctions conform to ANSI X3.159-1989 (``ANSI C'') and ISO/IEC 9899:1999 (``ISO C99''). Thesnprintfandvsnprintffunctions conform to ISO/IEC 9899:1999.

Concerning the return value ofsnprintf, the SUSv2 and the C99 standard contradict each other: whensnprintfis called withsize=0 then SUSv2 stipulates an unspecified return value less than 1, while C99 allowsstrto be NULL in this case, and gives the return value (as always) as the number of characters that would have been written in case the output string has been large enough.

Linux libc4 knows about the five C standard flags. It knows about the length modifiers h,l,L, and the conversions cdeEfFgGinopsuxX, where F is a synonym for f. Additionally, it accepts D,O,U as synonyms for ld,lo,lu. (This is bad, and caused serious bugs later, when support for %D disappeared.) No locale-dependent radix character, no thousands' separator, no NaN or infinity, no %m$ and *m$.

Linux libc5 knows about the five C standard flags and the ' flag, locale, %m$ and *m$. It knows about the length modifiers h,l,L,Z,q, but accepts L and q both for long doubles and for long long integers (this is a bug). It no longer recognizes FDOU, but adds a new conversion characterm, which outputsstrerror(errno).

glibc 2.0 adds conversion characters C and S.

glibc 2.1 adds length modifiers hh,j,t,z and conversion characters a,A.

glibc 2.2 adds the conversion character F with C99 semantics, and the flag character I.

HISTORY

Unix V7 defines the three routinesprintf,fprintf,sprintf, and has the flag -, the width or precision *, the length modifier l, and the conversions doxfegcsu, and also D,O,U,X as synonyms for ld,lo,lu,lx. This is still true for BSD 2.9.1, but BSD 2.10 has the flags #, + and <space> and no longer mentions D,O,U,X. BSD 2.11 hasvprintf,vfprintf,vsprintf, and warns not to use D,O,U,X. BSD 4.3 Reno has the flag 0, the length modifiers h and L, and the conversions n, p, E, G, X (with current meaning) and deprecates D,O,U. BSD 4.4 introduces the functionssnprintfandvsnprintf, and the length modifier q. FreeBSD also has functionsasprintfandvasprintf, that allocate a buffer large enough forsprintf. In glibc there are functionsdprintfandvdprintfthat print to a file descriptor instead of a stream.

BUGS

Becausesprintfandvsprintfassume an arbitrarily long string, callers must be careful not to overflow the actual space; this is often impossible to assure. Note that the length of the strings produced is locale-dependent and difficult to predict. Usesnprintfandvsnprintfinstead (orasprintfandvasprintf).

Linux libc4.[45] does not have asnprintf, but provides a libbsd that contains ansnprintfequivalent tosprintf, i.e., one that ignores thesizeargument. Thus, the use ofsnprintfwith early libc4 leads to serious security problems.

Code such asprintf(foo);often indicates a bug, sincefoomay contain a % character. Iffoocomes from untrusted user input, it may contain %n, causing theprintfcall to write to memory and creating a security hole.

SEE ALSO

printf(1),asprintf(3),dprintf(3),wcrtomb(3),wprintf(3),scanf(3),locale(5)

四 : fclose 中文man页面(1)

NAME

fclose - 关闭流

SYNOPSIS 总览

#include <stdio.h>

int fclose(FILE *stream);

DESCRIPTION 描述

函数fclose将名为stream的流与它底层关联的文件或功能集合断开。如果流曾用作输出,任何缓冲的数据都将首先被写入,使用fflush(3) 。

RETURN VALUE 返回值

成功执行返回 0,否则返回EOF并设置全局变量errno来指示错误发生。任何一种情况下,对流再进行存取 (包括再次调用fclose()) 都会带来未定义的结果。

ERRORS

EBADF
stream底层的文件描述符是无效的。

函数fclose也可能失败并置errnoclose(2),write(2) 或fflush(3) 指定的值。

NOTES 要点

注意fclose仅仅刷新用户空间的由 C 库提供的缓冲。要保证数据被物理地存储到磁盘上,必须也刷新内核缓冲。例如,使用sync(2) 或fsync(2).

CONFORMING TO 标准参考

函数fclose遵循 ANSI X3.159-1989 (``ANSI C'') 标准。

SEE ALSO 参见

close(2),fcloseall(3),fflush(3),fopen(3),setbuf(3)

fclose 中文man页面(1)_fclose

NAME

fclose - close a stream

SYNOPSIS

#include <stdio.h>

int fclose(FILE *stream);

DESCRIPTION

Thefclosefunction dissociates the namedstreamfrom its underlying file or set of functions. If the stream was being used for output, any buffered data is written first, usingfflush(3).

RETURN VALUE

Upon successful completion 0 is returned. Otherwise,EOFis returned and the global variableerrnois set to indicate the error. In either case any further access (including another call tofclose()) to the stream results in undefined behaviour.

ERRORS

EBADF
The filedescriptor underlyingstreamis not valid.

Thefclosefunction may also fail and seterrnofor any of the errors specified for the routinesclose(2),write(2) orfflush(3).

NOTES

Note thatfcloseonly flushes the user space buffers provided by the C library. To ensure that the data is physically stored on disk the kernel buffers must be flushed too, e.g. withsync(2) orfsync(2).

CONFORMING TO

Thefclosefunction conforms to ANSI X3.159-1989 (``ANSI C'').

SEE ALSO

close(2),fcloseall(3),fflush(3),fopen(3),setbuf(3)

本文标题:192.168.1.1登录页面-deallocvt 中文man页面(1)
本文地址: http://www.61k.com/1128358.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1