rename() system call

Andy Lieberman andy at garnet.berkeley.edu
Wed May 17 12:57:13 AEST 1989


I'm running on a SUN 3/50 with OS4.something.  I need to rename a file from
within a C program, but my call to rename must return an error if a file
with the new name already exists.  I cannot simply check for the presence of 
the file before calling rename because there's a slight chance that another 
process (_completely_ out of my control) may create the file at any time.

I thought of doing a system call to mv (probably through popen), but this
seems very wasteful.

Anybody else faced this before?  Is there some way to create a critical 
section of code so that I could have:

dont_swap;
if (file_doesnt_exist) {
	rename();
}
swap_as_needed;

Please e-mail responses to andy at garnet.Berkeley.EDU and I will post a summary.

Thanks in advance,
Andy Lieberman
Library Systems Office
UC Berkeley



More information about the Comp.unix.questions mailing list