This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[perl5.git] / util.c
diff --git a/util.c b/util.c
index 4642031..5336ad0 100644 (file)
--- a/util.c
+++ b/util.c
@@ -883,18 +883,21 @@ Perl_ibcmp_locale(pTHX_ const char *s1, const char *s2, register I32 len)
 
 =for apidoc savepv
 
-Copy a string to a safe spot.  This does not use an SV.
+Perl's version of C<strdup()>. Returns a pointer to a newly allocated
+string which is a duplicate of C<pv>. The size of the string is
+determined by C<strlen()>. The memory allocated for the new string can
+be freed with the C<Safefree()> function.
 
 =cut
 */
 
 char *
-Perl_savepv(pTHX_ const char *sv)
+Perl_savepv(pTHX_ const char *pv)
 {
     register char *newaddr = Nullch;
-    if (sv) {
-       New(902,newaddr,strlen(sv)+1,char);
-       (void)strcpy(newaddr,sv);
+    if (pv) {
+       New(902,newaddr,strlen(pv)+1,char);
+       (void)strcpy(newaddr,pv);
     }
     return newaddr;
 }
@@ -904,22 +907,23 @@ Perl_savepv(pTHX_ const char *sv)
 /*
 =for apidoc savepvn
 
-Copy a string to a safe spot.  The C<len> indicates number of bytes to
-copy. If pointer is NULL allocate space for a string of size specified.
-This does not use an SV.
+Perl's version of what C<strndup()> would be if it existed. Returns a
+pointer to a newly allocated string which is a duplicate of the first
+C<len> bytes from C<pv>. The memory allocated for the new string can be
+freed with the C<Safefree()> function.
 
 =cut
 */
 
 char *
-Perl_savepvn(pTHX_ const char *sv, register I32 len)
+Perl_savepvn(pTHX_ const char *pv, register I32 len)
 {
     register char *newaddr;
 
     New(903,newaddr,len+1,char);
     /* Give a meaning to NULL pointer mainly for the use in sv_magic() */
-    if (sv) {
-       Copy(sv,newaddr,len,char);      /* might not be null terminated */
+    if (pv) {
+       Copy(pv,newaddr,len,char);      /* might not be null terminated */
        newaddr[len] = '\0';            /* is now */
     }
     else {
@@ -931,18 +935,18 @@ Perl_savepvn(pTHX_ const char *sv, register I32 len)
 /*
 =for apidoc savesharedpv
 
-Copy a string to a safe spot in memory shared between threads.
-This does not use an SV.
+A version of C<savepv()> which allocates the duplicate string in memory
+which is shared between threads.
 
 =cut
 */
 char *
-Perl_savesharedpv(pTHX_ const char *sv)
+Perl_savesharedpv(pTHX_ const char *pv)
 {
     register char *newaddr = Nullch;
-    if (sv) {
-       newaddr = (char*)PerlMemShared_malloc(strlen(sv)+1);
-       (void)strcpy(newaddr,sv);
+    if (pv) {
+       newaddr = (char*)PerlMemShared_malloc(strlen(pv)+1);
+       (void)strcpy(newaddr,pv);
     }
     return newaddr;
 }
@@ -2275,7 +2279,7 @@ void
 Perl_dump_fds(pTHX_ char *s)
 {
     int fd;
-    struct stat tmpstatbuf;
+    Stat_t tmpstatbuf;
 
     PerlIO_printf(Perl_debug_log,"%s", s);
     for (fd = 0; fd < 32; fd++) {
@@ -2636,8 +2640,8 @@ Perl_same_dirent(pTHX_ char *a, char *b)
 {
     char *fa = strrchr(a,'/');
     char *fb = strrchr(b,'/');
-    struct stat tmpstatbuf1;
-    struct stat tmpstatbuf2;
+    Stat_t tmpstatbuf1;
+    Stat_t tmpstatbuf2;
     SV *tmpsv = sv_newmortal();
 
     if (fa)
@@ -3859,7 +3863,7 @@ Perl_getcwd_sv(pTHX_ register SV *sv)
 
 #else
 
-    struct stat statbuf;
+    Stat_t statbuf;
     int orig_cdev, orig_cino, cdev, cino, odev, oino, tdev, tino;
     int namelen, pathlen=0;
     DIR *dir;