[svn:parrot] r36542 - in trunk: src/io tools/dev

NotFound at svn.parrot.org NotFound at svn.parrot.org
Tue Feb 10 16:14:05 UTC 2009


Author: NotFound
Date: Tue Feb 10 16:14:03 2009
New Revision: 36542
URL: https://trac.parrot.org/parrot/changeset/36542

Log:
[io] report close errors back to callers, TT #297

Modified:
   trunk/src/io/portable.c
   trunk/src/io/unix.c
   trunk/src/io/win32.c
   trunk/tools/dev/pbc_to_exe.pir

Modified: trunk/src/io/portable.c
==============================================================================
--- trunk/src/io/portable.c	Tue Feb 10 16:02:47 2009	(r36541)
+++ trunk/src/io/portable.c	Tue Feb 10 16:14:03 2009	(r36542)
@@ -224,14 +224,17 @@
 Parrot_io_close_portable(PARROT_INTERP, ARGMOD(PMC *filehandle))
 {
     ASSERT_ARGS(Parrot_io_close_portable)
+    INTVAL result = 0;
     FILE * const fptr = (FILE *)Parrot_io_get_os_handle(interp, filehandle);
 
-    if (fptr)
-        fclose(fptr);
+    if (fptr) {
+        if (fclose(fptr) != 0)
+            result = errno;
+    }
 
     Parrot_io_set_os_handle(interp, filehandle, (PIOHANDLE)NULL);
 
-    return 0;
+    return result;
 }
 
 

Modified: trunk/src/io/unix.c
==============================================================================
--- trunk/src/io/unix.c	Tue Feb 10 16:02:47 2009	(r36541)
+++ trunk/src/io/unix.c	Tue Feb 10 16:14:03 2009	(r36542)
@@ -331,14 +331,16 @@
 Parrot_io_close_unix(PARROT_INTERP, ARGMOD(PMC *filehandle))
 {
     ASSERT_ARGS(Parrot_io_close_unix)
+    INTVAL result = 0;
     PIOHANDLE file_descriptor = Parrot_io_get_os_handle(interp, filehandle);
     /* BSD and Solaris need explicit fsync() */
     if (file_descriptor >= 0) {
         fsync(file_descriptor);
-        close(file_descriptor);
+        if (close(file_descriptor) != 0)
+            result = errno;
     }
     Parrot_io_set_os_handle(interp, filehandle, -1);
-    return 0;
+    return result;
 }
 
 /*

Modified: trunk/src/io/win32.c
==============================================================================
--- trunk/src/io/win32.c	Tue Feb 10 16:02:47 2009	(r36541)
+++ trunk/src/io/win32.c	Tue Feb 10 16:14:03 2009	(r36542)
@@ -301,9 +301,11 @@
 Parrot_io_close_win32(PARROT_INTERP, ARGMOD(PMC *filehandle))
 {
     ASSERT_ARGS(Parrot_io_close_win32)
+    UINTVAL result = 0;
     PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, filehandle);
     if (os_handle != INVALID_HANDLE_VALUE) {
-        CloseHandle(os_handle);
+        if (CloseHandle(os_handle) == 0)
+            result = GetLastError ();
         Parrot_io_set_os_handle(interp, filehandle, INVALID_HANDLE_VALUE);
     }
     return 0;

Modified: trunk/tools/dev/pbc_to_exe.pir
==============================================================================
--- trunk/tools/dev/pbc_to_exe.pir	Tue Feb 10 16:02:47 2009	(r36541)
+++ trunk/tools/dev/pbc_to_exe.pir	Tue Feb 10 16:14:03 2009	(r36542)
@@ -25,6 +25,7 @@
     .local string objfile
     .local string exefile
     .local string out
+    .local int    closeresult
 
     (infile, cfile, objfile, exefile) = 'handle_args'(argv)
     unless infile > '' goto err_infile
@@ -77,7 +78,11 @@
         }
 MAIN
 
-    close outfh
+    # The close opcode does not return a result code,
+    # use the method instead.
+    closeresult = outfh.'close'()
+    unless closeresult == 0 goto err_close
+
     'compile_file'(cfile, objfile)
     'link_file'(objfile, exefile)
     .return ()
@@ -86,6 +91,8 @@
     die "cannot read infile"
   err_outfh:
     die "cannot write outfile"
+  err_close:
+    die "cannot close outfile"
 .end
 
 


More information about the parrot-commits mailing list