简体   繁体   English

lseek问题

[英]Problem with lseek

I have the following code in C 我在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");
}

The lseek operation is returning Error in lseek: Invalid argument , as a result of 由于以下原因,lseek操作返回的错误lseek:Invalid arguments:

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

Do you have any idea how can I debug it so I can find out what's wrong? 您是否知道如何调试它,以便找出问题所在? I thought it was very trivial but it's driving me crazy. 我以为这很琐碎,但却让我发疯。

Thanks 谢谢

Have you tried strace on the process? 您是否尝试过strace? I'd check that before digging into the source to find out where is "invalid argument" thrown. 在深入研究源代码之前,我会先检查一下该代码,以找出在何处抛出“无效参数”。

Seeing Sean's answer, have you included the proper headers? 看到肖恩的答案,您是否包括适当的标题?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM