[MLton-commit] r4644

Matthew Fluet MLton@mlton.org
Mon, 12 Jun 2006 09:18:17 -0700


Typo in diskBack.unix.c
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/diskBack.unix.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/diskBack.unix.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/diskBack.unix.c	2006-06-11 07:54:45 UTC (rev 4643)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/diskBack.unix.c	2006-06-12 16:18:16 UTC (rev 4644)
@@ -17,7 +17,7 @@
   strcat (template, tag);
   m = umask(077);
   fd = mkstemp_safe (template);
-  f = fdopen(f, "w+");
+  f = fdopen_safe (fd, "w+");
   (void)umask(m);
   unlink_safe (template);
   free (template);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h	2006-06-11 07:54:45 UTC (rev 4643)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/util/safe.h	2006-06-12 16:18:16 UTC (rev 4644)
@@ -25,24 +25,15 @@
   return;
 }
 
-static inline void *malloc_safe (size_t size) {
-  void *res;
-  
-  res = malloc (size);
-  if (NULL == res)
-    die ("malloc (%zu) failed.\n", size);
+static inline FILE *fdopen_safe (int fd, const char *mode) {
+  FILE *res;
+
+  res = fdopen (fd, mode);
+  if (0 == res)
+    diee ("fopen (%d, %s) failed.\n", fd, mode);
   return res;
 }
 
-static inline int mkstemp_safe (char *template) {
-  int fd;
-  
-  fd = mkstemp (template);
-  if (-1 == fd)
-    diee ("mkstemp (%s) failed.\n", template);
-  return fd;
-}
-
 static inline FILE *fopen_safe (const char *fileName, const char *mode) {
   FILE *res;
 
@@ -61,6 +52,33 @@
           (long)size, (long)count, (long)res);
 }
 
+static inline void fwrite_safe (const void *buf, size_t size, size_t count, FILE *f) {
+  size_t res;
+
+  res = fwrite (buf, size, count, f);
+  if (res != count)
+      diee ("fwrite (_, %ld, %ld, _) failed (only wrote %ld).\n",
+            (long)size, (long)count, (long)res);
+}
+
+static inline void *malloc_safe (size_t size) {
+  void *res;
+  
+  res = malloc (size);
+  if (NULL == res)
+    die ("malloc (%zu) failed.\n", size);
+  return res;
+}
+
+static inline int mkstemp_safe (char *template) {
+  int fd;
+  
+  fd = mkstemp (template);
+  if (-1 == fd)
+    diee ("mkstemp (%s) failed.\n", template);
+  return fd;
+}
+
 static inline void unlink_safe (const char *pathname) {
   int res;
 
@@ -69,12 +87,3 @@
     diee ("unlink (%s) failed.\n", pathname);
   return;
 }
-
-static inline void fwrite_safe (const void *buf, size_t size, size_t count, FILE *f) {
-  size_t res;
-
-  res = fwrite (buf, size, count, f);
-  if (res != count)
-      diee ("fwrite (_, %ld, %ld, _) failed (only wrote %ld).\n",
-            (long)size, (long)count, (long)res);
-}