[m-rev.] diff: make mkinit.c more portable
Mark Anthony BROWN
dougl at cs.mu.OZ.AU
Tue Apr 10 02:37:10 AEST 2001
Estimated hours taken: 0.1
Branches: main, release
util/mkinit.c:
Test for the existence of files in a more portable way.
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.73
diff -u -r1.73 mkinit.c
--- util/mkinit.c 2001/04/08 13:21:41 1.73
+++ util/mkinit.c 2001/04/09 16:32:03
@@ -23,14 +23,18 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
-#include <sys/stat.h>
+#include "mercury_conf.h"
+
+#ifdef HAVE_SYS_STAT_H
+ #include <sys/stat.h>
+#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "getopt.h"
-#include "mercury_conf.h"
#include "mercury_std.h"
/* --- adjustable limits --- */
@@ -496,15 +500,23 @@
/*
** Check whether a file exists.
- ** At some point in the future it may be worth making this
- ** implementation more portable.
*/
static bool
file_exists(const char *filename)
{
+#ifdef HAVE_SYS_STAT_H
struct stat buf;
return (stat(filename, &buf) == 0);
+#else
+ FILE *f = fopen(filename, "rb");
+ if (f != NULL) {
+ fclose(f);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+#endif
}
/*---------------------------------------------------------------------------*/
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list