码迷,mamicode.com
首页 > 系统相关 > 详细

linux 通用IO

时间:2014-12-08 17:12:52      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:des   io   ar   os   sp   for   on   文件   bs   

open(),read(),write(),close()可以应用于管道,FIFO,socket,或者终端等所有文件类型执行IO操作。

lseek()并不适用于所有类型的文件。不允许将lseek()应用于管道,FIFO,socket或者终端,只要合情合理,也可以将lseek应用于设备。例如在磁盘或磁带上查找一处具体位置。

cp test test.old

cp test /dev/pts/0

cp /dev/pts/0 test

cp /dev/pts/0 /dev/pts/1

[root@250-shiyan pts]# echo "wo shi " > /dev/pts/0
[root@250-shiyan ~]# cp /dev/pts/1 b.txt
fjei
sfoei
rifeo
wfowef
[root@250-shiyan ~]# cat b.txt
fjei
sfoei
rifeo
wfowef

 

/usr/include/netinet/in.h 

/* Structure describing an Internet socket address.  */
struct sockaddr_in
  {
    __SOCKADDR_COMMON (sin_);
    in_port_t sin_port;                 /* Port number.  */
    struct in_addr sin_addr;            /* Internet address.  */

    /* Pad to size of `struct sockaddr‘.  */
    unsigned char sin_zero[sizeof (struct sockaddr) -
                           __SOCKADDR_COMMON_SIZE -
                           sizeof (in_port_t) -
                           sizeof (struct in_addr)];
  };

/* Ditto, for IPv6.  */
struct sockaddr_in6
  {
    __SOCKADDR_COMMON (sin6_);
    in_port_t sin6_port;        /* Transport layer port # */
    uint32_t sin6_flowinfo;     /* IPv6 flow information */
    struct in6_addr sin6_addr;  /* IPv6 address */
    uint32_t sin6_scope_id;     /* IPv6 scope-id */
  };

/usr/include/sys/socket.h

/* Create a new socket of type TYPE in domain DOMAIN, using
   protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
   Returns a file descriptor for the new socket, or -1 for errors.  */
extern int socket (int __domain, int __type, int __protocol) __THROW;


socketpair()系统调用只能用在unix domain中,
/* Create two new sockets, of type TYPE in domain DOMAIN and using
   protocol PROTOCOL, which are connected to each other, and put file
   descriptors for them in FDS[0] and FDS[1].  If PROTOCOL is zero,
   one will be chosen automatically.  Returns 0 on success, -1 for errors.  */
extern int socketpair (int __domain, int __type, int __protocol,
                       int __fds[2]) __THROW;

linux 通用IO

标签:des   io   ar   os   sp   for   on   文件   bs   

原文地址:http://www.cnblogs.com/createyuan/p/4151297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!