Hi all,
I have a bit of a dilemma I'm hoping someone might be able
to shed some light on.
I'm working on some software which uses fopen(), fread(),
fseek(), and fclose() to operate on data in a file. This
is working for files on disk but I would like to extend
this to work on stdin as well. At the moment I'm doing
this by by setting the FILE* pointer to stdin and it works
on one case but not on another.
Case 1:
myprog <file - works fine
Case 2:
cat file |myprog - fseek() fails
My guess is that the "<" file redirection actually causes
the shell to open the disk file and connects it to the
program while "|" pipe command creates a temporary buffer
which feeds stdin of my program. Obviously, the temporary
buffer won't support fseek().
So, my question is, what's the best way of getting my program
to work correctly with piped input? I have thought of using a
temporary file but I'm hoping for a neater solution.
Thanks in advance,
Neo
PS: I'm working on Linux with gcc but the behaviour is the
same on Sparc Solaris.
PPS: Please post the answer to the group rather than emailing me.
--
Neo Brave
Going where no-one has gone before!
Sent via Deja.com http://www.deja.com/
Before you buy.