五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

(5)關(guān)于Linux系統(tǒng)的lseek函數(shù)誤區(qū)指南(附測試源碼)

2023-03-08 17:24 作者:豆豆?jié)M江紅  | 我要投稿

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>


int main(void)

{

? ? int fd1,fd2;

? ? int ret;

? ? char buf[128]={0};



? ? fd1 = open("./test_file",O_TRUNC|O_RDWR);

? ? if(-1 == fd1){

? ? ? ? perror("open error");

? ? ? ? return -1;

? ? }


? ? lseek(fd1,0,SEEK_END);? ??

? ? ret = write(fd1,"HELLO WORLD",11);

? ? if (-1 == ret)

? ? {

? ? ? ? perror("write error");

? ? ? ? close(fd1);

? ? ? ? return -1;

? ? }

? ??

? ? fd2 = open("./test_file",O_RDWR);


? ? lseek(fd2,0,SEEK_END);

? ? ret = write(fd2,"My Love",7);

? ? if(-1 == ret)

? ? {

? ? ? ? perror("read error");

? ? ? ? close(fd1);

? ? ? ? return -1;

? ? }


? ? lseek(fd2,0,SEEK_SET);


? ? ret = read(fd2,buf,18);

? ? if(-1 == ret){

? ? ? ? perror("read error");

? ? ? ? close(fd1);

? ? ? ? close(fd2);

? ? ? ? return -1;

? ? }

? ? printf("read is %s\n",buf);

? ? close(fd1);

? ? close(fd2);

}

/*驗證結(jié)論 : 對于lseek函數(shù)。將文件做末尾對齊時 它會從已經(jīng)寫的字節(jié)的開頭開始寫

即 如果你已經(jīng)寫了一些內(nèi)容如下

buf=[HELLO WORLD]

此時再進(jìn)行末尾寫入

得到的結(jié)果為

buf=[HELLO WORLDMy Love]

*/


(5)關(guān)于Linux系統(tǒng)的lseek函數(shù)誤區(qū)指南(附測試源碼)的評論 (共 條)

分享到微博請遵守國家法律
铜川市| 福鼎市| 繁昌县| 龙海市| 大厂| 门头沟区| 招远市| 昆明市| 都安| 南皮县| 连江县| 蓬溪县| 耿马| 固阳县| 长汀县| 聂荣县| 吴旗县| 天津市| 黄大仙区| 托克托县| 玉山县| 临桂县| 合川市| 广东省| 樟树市| 南陵县| 宜章县| 柳林县| 高清| 时尚| 灵武市| 沾益县| 平乐县| 黄浦区| 平湖市| 太仆寺旗| 晋城| 西和县| 仁化县| 枣强县| 旬邑县|