Ticket #297: close.patch

File close.patch, 2.8 KB (added by NotFound, 13 years ago)
  • src/io/win32.c

     
    301301Parrot_io_close_win32(PARROT_INTERP, ARGMOD(PMC *filehandle)) 
    302302{ 
    303303    ASSERT_ARGS(Parrot_io_close_win32) 
     304    UINTVAL result = 0; 
    304305    PIOHANDLE os_handle = Parrot_io_get_os_handle(interp, filehandle); 
    305306    if (os_handle != INVALID_HANDLE_VALUE) { 
    306         CloseHandle(os_handle); 
     307        if (CloseHandle(os_handle) == 0) 
     308            result = GetLastError (); 
    307309        Parrot_io_set_os_handle(interp, filehandle, INVALID_HANDLE_VALUE); 
    308310    } 
    309311    return 0; 
  • src/io/unix.c

     
    331331Parrot_io_close_unix(PARROT_INTERP, ARGMOD(PMC *filehandle)) 
    332332{ 
    333333    ASSERT_ARGS(Parrot_io_close_unix) 
     334    INTVAL result = 0; 
    334335    PIOHANDLE file_descriptor = Parrot_io_get_os_handle(interp, filehandle); 
    335336    /* BSD and Solaris need explicit fsync() */ 
    336337    if (file_descriptor >= 0) { 
    337338        fsync(file_descriptor); 
    338         close(file_descriptor); 
     339        if (close(file_descriptor) != 0) 
     340            result = errno; 
    339341    } 
    340342    Parrot_io_set_os_handle(interp, filehandle, -1); 
    341     return 0; 
     343    return result; 
    342344} 
    343345 
    344346/* 
  • src/io/portable.c

     
    224224Parrot_io_close_portable(PARROT_INTERP, ARGMOD(PMC *filehandle)) 
    225225{ 
    226226    ASSERT_ARGS(Parrot_io_close_portable) 
     227    INTVAL result = 0; 
    227228    FILE * const fptr = (FILE *)Parrot_io_get_os_handle(interp, filehandle); 
    228229 
    229     if (fptr) 
    230         fclose(fptr); 
     230    if (fptr) { 
     231        if (fclose(fptr) != 0) 
     232            result = errno; 
     233    } 
    231234 
    232235    Parrot_io_set_os_handle(interp, filehandle, (PIOHANDLE)NULL); 
    233236 
    234     return 0; 
     237    return result; 
    235238} 
    236239 
    237240 
  • tools/dev/pbc_to_exe.pir

     
    2525    .local string objfile 
    2626    .local string exefile 
    2727    .local string out 
     28    .local int    closeresult 
    2829 
    2930    (infile, cfile, objfile, exefile) = 'handle_args'(argv) 
    3031    unless infile > '' goto err_infile 
     
    7778        } 
    7879MAIN 
    7980 
    80     close outfh 
     81    # The close opcode does not return a result code, 
     82    # use the method instead. 
     83    closeresult = outfh.'close'() 
     84    unless closeresult == 0 goto err_close 
     85 
    8186    'compile_file'(cfile, objfile) 
    8287    'link_file'(objfile, exefile) 
    8388    .return () 
     
    8691    die "cannot read infile" 
    8792  err_outfh: 
    8893    die "cannot write outfile" 
     94  err_close: 
     95    die "cannot close outfile" 
    8996.end 
    9097 
    9198