Ok, here's try two.  Platform specific stuff has been moved into
config/gen/platform, and non-win32 platforms use strerror_r directly.

On Fri Nov 23 01:29:35 2007, kjs wrote:
> On Nov 22, 2007 9:03 PM, Joe Sadusk via RT
> <[EMAIL PROTECTED]> wrote:
> > Reposting this because this is my first patch, and it didn't occur to me
> > that if I don't CC perl6-internals, no one would notice it.
> >
> > It turns out that strerror_r is POSIX only, and windows has the slightly
> > different strerror_s (exactly the same except the arguments are in a
> > different order). I defined a macro that abstracts this, but I don't
> > know if there's a standard header file cross platform macros like this
> > are put in, so I put it inline in the pmc. If anyone has a suggestion of
> > where this belongs, I'll gladly move it.
> 
> I'm no expert on this, but in config/gen/platform, there are
> subdirectories that contain files that do platform dependent stuff.
> (I only know this because I once added
> config/gen/platform/win32/string.h, which defines a macro for strdup
> for MSVC users.)
> 
> I suspect that your macro should go in a similar file, but this should
> be confirmed by someone with more knowledge on this.
> 
> kjs
> 



diff --git a/config/gen/platform/generic/string.h b/config/gen/platform/generic/string.h
new file mode 100644
index 0000000..8de1ca1
--- /dev/null
+++ b/config/gen/platform/generic/string.h
@@ -0,0 +1,22 @@
+/*
+ * $Id$
+ * Copyright (C) 2004-2007, The Perl Foundation.
+ */
+
+#ifndef PARROT_PLATFORM_GENERIC_STRING_H_GUARD
+#define PARROT_PLATFORM_GENERIC_STRING_H_GUARD
+
+#if defined __GLIBC__
+#  define _XOPEN_SOURCE 600
+#endif
+
+#include <string.h>
+
+#endif /* PARROT_PLATFORM_GENERIC_STRING_H_GUARD */
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
diff --git a/config/gen/platform/win32/string.h b/config/gen/platform/win32/string.h
index 607745a..bd47db3 100644
--- a/config/gen/platform/win32/string.h
+++ b/config/gen/platform/win32/string.h
@@ -14,6 +14,8 @@
 #  endif
 #endif
 
+#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+
 #endif /* PARROT_PLATFORM_WIN32_STRING_H_GUARD */
 
 /*
diff --git a/src/pmc/file.pmc b/src/pmc/file.pmc
index 3c8d801..56be62d 100644
--- a/src/pmc/file.pmc
+++ b/src/pmc/file.pmc
@@ -27,6 +27,13 @@ C<File> is a singleton class which provides access to File functions.
 /* RT#46679 Check if we need to deallocate strerror strings */
 /* RT#46681 apparently, strerror_r is thread-safe and should be used instead.*/
 
+/* strerror_r should truncate the message if its too long for the supplied buffer
+ * its probably best to just specify a sane default buffer size than to worry
+ * about retrying calls
+ */
+#define ERRBUF_SIZE 128
+
+
 static PMC *File_PMC;
 pmclass File singleton {
 
@@ -98,7 +105,8 @@ Returns a true value (1) if the supplied path is a directory.
         string_cstring_free(cpath);
 
         if (error) {
-            char *errmsg = strerror(errno);
+            char errmsg[ERRBUF_SIZE];
+            strerror_r(errno, errmsg, ERRBUF_SIZE);
             real_exception(interp, NULL, E_SystemError, errmsg);
         }
 
@@ -129,7 +137,8 @@ Returns a true value (1) if the supplied path is a plain file.
         string_cstring_free(cpath);
 
         if (error) {
-            char *errmsg = strerror(errno);
+            char errmsg[ERRBUF_SIZE];
+            strerror_r(errno, errmsg, ERRBUF_SIZE);
             real_exception(interp, NULL, E_SystemError, errmsg);
         }
 
@@ -162,7 +171,8 @@ Returns a true value (1) if the supplied path is a link.
         string_cstring_free(cpath);
 
         if (error) {
-            char *errmsg = strerror(errno);
+            char errmsg[ERRBUF_SIZE];
+            strerror_r(errno, errmsg, ERRBUF_SIZE);
             real_exception(interp, NULL, E_SystemError, errmsg);
         }
 
@@ -197,6 +207,8 @@ free to change or give me hints on how to change it. -- ambs
 
         FILE *source = fopen(cfrom, "rb");
 
+        char errmsg[ERRBUF_SIZE];
+
         if (source) {
             FILE *target = fopen(cto, "w+b");
 
@@ -218,13 +230,13 @@ free to change or give me hints on how to change it. -- ambs
                 fclose(target);
             }
             else {
-                char *errmsg = strerror(errno);
+                strerror_r(errno, errmsg, ERRBUF_SIZE);
                 real_exception(interp, NULL, E_SystemError, errmsg);
             }
             fclose(source);
         }
         else {
-            char *errmsg = strerror(errno);
+            strerror_r(errno, errmsg, ERRBUF_SIZE);
             real_exception(interp, NULL, E_SystemError, errmsg);
         }
         string_cstring_free(cfrom);
@@ -251,7 +263,8 @@ Rename a file C<from> to the path C<to>.
         string_cstring_free(cto);
 
         if (error) {
-            char *errmsg = strerror(errno);
+            char errmsg[ERRBUF_SIZE];
+            strerror_r(errno, errmsg, ERRBUF_SIZE);
             real_exception(interp, NULL, E_SystemError, errmsg);
         }
     }

Reply via email to