Xref: utzoo comp.unix.questions:6435 comp.unix.wizards:7593 comp.lang.c:8932 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ncar!noao!arizona!lm From: lm@arizona.edu (Larry McVoy) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.lang.c Subject: Re: Writing to A NON-Existing File in "C" Message-ID: <4709@megaron.arizona.edu> Date: 6 Apr 88 07:28:12 GMT References: <9654@jplgodo.UUCP> Reply-To: lm@megaron.arizona.edu (Larry McVoy) Distribution: na Organization: University of Arizona, Tucson Lines: 46 Keywords: C program, NON-EXISTING File, flushed results 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 ------ UNTESTED! ------- If you are using FILE* # include # include # include FILE* myopen(name) char* name; { struct stat buf; extern errno; if (stat(name, &buf) == -1 && errno == ENOENT) return fopen("/dev/null", "w"); else return fopen(name, "w"); } Else myopen(name) char* name; { struct stat buf; extern errno; if (stat(name, &buf) == -1 && errno == ENOENT) return open("/dev/null", 1); else return open(name, 1); } How's that? -- "These aren't my thoughts, they're my cat walking on the keyboard." Larry McVoy lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm