delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/23/17:35:05

From: Marco DOT Monteiro AT delorie DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: file_exists()
Date: Fri, 22 Aug 1997 20:09:11 GMT
Lines: 24
Message-ID: <33fdf19a.5293195@news.telepac.pt>
NNTP-Posting-Host: 194.65.174.113
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello,

	how can i inspect if a file exists?
	I'm using the function following function; is there a better one?

/* returns 1 if file exists and 0 otherwise */
int file_exists(char *name)
{
   FILE *fp;
   int v = 0;

   if ((fp = fopen(name, "rb")) != NULL) {        /* if file opens */
      if (fclose(fp) != 0) {                      /* close file */
         printf("ed: error handling %s\n", name); /* can't close file
*/
         exit(2);                                 /* bye */
      }                                           /* file closed */
      v = 1;                                      /* file exists
(return 1) */
   }
   return v;                                      /* end */
}

Marco Monteiro
 back to a simtel site and try
getting at least the latest binutils, that is 
where 'as' comes from.

Andrew

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019