My best advice would be to ask a C language question on a C language forum. This forum is really only for questions about the SQL language for the PostgreSQL database. I.e. no MariaDB, MySQL, MS SQL questions.
First, you didn't say what OS and she'll you're using. I an guessing BASH and Linux.
Second, you did NO error checking. I would purely guess that the lseek() is getting a return value of -1, probably with an error of ESPIPE.