我在C中有以下代码

long from = atol(buffer);
printf("From: %ld\n", from);

int file_fd = open(fullPath, O_RDONLY);
if (file_fd == -1) error("Error opening file");

if (from > -1)
{
    int a = lseek(file_fd, from, SEEK_SET);
    if (a == -1)
        error("Error in lseek");
}


由于以下原因,lseek操作将在lseek中返回错误:无效参数

void error(char *msg)
{
    perror(msg);
    exit(1);
}


您是否知道如何调试它,以便找出问题所在?我以为这很琐碎,但却让我发疯。

谢谢

最佳答案

您是否尝试过strace?在深入研究源代码之前,我先检查一下该代码,以找出在哪里抛出“无效参数”。

看到肖恩的答案,您是否包括适当的标题?

   #include <sys/types.h>
   #include <unistd.h>

关于c - lseek问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1183301/

10-08 23:22