gpt4 book ai didi

c - 将 win32 中编写的 C 代码替换为基于 linux 的系统

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:08 25 4
gpt4 key购买 nike

我正在尝试为 MacOSX 复制 WIN32 代码,但是我无法复制部分代码

这是代码。

main_int64 pos;
OP_ASSERT(sizeof(pos)==sizeof(fpos_t));
/*Translate the seek to an absolute one.*/
if(_whence==SEEK_CUR)
{
int ret;
ret=fgetpos((FILE *)_stream,(fpos_t *)&pos);
if(ret)return ret;
}
else if(_whence==SEEK_END)pos=_filelengthi64(_fileno((FILE *)_stream));
else if(_whence==SEEK_SET)pos=0;
else return -1;
/*Check for errors or overflow.*/
if(pos<0||_offset<-pos||_offset>OP_INT64_MAX-pos)return -1;
pos+=_offset;

int seeko = fsetpos((FILE *)_stream,(fpos_t *)&pos);
fprintf("BaseTool", "SEEKO VALUE %d \n", seeko);
return seeko;

我卡在了

else if(_whence==SEEK_END)pos=_filelengthi64(_fileno((FILE
*)_stream));

我不确定如何在基于 mac 的系统中替换这些函数,因为这些是基于 WIN 的函数

最佳答案

从代码中我了解到你正在尝试获取文件的长度,在 linux 中你可以这样做,

 int fp           = open("check5.c", O_RDONLY);
off_t lengthOfFile = lseek(fp, 0, SEEK_END);
close(fp);
printf("%d",lengthOfFile);

因此将其替换为“lseek(fileno,0, SEEK_END)”应该给出文件的长度。

关于c - 将 win32 中编写的 C 代码替换为基于 linux 的系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50288814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com