l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2003 May 21 09:06

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] [C] randomly accessing file data in C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



On Tue, 20 May 2003, Mark K. Kim wrote:

> 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+"?

Read the manpage for fopen, and compare "r+" to "w+", as they behave
differently.  I thought you were reading and writing from the same file
when I wrote that... recall your opening text:

> > > I'm trying to access data in a file in C.  I want to read some
> > > portion of it, modify it, then rewrite that portion back into the
> > > file.


> 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?

Only if you intended to read and write the same file.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------


_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!