lseek()函数:移动光标
off_t lseek(int fd, off_t offset, int whence);
使用lseek函数需要的头文件:
#include <unistd.h>
#include <sys/types.h>
lseek()的返回值:
返回一个整型数,大小为文件内容长度
参数:
int fd:
使用open()时返回的文件描述符
off_t offset:
偏移字节:0为不偏移,-a为往前偏移a个字节,b为往前偏移b个字节
int whence:
光标位置:
SEEK_SET 文件指针开始位置
SEEK_CUR 文件指针当前位置
SEEK_END 文件指针尾部位置
文件创建函数:creat()
int creat(const char *pathname, mode_t mode);
使用creat函数需要的头文件:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
creat()的返回值:
返回一个文件描述符,当文件成功创建时,返回一个非负整数,当文件创建失败时,返回-1
参数:
const char *pathname:
路径,创建的文件后会存在于该路径
mode_t mode:
选择打开文件的操作:
S_IRUSR 可读
S_IWUSR 可写
S_IXUSR 可执行
S_IRWXU 可读、写、执行
创建一个可执行的文件file_h