linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* lseek question
@ 2005-11-06  1:14 fabio
  2005-11-06  2:04 ` Markus Rechberger
  0 siblings, 1 reply; 2+ messages in thread
From: fabio @ 2005-11-06  1:14 UTC (permalink / raw)
  To: linux-c-programming

Hello people,

What's wrong with this code:

-bash-3.00$ cat lseek.c ; wc -l datafile ; gcc lseek.c ; ./a.out 1000
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
main(int argc, char *argv[])
{
        FILE *fp;
        int offset=atoi(argv[1]);
        fp=fopen("datafile","r");
        lseek(fp,offset,SEEK_SET);
        char foo[256];
        fscanf(fp,"%s\n",foo);
        printf("%s\n",foo);
}

 1000000 datafile
lseek.c: In function `main':
lseek.c:9: warning: passing arg 1 of `lseek' makes integer from pointer 
without a cast
record:0


The record number 1000 is called "record:10000" :). According to truss:

-bash-3.00$ truss ./a.out 1000 2>&1 |more
execve("a.out", 0xFFBFF1D4, 0xFFBFF1E0)  argc = 2
 argv: ./a.out 100
[snip]
open("datafile", O_RDONLY)                      = 3
lseek(-13187092, 1000, SEEK_SET)                Err#9 EBADF
fstat64(3, 0xFFBFEC30)                          = 0
brk(0x00020A68)                                 = 0
brk(0x00024A68)                                 = 0
fstat64(3, 0xFFBFEAD8)                          = 0
ioctl(3, TCGETA, 0xFFBFEBBC)                    Err#25 ENOTTY
read(3, " r e c o r d : 0\n r e c".., 8192)     = 8192
ioctl(1, TCGETA, 0xFFBFE1FC)                    Err#22 EINVAL
fstat64(1, 0xFFBFE270)                          = 0
fstat64(1, 0xFFBFE118)                          = 0
record:0
write(1, " r e c o r d : 0\n", 9)               = 9
llseek(3, 0xFFFFFFFFFFFFE009, SEEK_CUR)         = 9
_exit(141956)


Thanks for help.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-11-06  2:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-06  1:14 lseek question fabio
2005-11-06  2:04 ` Markus Rechberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).