Path: utzoo!mnetor!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!nrl-cmf!cmcl2!brl-adm!adm!drears@ardec.arpa From: drears@ardec.arpa (Dennis G. Rears (FSAC)) Newsgroups: comp.unix.wizards Subject: Re: Writing to A NON-Existing File in C Message-ID: <12895@brl-adm.ARPA> Date: 9 Apr 88 17:22:49 GMT Sender: news@brl-adm.ARPA Lines: 55 ok. ok. After over 20 messages I admit I f*cked up on my posting and program. The errors pointed out were: 1) comment should have ended in "*/" not "*?" 2) The declaration #define NULL "/dev/null/" should not have used NUll and the / after null was wrong 3) I use the word FILE instead of FILENAME in my stat(2) call Next time I will not send a program while sleeping. Please no more messages about this. Here is a corrected version of it: #include #include #include #define FILENAME "/usr/foobar" /* not a trademark of AT&T */ #define DEVNULL "dev/null" main(a,b) int a; char *b[]; { struct stat buf; FILE *fopen(), *fp; if(stat(FILENAME,&buf)){ if ( (fp=fopen(DEVNULL,"a")) == NULL ) { /* or use perror() */ (void)fprintf (stderr, "%s: Can not open /dev/null file\n",b[0]); exit(-1); } } else if ( (fp=fopen(FILENAME,"a")) == NULL ) { (void)fprintf (stderr, "%s: Can not open %sfile\n",b[0],FILENAME); exit(-1); } /* go on writing to filepointer fp */ } ------------------------------------------------------------ ARPA: drears@ardec-ac4.arpa UUCP: ...!uunet!ardec-ac4.arpa!drears AT&T: 201-724-6639 Snailmail: Box 210, Wharton, NJ 07885 Govt Nonmail: US Army ARDEC, ATTN SMCAR-FSS-E, Dennis Rears Bldg 94, Picatinny Arsenal, NJ 07806 Flames: /dev/null ------------------------------------------------------------