Xref: utzoo comp.unix.questions:6592 comp.unix.wizards:7819 comp.lang.c:9400 Path: utzoo!utgpu!water!watmath!clyde!att-cb!osu-cis!tut.cis.ohio-state.edu!uwmcsd1!marque!uunet!vsi!friedl From: friedl@vsi.UUCP (Stephen J. Friedl) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.lang.c Subject: Re: Writing to A NON-Existing File in "C" Summary: Please do *not* use access to see if a file exists Keywords: C program, NON-EXISTING File, flushed results Message-ID: <549@vsi.UUCP> Date: 16 Apr 88 02:28:01 GMT References: <9654@jplgodo.UUCP> <10285@steinmetz.steinmetz.ge.com> <147@obie.UUCP> Distribution: na Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 31 In article <9654@jplgodo.UUCP> deutsch@jplgodo.UUCP (Michael Deutsch ) writes: > I have a "C" program that records the program results into a file, > provided that file already exists. In case the file DOES NOT exist > I want the program to function identically but the results should > be flushed down the tube, i.e. nowhere, i.e. written to a nong > file? Then (William E. Davidsen Jr) replies: > [little C fragment to do the above] In article <147@obie.UUCP>, wes@obie.UUCP (Barnacle Wes) writes: > I'd do it slightly different. Unless you need speed, try using > access(2) to determine if the file is available to you, and if not > open /dev/null for writing: > > [little C fragment to do the above] AAAAAAAAAARGH! Please do not use access(2) as a handy-dandy "does the file exist?" function. It is designed to be used by set-{user,group}-id programs to see if the underlying user has permission to access the file in the requested manner. I hate to sound like a flamer, but programmers who do not understand the troubles with access(2) should probably not use it; you will make life difficult for somebody down the road. Stat(2) can be used to do the same thing with just a little extra code. I wrote an "accfile(3)" function that does what you *think* access(2) is doing; send me a note to get a copy. Steve Friedl, resident access(2)-basher -- Steve Friedl V-Systems, Inc. "Yes, I'm jeff@unh's brother" friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl