Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!ucbvax!agate!garnet.berkeley.edu!andy From: andy@garnet.berkeley.edu (Andy Lieberman) Newsgroups: comp.unix.questions Subject: rename() system call Message-ID: <24504@agate.BERKELEY.EDU> Date: 17 May 89 02:57:13 GMT Sender: usenet@agate.BERKELEY.EDU Organization: University of California, Berkeley Lines: 24 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@garnet.Berkeley.EDU and I will post a summary. Thanks in advance, Andy Lieberman Library Systems Office UC Berkeley