This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test the warnings.
[perl5.git] / caretx.c
index 184c7d0..9366bc4 100644 (file)
--- a/caretx.c
+++ b/caretx.c
@@ -9,7 +9,13 @@
  */
 
 /*
- *     TODO: Quote
+ *   'I do not know clearly,' said Frodo; 'but the path climbs, I think,
+ * up into the mountains on the northern side of that vale where the old
+ * city stands.  It goes up to a high cleft and so down to -- that which
+ * is beyond.'
+ *   'Do you know the name of that high pass?' said Faramir.
+ *
+ *     [p.691 of _The Lord of the Rings_, IV/xi: "The Forbidden Pool"]
  */
 
 /* This file contains a single function, set_caret_X, to set the $^X
 # include <mach-o/dyld.h>
 #endif
 
+/* Note: Functions in this file must not have bool parameters.  When
+   PERL_BOOL_AS_CHAR is #defined, mach-o/dyld.h overrides it in this file
+   by #including stdbool.h, so the function parameters here would conflict
+   with those in proto.h.
+*/
+
 void
 Perl_set_caret_X(pTHX) {
-    dVAR;
     GV* tmpgv = gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL, SVt_PV); /* $^X */
     if (tmpgv) {
         SV *const caret_x = GvSV(tmpgv);
@@ -88,7 +99,13 @@ Perl_set_caret_X(pTHX) {
         }
 #  elif defined(HAS_PROCSELFEXE)
         char buf[MAXPATHLEN];
-        int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
+        SSize_t len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1);
+        /* NOTE: if the length returned by readlink() is sizeof(buf) - 1,
+         * it is impossible to know whether the result was truncated. */
+
+        if (len != -1) {
+            buf[len] = '\0';
+        }
 
         /* On Playstation2 Linux V1.0 (kernel 2.2.1) readlink(/proc/self/exe)
            includes a spurious NUL which will cause $^X to fail in system
@@ -118,11 +135,5 @@ Perl_set_caret_X(pTHX) {
 }
 
 /*
- * Local variables:
- * c-indentation-style: bsd
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- *
  * ex: set ts=8 sts=4 sw=4 et:
  */