数据类型不一致:
stdin类型为 FILE*
STDIN_FILENO类型为 int
使用stdin的函数主要有:fread、fwrite、fclose等,基本上都以f开头
使用STDIN_FILENO的函数有:read、write、close等
层次不一样。STDIN 属于标准库处理的输入流,其声明为 FILE 型的,对应的函数前面都有f开头,如fopen/fread/fwrite/fclose 标准库调用等
STDIN_FILENO属于系统API接口库,其声明为 int 型,是一个打开文件句柄,对应的函数主要包括 open/read/write/close 等系统级调用。
标准库内封装了系统 API 调用,如 fread 内部实现调用 read。
获取主机mac地址程序源代码;
#include <sys/types.h>
#include <sys/socket.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <linux/if.h>
int
main ()
{
int fd;
struct ifreq ifr;
int i;
char *j;
fd = socket (AF_INET, SOCK_DGRAM, 0);
strcpy (ifr.ifr_name, "eth0");
if (ioctl (fd, SIOCGIFHWADDR, &ifr) < 0)
{
puts ("error");
}
else
{
j = ifr.ifr_hwaddr.sa_data;
for (i = 0; i < 6; i++, j++)
printf ("%02x:", (0xff & (*j)));
printf("/n");
}
}
The function fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. The open status of the stream is unaffected. If the stream argument is NULL, fflush() flushes all open output streams.
Note that fflush() only 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, for example, with sync(2) or fsync(2). |
size_t
有时就是unsigned int;
有时就是unsigned long;
它的定义随体系结构而不定。
off_t和size_t类似,但是off_t可以是负数。
On many architectures both off_t and long are 32-bit types, but compilation with
#define _FILE_OFFSET_BITS 64
will turn off_t into a 64-bit type.
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
sendfile() copies data between one file descriptor and another. Because this copying is done within the kernel,
sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data
to and from user space.