summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorDoug MacEachern <dougm@covalent.net>2001-06-21 12:32:05 -0700
committerJarkko Hietaniemi <jhi@iki.fi>2001-06-22 02:01:23 +0000
commit60e110a83edc19ea4be1b1b0a6f0914c60656856 (patch)
treee4b63d89efda83d85133fd44367bc02e7d957369 /util.c
parent64778e5fb295d7863aed7595c138348cf2333d4e (diff)
downloadperl-60e110a83edc19ea4be1b1b0a6f0914c60656856.tar.gz
Re: Automated smoke report for patch 10764 (truncated)
Message-ID: <Pine.LNX.4.21.0106211925020.17261-100000@mako.covalent.net> plus reword the getcwd() comment, plus use getcwd() buffer size minus one. p4raw-id: //depot/perl@10810
Diffstat (limited to 'util.c')
-rw-r--r--util.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/util.c b/util.c
index feef339893..aa8a84f2c5 100644
--- a/util.c
+++ b/util.c
@@ -3611,29 +3611,20 @@ Perl_sv_getcwd(pTHX_ register SV *sv)
#ifdef HAS_GETCWD
{
- char* buf;
-
- SvPOK_off(sv);
- New(0, buf, MAXPATHLEN, char);
- if (buf) {
- buf[MAXPATHLEN - 1] = 0;
- /* Yes, some getcwd()s automatically allocate a buffer
- * if given a NULL one. Portability is the problem.
- * XXX Configure probe needed. */
- if (getcwd(buf, MAXPATHLEN - 1)) {
- STRLEN len = strlen(buf);
- sv_setpvn(sv, buf, len);
- SvPOK_only(sv);
- SvCUR_set(sv, len);
- }
- else
- sv_setsv(sv, &PL_sv_undef);
- Safefree(buf);
- }
- else
- sv_setsv(sv, &PL_sv_undef);
-
- return SvPOK(sv) ? TRUE : FALSE;
+ char buf[MAXPATHLEN];
+
+ /* Some getcwd()s automatically allocate a buffer of the given
+ * size from the heap if they are given a NULL buffer pointer.
+ * The problem is that this behaviour is not portable. */
+ if (getcwd(buf, sizeof(buf) - 1)) {
+ STRLEN len = strlen(buf);
+ sv_setpvn(sv, buf, len);
+ return TRUE;
+ }
+ else {
+ sv_setsv(sv, &PL_sv_undef);
+ return FALSE;
+ }
}
#else
@@ -3727,12 +3718,14 @@ Perl_sv_getcwd(pTHX_ register SV *sv)
#endif
}
- SvCUR_set(sv, pathlen);
- *SvEND(sv) = '\0';
- SvPOK_only(sv);
+ if (pathlen) {
+ SvCUR_set(sv, pathlen);
+ *SvEND(sv) = '\0';
+ SvPOK_only(sv);
- if (PerlDir_chdir(SvPVX(sv)) < 0) {
- SV_CWD_RETURN_UNDEF;
+ hreif (PerlDir_chdir(SvPVX(sv)) < 0) {
+ SV_CWD_RETURN_UNDEF;
+ }
}
if (PerlLIO_stat(".", &statbuf) < 0) {
SV_CWD_RETURN_UNDEF;