linux下文件的读写操作、字符串的处理操作,多线程操作等相关函数使用说明

来源:互联网 发布:unity3d texture type 编辑:程序博客网 时间:2024/05/17 22:27

linux系统中:

         对文件的读写操作一般有如下几个函数:open , read , write , close ,lseek;

函数声明功能说明参数说明头文件更多

int open(const *pathname, int flags);

int open(const *pathname,int flags,

mode_t mode);

1.打开已有文件

2.新建并打开文件

3.打开成功后返回文件描述符

pathname:欲打开文件路劲字符串

flags:文件属性设置,有:

O_RDONLY(只读);O_WRONLY(只写)

O_RDWR(可读写);O_CREAT(新建)

#include <sys/types.h>

#include <sys/stat.h>

#include<fcntl.h>

百科

ssize_t read(int fd,void *buf,size_t count)从已打开的文件读取数据

fd:文件描述符---需要读取的文件

count:需读取的字节数;

buf:数据所存内存的指针;

#include<unistd.h>百科ssize_t write(int fd,const void *buf,size_t count);将数据写入已打开的文件

fd:文件描述符---需要写入的文件

count:需读取的字节数;

buf:数据所存内存的指针;

#include<unistd.h>百科int close(int fd);关闭文件

fd:文件描述符---需关闭的文件

成功返回 0,失败:-1;

#include<unistd.h> off_t lseek(int fildes,off_t offset,int whence);移动文件的读写位置

fildes:文件描述符;

offset:根据whence的偏移量;

whence:可为SEEK_SET,

SEEK_CUR:当前位置

SEEK_END:文件尾部

#include<sys/types.h>

#include<unistd.h>

 

        对字符串的操作较常用的有如下几个函数:memcpy,memcmp,strcasecmp,strcasecmp,

       而多线程的操作主要有以下几个函数:fork(),pthread_creat()等

 

 注译:更多的linux函数使用说明请参考:“linux函数库”一书,已上传共享;

原创粉丝点击