From: fabio <fabio@crearium.com>
To: linux-c-programming@vger.kernel.org
Subject: lseek question
Date: Sat, 05 Nov 2005 19:14:59 -0600 [thread overview]
Message-ID: <436D5913.504@crearium.com> (raw)
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.
next reply other threads:[~2005-11-06 1:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-06 1:14 fabio [this message]
2005-11-06 2:04 ` lseek question Markus Rechberger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=436D5913.504@crearium.com \
--to=fabio@crearium.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.