[vox-tech] [C] randomly accessing file data in C

Mark K. Kim vox-tech@lists.lugod.org
Tue, 20 May 2003 23:12:50 -0700 (PDT)


Never mind... got it figured out.  I had forgotten to put a couple flags.
Heh... it happens now and then :P  I'm now using POSIX calls instead of
the C library calls -- probably safer to interact directly with the kernel
rather than through the C library -- one less layer of large file support
to worry about.

Anyway, as always, Jeff has some productive things to say here so let
me reply...:

On Tue, 20 May 2003, Jeff Newmiller wrote:

> You need to be careful how you open it... if you are using open, you
> probably want O_RDWR mode... if fopen, "r+".

If I'm reading one file, then writing another, I only need "r" for the
file I'm reading and "w" for the file I'm writing, don't I?  Why would
you open it "r+"?

Anyway, I'm now opening the output file with (O_WRONLY | O_CREAT |
O_LARGEFILE).  Should I open it with (O_RDWR | O_CREAT | O_LARGEFILE)
instead?

> Google sez http://www.suse.de/~aj/linux_lfs.html.  Note that the gory
> details are described in the document linked at the bottom of the "Using
> LFS" section.

This is great!  Thank you for the link!!! ^_^

> I say be scrupulous about using typedefs like off_t or you will be sorry,
> and beware of shared libraries that aren't set up for large file support.

Thanks for the warning!

> PS: Looked at your code... it is always a red flag to me when you place
> your own prototypes for library functions in your source file.  Use the
> defines described in the document referenced above.  Also, you are using
> "w+b" instead of "r+b".

Yeah, I'm weary, too.  I couldn't figure out how to do it properly but
your link above showed the right way.  Thank you sooooo much!! ^_^

-Mark

PS: Someone really should document the LFS API into the man pages.
Anyone got time? ^_^


-- 
Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.