-
pwrite
鎖定
pwrite函數名
pwrite
pwrite功能
帶偏移量地寫數據到文件中
pwrite函數原型
ssize_t pwrite(intfd, const void *buf, size_tcount, off_toffset);
pwrite用法
返回值:成功,返回寫入到文件中的字節數;失敗,返回-1;
參數:
(1) fd:要寫入數據的文件描述符
(3) count:寫入文件中的數據的字節數
(4) offset:偏移地址
pwrite程序實例
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> void main() { int fd; int count = 128; int offset = 32; int ret; char buf[1024]="hi ! this is pwrite."; char pathname[128] = "/tmp/1.txt"; fd = open( pathname, O_WRONLY); if((ret = pwrite(fd, buf, count, offset))==-1) { printf("pwrite error\n"); exit(1); } else { printf("pwrite success\n"); printf("the writed data is:%s\n", buf); } }
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:11次歷史版本
- 最近更新: JD萤火虫003