# New Ticket Created by Ron Blaschke # Please include the string: [perl #43438] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=43438 >
Attached patch steal the basic layout from F<config/gen/platform/generic/stat.c> and makes the F<t/pmc/io.t> "stat failed" test work. Changed Files: config/gen/platform/win32/stat.c t/pmc/io.t Tested on: Visual C++ 8.0 $ runtests t\pmc\io.t t\pmc\io......ok All tests successful. Test Summary Report ------------------- t\pmc\io.t (Wstat: 0 Tests: 45 Failed: 0) Tests skipped: 8 Files=1, Tests=45, 3 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 CPU) Visual C++ 7.1 $ runtests t\pmc\io.t t\pmc\io......ok All tests successful. Test Summary Report ------------------- t\pmc\io.t (Wstat: 0 Tests: 45 Failed: 0) Tests skipped: 8 Files=1, Tests=45, 3 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 CPU) MinGW GCC 3.4.2 $ runtests t\pmc\io.t t\pmc\io......ok All tests successful. Test Summary Report ------------------- t\pmc\io.t (Wstat: 0 Tests: 45 Failed: 0) Tests skipped: 8 Files=1, Tests=45, 6 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 CPU) Ron
Index: config/gen/platform/win32/stat.c =================================================================== --- config/gen/platform/win32/stat.c (revision 19421) +++ config/gen/platform/win32/stat.c (working copy) @@ -2,173 +2,145 @@ * File stat stuff */ +static INTVAL +stat_common(Interp *interpreter, struct _stat *statbuf, + INTVAL thing, int status) +{ + INTVAL result; + + if (thing == STAT_EXISTS) + return status == 0; + if (status == -1) { + const char *err = strerror(errno); + real_exception(interpreter, NULL, E_IOError, + "stat failed: %s", err); + } + + switch (thing) { + case STAT_FILESIZE: + result = statbuf->st_size; + break; + + case STAT_ISDIR: + result = S_ISDIR(statbuf->st_mode); + break; + + case STAT_ISDEV: + result = S_ISCHR(statbuf->st_mode) || S_ISBLK(statbuf->st_mode); + break; + + case STAT_CREATETIME: + result = -1; + break; + + case STAT_ACCESSTIME: + result = statbuf->st_atime; + break; + + case STAT_MODIFYTIME: + result = statbuf->st_mtime; + break; + + case STAT_CHANGETIME: + result = statbuf->st_ctime; + break; + + case STAT_BACKUPTIME: + result = -1; + break; + + case STAT_UID: + result = statbuf->st_uid; + break; + + case STAT_GID: + result = statbuf->st_gid; + break; + + case STAT_PLATFORM_DEV: + result = statbuf->st_dev; + break; + + case STAT_PLATFORM_INODE: + result = statbuf->st_ino; + break; + + case STAT_PLATFORM_MODE: + result = statbuf->st_mode; + break; + + case STAT_PLATFORM_NLINKS: + result = statbuf->st_nlink; + break; + + case STAT_PLATFORM_DEVTYPE: + result = statbuf->st_rdev; + break; + + case STAT_PLATFORM_BLOCKSIZE: + internal_exception(1, "STAT_PLATFORM_BLOCKSIZE not supported"); + break; + + case STAT_PLATFORM_BLOCKS: + internal_exception(1, "STAT_PLATFORM_BLOCKS not supported"); + break; + + default: + result = -1; + } + + return result; +} + PMC * Parrot_stat_file(Parrot_Interp interpreter, STRING *filename) { - return NULL; + return NULL; } PMC * Parrot_stat_info_pmc(Parrot_Interp interpreter, STRING *filename, INTVAL thing) { - return NULL; + return NULL; } INTVAL Parrot_stat_info_intval(Parrot_Interp interpreter, STRING *file, INTVAL thing) { - struct stat statbuf; - char *filename; - INTVAL result = -1; - int status; + struct _stat statbuf; + char *filename; + int status; - /* Get the name of the file as something we can use */ - filename = string_to_cstring(interpreter, file); + /* Get the name of the file as something we can use */ + filename = string_to_cstring(interpreter, file); - /* Everything needs the result of stat, so just go do it */ - status = stat(filename, &statbuf); - - switch (thing) { - case STAT_EXISTS: - result = (status == 0); - break; - case STAT_FILESIZE: - result = statbuf.st_size; - break; - case STAT_ISDIR: - result = S_ISDIR(statbuf.st_mode); - break; - case STAT_ISDEV: - result = S_ISCHR(statbuf.st_mode) || S_ISBLK(statbuf.st_mode); - break; - case STAT_CREATETIME: - result = -1; - break; - case STAT_ACCESSTIME: - result = statbuf.st_atime; - break; - case STAT_MODIFYTIME: - result = statbuf.st_mtime; - break; - case STAT_CHANGETIME: - result = statbuf.st_ctime; - break; - case STAT_BACKUPTIME: - result = -1; - break; - case STAT_UID: - result = statbuf.st_uid; - break; - case STAT_GID: - result = statbuf.st_gid; - break; - case STAT_PLATFORM_DEV: - result = statbuf.st_dev; - break; - case STAT_PLATFORM_INODE: - result = statbuf.st_ino; - break; - case STAT_PLATFORM_MODE: - result = statbuf.st_mode; - break; - case STAT_PLATFORM_NLINKS: - result = statbuf.st_nlink; - break; - case STAT_PLATFORM_DEVTYPE: - result = statbuf.st_rdev; - break; - case STAT_PLATFORM_BLOCKSIZE: - internal_exception(1, "STAT_PLATFORM_BLOCKSIZE not supported"); - break; - case STAT_PLATFORM_BLOCKS: - internal_exception(1, "STAT_PLATFORM_BLOCKS not supported"); - break; - } - - string_cstring_free(filename); - return result; + /* Everything needs the result of stat, so just go do it */ + status = _stat(filename, &statbuf); + string_cstring_free(filename); + return stat_common(interpreter, &statbuf, thing, status); } INTVAL Parrot_fstat_info_intval(Parrot_Interp interpreter, INTVAL file, INTVAL thing) { - struct stat statbuf; - INTVAL result = -1; - int status; + struct _stat statbuf; + int status; - /* Everything needs the result of stat, so just go do it */ - status = fstat(file, &statbuf); - - switch (thing) { - case STAT_EXISTS: - result = (status == 0); - break; - case STAT_FILESIZE: - result = statbuf.st_size; - break; - case STAT_ISDIR: - result = S_ISDIR(statbuf.st_mode); - break; - case STAT_ISDEV: - result = S_ISCHR(statbuf.st_mode) || S_ISBLK(statbuf.st_mode); - break; - case STAT_CREATETIME: - result = -1; - break; - case STAT_ACCESSTIME: - result = statbuf.st_atime; - break; - case STAT_MODIFYTIME: - result = statbuf.st_mtime; - break; - case STAT_CHANGETIME: - result = statbuf.st_ctime; - break; - case STAT_BACKUPTIME: - result = -1; - break; - case STAT_UID: - result = statbuf.st_uid; - break; - case STAT_GID: - result = statbuf.st_gid; - break; - case STAT_PLATFORM_DEV: - result = statbuf.st_dev; - break; - case STAT_PLATFORM_INODE: - result = statbuf.st_ino; - break; - case STAT_PLATFORM_MODE: - result = statbuf.st_mode; - break; - case STAT_PLATFORM_NLINKS: - result = statbuf.st_nlink; - break; - case STAT_PLATFORM_DEVTYPE: - result = statbuf.st_rdev; - break; - case STAT_PLATFORM_BLOCKSIZE: - internal_exception(1, "STAT_PLATFORM_BLOCKSIZE not supported"); - break; - case STAT_PLATFORM_BLOCKS: - internal_exception(1, "STAT_PLATFORM_BLOCKS not supported"); - break; - } - - return result; + /* Everything needs the result of stat, so just go do it */ + status = _fstat(file, &statbuf); + return stat_common(interpreter, &statbuf, thing, status); } FLOATVAL Parrot_stat_info_floatval(Parrot_Interp interpreter, STRING *filename, INTVAL thing) { - return -1; + return -1; } STRING * Parrot_stat_info_string(Parrot_Interp interpreter, STRING *filename, INTVAL thing) { - return NULL; + return NULL; } /* Index: t/pmc/io.t =================================================================== --- t/pmc/io.t (revision 19421) +++ t/pmc/io.t (working copy) @@ -900,10 +900,7 @@ OUTPUT unlink("temp.file"); -SKIP: { - skip 'broken on windows', 1 if $^O eq 'MSWin32'; - - pir_error_output_like( <<'CODE', <<"OUTPUT", "stat failed" ); +pir_error_output_like( <<'CODE', <<"OUTPUT", "stat failed" ); .sub main :main .local pmc pio .local int len @@ -916,7 +913,6 @@ CODE /stat failed:/ OUTPUT -} # Local Variables: # mode: cperl