diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2004-12-22 08:46:21 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2004-12-22 08:46:21 +0000 |
commit | 56cf6df88be94735387b08ddb4d6153b4d344490 (patch) | |
tree | fba5ff693762a6a5a88e562f3cba0d850d6c4c36 /perl.c | |
parent | b7975bdd15a2f8cfdd39f81ddeda20aac688230d (diff) | |
download | perl-56cf6df88be94735387b08ddb4d6153b4d344490.tar.gz |
Move the definition of the S_procself_val() function before
the point where it's used
p4raw-id: //depot/perl@23668
Diffstat (limited to 'perl.c')
-rw-r--r-- | perl.c | 69 |
1 files changed, 34 insertions, 35 deletions
@@ -967,6 +967,40 @@ Perl_call_atexit(pTHX_ ATEXIT_t fn, void *ptr) ++PL_exitlistlen; } +#ifdef HAS_PROCSELFEXE +/* This is a function so that we don't hold on to MAXPATHLEN + bytes of stack longer than necessary + */ +STATIC void +S_procself_val(pTHX_ SV *sv, char *arg0) +{ + char buf[MAXPATHLEN]; + int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1); + + /* 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 + or backticks (this will prevent extensions from being built and + many tests from working). readlink is not meant to add a NUL. + Normal readlink works fine. + */ + if (len > 0 && buf[len-1] == '\0') { + len--; + } + + /* FreeBSD's implementation is acknowledged to be imperfect, sometimes + returning the text "unknown" from the readlink rather than the path + to the executable (or returning an error from the readlink). Any valid + path has a '/' in it somewhere, so use that to validate the result. + See http://www.freebsd.org/cgi/query-pr.cgi?pr=35703 + */ + if (len > 0 && memchr(buf, '/', len)) { + sv_setpvn(sv,buf,len); + } + else { + sv_setpv(sv,arg0); + } +} +#endif /* HAS_PROCSELFEXE */ STATIC void S_set_caret_X(pTHX) { @@ -4042,41 +4076,6 @@ Perl_init_argv_symbols(pTHX_ register int argc, register char **argv) } } -#ifdef HAS_PROCSELFEXE -/* This is a function so that we don't hold on to MAXPATHLEN - bytes of stack longer than necessary - */ -STATIC void -S_procself_val(pTHX_ SV *sv, char *arg0) -{ - char buf[MAXPATHLEN]; - int len = readlink(PROCSELFEXE_PATH, buf, sizeof(buf) - 1); - - /* 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 - or backticks (this will prevent extensions from being built and - many tests from working). readlink is not meant to add a NUL. - Normal readlink works fine. - */ - if (len > 0 && buf[len-1] == '\0') { - len--; - } - - /* FreeBSD's implementation is acknowledged to be imperfect, sometimes - returning the text "unknown" from the readlink rather than the path - to the executable (or returning an error from the readlink). Any valid - path has a '/' in it somewhere, so use that to validate the result. - See http://www.freebsd.org/cgi/query-pr.cgi?pr=35703 - */ - if (len > 0 && memchr(buf, '/', len)) { - sv_setpvn(sv,buf,len); - } - else { - sv_setpv(sv,arg0); - } -} -#endif /* HAS_PROCSELFEXE */ - STATIC void S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register char **env) { |