文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>输出&输出

输出&输出

时间:2010-10-05  来源:noyear

1.linux文件系统文件类型:
套接口(Socket)
符号链接(Symbolic link)
FIFO
普通文件(Regular file)
目录(Directory)
块设备(Block device)
字符设备(Character device)
2.文件模式--是一个16比特位的域,由一个八进制数表示,代表文件的文件类型和
访问权限。其中,访问权限和修饰位占低12比特位,高4比特位表示文件类型。
3. #include <sys/stat.h>
    mode_t umask(mode_t newmask);
把进程的新umask设置为newmask,无论调用成功与否umask返回原来的umask值。注
意,使用这个函数只能设置更严格的umask掩码。
4. 文件描述符
打开和关闭
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags).
int creat(const char *pathname, int flags, mode_t mode);
读写文件描述符
#include <unistd.h>
ssize_t read(int fd, const void *buf, size_t count);
ssize_t write(int fd,const void *buf, size_t count);
缩短文件
#include <unistd.h>
int ftruncate(int fd, off_t length);
定位文件指针
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int fd, off_t offset, int whence);
//whrence: SEEK_SET, SEEK_CUR, SEEK_END.
同步到硬盘
#include <unistd.h>
int fsync(int fd);
#ifdef _POSIX_SYNCHRONIZED_IO
int fdatasync(int fd);
#endif
获得文件信息 fstat
#include <sys/stat.h>
#include <unistd.h>
int fstat(int fd, struct stat *buf);

改变文件所有权 fchown
#include <sys/types.h>
#include <unistd.h>
int fchown(int fd, uid_t owner, gid_t group);
改变文件读写权 fchmod
#include <sys/types.h>
#include <sys/stat.h>
int fchmod(int fd, mode_t mode);

给文件上锁 flock  fcntl
#include <sys/file.h>
int flock(int fd, int operation);
// operation : LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB
访问一个上锁文件步骤:
1,检查是否有锁
2,如果文件没有锁,则建立自己的锁
3,打开文件
4,对文件做必要的修改。
5,关闭文件
6,对文件解锁。

#include <unistd.h>
#include <fcntl.h>
int fcntl(int fd, int cmd);
int fcntl(int fd, int cmd, long arg);
int fcntl(int fd, int cmd, struct flock *lock);

复制文件描述符
#include <unistd.h>
int dup(int oldfd)
int dup2(int oldfd, int newfd);
5,select同时读写多个文件
int select(int n, fd_set *readfds, fd_set *writefds, fd_set exceptfds,
struct timeval *timeout);

FD_ZERO(fd_set *set)
FD_SET(int fd, fd_set *set);
FD_CLR(int fd, fd_set *set);
FD_ISSET(int fd, fd_set *set);
6,ioctl
#include <sys/ioctl.h>
int ioctl(int d,int request,...);
//参数d必须是一个打开的文件描述符,系统调用ioctl的作用是设置或检索文件
的多种上有关参数并对文件进行一些其它的操作。

相关阅读 更多 +
排行榜 更多 +
野生恐龙射击生存安卓版

野生恐龙射击生存安卓版

飞行射击 下载
战场狙击手

战场狙击手

飞行射击 下载
1v1布娃娃射击安卓版

1v1布娃娃射击安卓版

飞行射击 下载