Problem with lseek

c

I have the following code in 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

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

Best Answer

Have you tried strace on the process? 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>