3 * Copyright (c) 1991-1994, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Very useful, no doubt, that was to Saruman; yet it seems that he was
12 * not content." --Gandalf
18 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
22 /* Omit this -- it causes too much grief on mixed systems.
32 /* Put this after #includes because fork and vfork prototypes may
43 # include <sys/file.h>
49 static void xstat _((void));
54 /* paranoid version of malloc */
56 /* NOTE: Do not call the next three routines directly. Use the macros
57 * in handy.h, so that we can easily redefine everything to do tracking of
58 * allocated hunks back to the original New to track down any memory leaks.
72 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
78 croak("panic: malloc");
80 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
81 #if !(defined(I286) || defined(atarist))
82 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
84 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
91 fputs(no_mem,stderr) FLUSH;
97 /* paranoid version of realloc */
100 saferealloc(where,size)
109 #if !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE)
111 #endif /* !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) */
115 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
120 croak("Null realloc");
123 croak("panic: realloc");
125 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
127 #if !(defined(I286) || defined(atarist))
129 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
130 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
134 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
135 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
144 fputs(no_mem,stderr) FLUSH;
150 /* safe version of free */
156 #if !(defined(I286) || defined(atarist))
157 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
159 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
167 #endif /* !safemalloc */
171 #define ALIGN sizeof(long)
178 register char *where;
180 where = safemalloc(size + ALIGN);
184 return where + ALIGN;
188 safexrealloc(where,size)
192 register char *new = saferealloc(where - ALIGN, size + ALIGN);
205 x = where[0] + 100 * where[1];
215 for (i = 0; i < MAXXCOUNT; i++) {
216 if (xcount[i] > lastxcount[i]) {
217 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
218 lastxcount[i] = xcount[i];
223 #endif /* LEAKTEST */
225 /* copy a string up to some (non-backslashed) delimiter, if any */
228 cpytill(to,from,fromend,delim,retlen)
231 register char *fromend;
237 for (; from < fromend; from++,to++) {
239 if (from[1] == delim)
241 else if (from[1] == '\\')
244 else if (*from == delim)
249 *retlen = to - origto;
253 /* return ptr to little string in big string, NULL if not found */
254 /* This routine was donated by Corey Satten. */
259 register char *little;
261 register char *s, *x;
272 for (x=big,s=little; *s; /**/ ) {
286 /* same as instr but allow embedded nulls */
289 ninstr(big, bigend, little, lend)
291 register char *bigend;
295 register char *s, *x;
296 register I32 first = *little;
297 register char *littleend = lend;
299 if (!first && little >= littleend)
301 if (bigend - big < littleend - little)
303 bigend -= littleend - little++;
304 while (big <= bigend) {
307 for (x=big,s=little; s < littleend; /**/ ) {
319 /* reverse of the above--find last substring */
322 rninstr(big, bigend, little, lend)
328 register char *bigbeg;
329 register char *s, *x;
330 register I32 first = *little;
331 register char *littleend = lend;
333 if (!first && little >= littleend)
336 big = bigend - (littleend - little++);
337 while (big >= bigbeg) {
340 for (x=big+2,s=little; s < littleend; /**/ ) {
353 fbm_compile(sv, iflag)
357 register unsigned char *s;
358 register unsigned char *table;
360 register U32 len = SvCUR(sv);
365 return; /* can't have offsets that big */
367 table = (unsigned char*)(SvPVX(sv) + len + 1);
369 for (i = 0; i < 256; i++) {
373 while (s >= (unsigned char*)(SvPVX(sv)))
375 if (table[*s] == len) {
378 table[*s] = table[fold[*s]] = i;
392 sv_upgrade(sv, SVt_PVBM);
393 sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
396 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
398 register U32 tmp, foldtmp;
400 for (i = 0; i < len; i++) {
402 foldtmp=freq[fold[s[i]]];
403 if (tmp < frequency && foldtmp < frequency) {
405 /* choose most frequent among the two */
406 frequency = (tmp > foldtmp) ? tmp : foldtmp;
411 for (i = 0; i < len; i++) {
412 if (freq[s[i]] < frequency) {
414 frequency = freq[s[i]];
418 BmRARE(sv) = s[rarest];
419 BmPREVIOUS(sv) = rarest;
420 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
424 fbm_instr(big, bigend, littlestr)
426 register unsigned char *bigend;
429 register unsigned char *s;
431 register I32 littlelen;
432 register unsigned char *little;
433 register unsigned char *table;
434 register unsigned char *olds;
435 register unsigned char *oldlittle;
437 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
439 char *l = SvPV(littlestr,len);
442 return ninstr((char*)big,(char*)bigend, l, l + len);
445 littlelen = SvCUR(littlestr);
446 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
447 if (littlelen > bigend - big)
449 little = (unsigned char*)SvPVX(littlestr);
450 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
451 big = bigend - littlelen; /* just start near end */
452 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
456 s = bigend - littlelen;
457 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
458 return (char*)s; /* how sweet it is */
459 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
462 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
468 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
469 if (--littlelen >= bigend - big)
472 oldlittle = little = table - 2;
473 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
477 if (tmp = table[*s]) {
479 if (bigend - s > tmp) {
484 if ((s += tmp) < bigend)
490 tmp = littlelen; /* less expensive than calling strncmp() */
493 if (*--s == *--little || fold[*s] == *little)
495 s = olds + 1; /* here we pay the price for failure */
497 if (s < bigend) /* fake up continue to outer loop */
509 if (tmp = table[*s]) {
511 if (bigend - s > tmp) {
516 if ((s += tmp) < bigend)
522 tmp = littlelen; /* less expensive than calling strncmp() */
525 if (*--s == *--little)
527 s = olds + 1; /* here we pay the price for failure */
529 if (s < bigend) /* fake up continue to outer loop */
541 screaminstr(bigstr, littlestr)
545 register unsigned char *s, *x;
546 register unsigned char *big;
548 register I32 previous;
550 register unsigned char *little;
551 register unsigned char *bigend;
552 register unsigned char *littleend;
554 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
556 little = (unsigned char *)(SvPVX(littlestr));
557 littleend = little + SvCUR(littlestr);
559 previous = BmPREVIOUS(littlestr);
560 big = (unsigned char *)(SvPVX(bigstr));
561 bigend = big + SvCUR(bigstr);
562 while (pos < previous) {
563 if (!(pos += screamnext[pos]))
567 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
569 if (big[pos-previous] != first && big[pos-previous] != fold[first])
571 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
574 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
580 return (char *)(big+pos-previous);
582 pos += screamnext[pos] /* does this goof up anywhere? */
587 if (big[pos-previous] != first)
589 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
598 return (char *)(big+pos-previous);
599 } while ( pos += screamnext[pos] );
601 #else /* !POINTERRIGOR */
603 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
605 if (big[pos] != first && big[pos] != fold[first])
607 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
610 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
616 return (char *)(big+pos);
618 pos += screamnext[pos] /* does this goof up anywhere? */
623 if (big[pos] != first)
625 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
634 return (char *)(big+pos);
636 pos += screamnext[pos]
639 #endif /* POINTERRIGOR */
654 if (fold[*a++] == *b++)
661 /* copy a string to a safe spot */
667 register char *newaddr;
669 New(902,newaddr,strlen(sv)+1,char);
670 (void)strcpy(newaddr,sv);
674 /* same thing but with a known length */
681 register char *newaddr;
683 New(903,newaddr,len+1,char);
684 Copy(sv,newaddr,len,char); /* might not be null terminated */
685 newaddr[len] = '\0'; /* is now */
689 #if !defined(I_STDARG) && !defined(I_VARARGS)
692 * Fallback on the old hackers way of doing varargs
697 mess(pat,a1,a2,a3,a4)
702 I32 usermess = strEQ(pat,"%s");
707 tmpstr = sv_newmortal();
708 sv_setpv(tmpstr, (char*)a1);
709 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
712 (void)sprintf(s,pat,a1,a2,a3,a4);
718 strcpy(s, " during global destruction.\n");
720 if (curcop->cop_line) {
721 (void)sprintf(s," at %s line %ld",
722 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
725 if (GvIO(last_in_gv) &&
726 IoLINES(GvIOp(last_in_gv)) ) {
727 (void)sprintf(s,", <%s> %s %ld",
728 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
729 strEQ(rs,"\n") ? "line" : "chunk",
730 (long)IoLINES(GvIOp(last_in_gv)));
733 (void)strcpy(s,".\n");
736 sv_catpv(tmpstr,buf+1);
739 return SvPVX(tmpstr);
745 void croak(pat,a1,a2,a3,a4)
755 message = mess(pat,a1,a2,a3,a4);
756 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
761 PUSHs(sv_2mortal(newSVpv(message,0)));
763 perl_call_sv((SV*)cv, G_DISCARD);
766 restartop = die_where(message);
769 fputs(message,stderr);
770 (void)fflush(stderr);
772 (void)UNLINK(e_tmpname);
773 statusvalue = SHIFTSTATUS(statusvalue);
775 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
777 my_exit((U32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
782 void warn(pat,a1,a2,a3,a4)
792 message = mess(pat,a1,a2,a3,a4);
793 if (warnhook && (cv = sv_2cv(warnhook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
798 PUSHs(sv_2mortal(newSVpv(message,0)));
800 perl_call_sv((SV*)cv, G_DISCARD);
803 fputs(message,stderr);
807 (void)fflush(stderr);
811 #else /* !defined(I_STDARG) && !defined(I_VARARGS) */
815 mess(char *pat, va_list *args)
828 #ifdef USE_CHAR_VSPRINTF
836 usermess = strEQ(pat, "%s");
838 tmpstr = sv_newmortal();
839 sv_setpv(tmpstr, va_arg(*args, char *));
840 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
843 (void) vsprintf(s,pat,*args);
850 strcpy(s, " during global destruction.\n");
852 if (curcop->cop_line) {
853 (void)sprintf(s," at %s line %ld",
854 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
857 if (GvIO(last_in_gv) &&
858 IoLINES(GvIOp(last_in_gv)) ) {
859 (void)sprintf(s,", <%s> %s %ld",
860 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
861 strEQ(rs,"\n") ? "line" : "chunk",
862 (long)IoLINES(GvIOp(last_in_gv)));
865 (void)strcpy(s,".\n");
868 sv_catpv(tmpstr,buf+1);
872 return SvPVX(tmpstr);
879 croak(char* pat, ...)
899 message = mess(pat, &args);
901 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
906 PUSHs(sv_2mortal(newSVpv(message,0)));
908 perl_call_sv((SV*)cv, G_DISCARD);
911 restartop = die_where(message);
914 fputs(message,stderr);
915 (void)fflush(stderr);
917 (void)UNLINK(e_tmpname);
918 statusvalue = SHIFTSTATUS(statusvalue);
920 my_exit((U32)(vaxc$errno?vaxc$errno:(statusvalue?statusvalue:44)));
922 my_exit((U32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
947 message = mess(pat, &args);
950 if (warnhook && (cv = sv_2cv(warnhook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
955 PUSHs(sv_2mortal(newSVpv(message,0)));
957 perl_call_sv((SV*)cv, G_DISCARD);
960 fputs(message,stderr);
964 (void)fflush(stderr);
967 #endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
969 #ifndef VMS /* VMS' my_setenv() is in VMS.c */
974 register I32 i=setenv_getix(nam); /* where does it go? */
976 if (environ == origenviron) { /* need we copy environment? */
982 for (max = i; environ[max]; max++) ;
983 New(901,tmpenv, max+2, char*);
984 for (j=0; j<max; j++) /* copy environment */
985 tmpenv[j] = savepv(environ[j]);
986 tmpenv[max] = Nullch;
987 environ = tmpenv; /* tell exec where it is now */
991 environ[i] = environ[i+1];
996 if (!environ[i]) { /* does not exist yet */
997 Renew(environ, i+2, char*); /* just expand it a bit */
998 environ[i+1] = Nullch; /* make sure it's null terminated */
1001 Safefree(environ[i]);
1002 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
1004 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
1006 /* MS-DOS requires environment variable names to be in uppercase */
1007 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
1008 * some utilities and applications may break because they only look
1009 * for upper case strings. (Fixed strupr() bug here.)]
1011 strcpy(environ[i],nam); strupr(environ[i]);
1012 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
1020 register I32 i, len = strlen(nam);
1022 for (i = 0; environ[i]; i++) {
1023 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
1024 break; /* strnEQ must come first to avoid */
1025 } /* potential SEGV's */
1032 unlnk(f) /* unlink all versions of a file */
1037 for (i = 0; unlink(f) >= 0; i++) ;
1042 #if !defined(HAS_BCOPY) || !defined(HAS_SAFE_BCOPY)
1044 my_bcopy(from,to,len)
1045 register char *from;
1051 if (from - to >= 0) {
1059 *(--to) = *(--from);
1065 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1081 my_memcmp(s1,s2,len)
1082 register unsigned char *s1;
1083 register unsigned char *s2;
1089 if (tmp = *s1++ - *s2++)
1094 #endif /* HAS_MEMCMP */
1099 #ifdef USE_CHAR_VSPRINTF
1104 vsprintf(dest, pat, args)
1105 char *dest, *pat, *args;
1109 fakebuf._ptr = dest;
1110 fakebuf._cnt = 32767;
1114 fakebuf._flag = _IOWRT|_IOSTRG;
1115 _doprnt(pat, args, &fakebuf); /* what a kludge */
1116 (void)putc('\0', &fakebuf);
1117 #ifdef USE_CHAR_VSPRINTF
1120 return 0; /* perl doesn't use return value */
1125 vfprintf(fd, pat, args)
1129 _doprnt(pat, args, fd);
1130 return 0; /* wrong, but perl doesn't use the return value */
1132 #endif /* HAS_VPRINTF */
1133 #endif /* I_VARARGS */
1136 #if BYTEORDER != 0x4321
1138 #ifndef CAN_PROTOTYPE
1145 #if (BYTEORDER & 1) == 0
1148 result = ((s & 255) << 8) + ((s >> 8) & 255);
1156 #ifndef CAN_PROTOTYPE
1165 char c[sizeof(long)];
1168 #if BYTEORDER == 0x1234
1169 u.c[0] = (l >> 24) & 255;
1170 u.c[1] = (l >> 16) & 255;
1171 u.c[2] = (l >> 8) & 255;
1175 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1176 croak("Unknown BYTEORDER\n");
1181 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1182 u.c[o & 0xf] = (l >> s) & 255;
1190 #ifndef CAN_PROTOTYPE
1199 char c[sizeof(long)];
1202 #if BYTEORDER == 0x1234
1203 u.c[0] = (l >> 24) & 255;
1204 u.c[1] = (l >> 16) & 255;
1205 u.c[2] = (l >> 8) & 255;
1209 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1210 croak("Unknown BYTEORDER\n");
1217 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1218 l |= (u.c[o & 0xf] & 255) << s;
1225 #endif /* BYTEORDER != 0x4321 */
1229 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1230 * If these functions are defined,
1231 * the BYTEORDER is neither 0x1234 nor 0x4321.
1232 * However, this is not assumed.
1236 #define HTOV(name,type) \
1243 char c[sizeof(type)]; \
1247 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1248 u.c[i] = (n >> s) & 0xFF; \
1253 #define VTOH(name,type) \
1260 char c[sizeof(type)]; \
1266 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1267 n += (u.c[i] & 0xFF) << s; \
1272 #if defined(HAS_HTOVS) && !defined(htovs)
1275 #if defined(HAS_HTOVL) && !defined(htovl)
1278 #if defined(HAS_VTOHS) && !defined(vtohs)
1281 #if defined(HAS_VTOHL) && !defined(vtohl)
1285 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1292 register I32 this, that;
1295 I32 doexec = strNE(cmd,"-");
1299 this = (*mode == 'w');
1304 taint_proper("Insecure %s%s", "EXEC");
1307 while ((pid = (doexec?vfork():fork())) < 0) {
1308 if (errno != EAGAIN) {
1311 croak("Can't fork");
1322 if (p[THIS] != (*mode == 'r')) {
1323 dup2(p[THIS], *mode == 'r');
1327 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
1333 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1336 do_exec(cmd); /* may or may not use the shell */
1340 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
1341 sv_setiv(GvSV(tmpgv),(I32)getpid());
1343 hv_clear(pidstatus); /* we have no children */
1348 do_execfree(); /* free any memory malloced by child on vfork */
1350 if (p[that] < p[this]) {
1351 dup2(p[this], p[that]);
1355 sv = *av_fetch(fdpid,p[this],TRUE);
1356 (void)SvUPGRADE(sv,SVt_IV);
1359 return fdopen(p[this], mode);
1369 return popen(cmd, mode);
1373 #endif /* !DOSISH */
1380 struct stat tmpstatbuf;
1382 fprintf(stderr,"%s", s);
1383 for (fd = 0; fd < 32; fd++) {
1384 if (Fstat(fd,&tmpstatbuf) >= 0)
1385 fprintf(stderr," %d",fd);
1387 fprintf(stderr,"\n");
1397 #if defined(HAS_FCNTL) && defined(F_DUPFD)
1401 return fcntl(oldfd, F_DUPFD, newfd);
1410 while ((fd = dup(oldfd)) != newfd && fd >= 0) /* good enough for low fd's */
1413 close(fdtmp[--fdx]);
1420 #ifndef VMS /* VMS' my_pclose() is in VMS.c */
1425 Signal_t (*hstat)(), (*istat)(), (*qstat)();
1430 svp = av_fetch(fdpid,fileno(ptr),TRUE);
1431 pid = (int)SvIVX(*svp);
1436 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1438 hstat = signal(SIGHUP, SIG_IGN);
1439 istat = signal(SIGINT, SIG_IGN);
1440 qstat = signal(SIGQUIT, SIG_IGN);
1442 pid = wait4pid(pid, &status, 0);
1443 } while (pid == -1 && errno == EINTR);
1444 signal(SIGHUP, hstat);
1445 signal(SIGINT, istat);
1446 signal(SIGQUIT, qstat);
1447 return(pid < 0 ? pid : status);
1451 wait4pid(pid,statusp,flags)
1463 sprintf(spid, "%d", pid);
1464 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1465 if (svp && *svp != &sv_undef) {
1466 *statusp = SvIVX(*svp);
1467 (void)hv_delete(pidstatus,spid,strlen(spid),G_DISCARD);
1474 hv_iterinit(pidstatus);
1475 if (entry = hv_iternext(pidstatus)) {
1476 pid = atoi(hv_iterkey(entry,(I32*)statusp));
1477 sv = hv_iterval(pidstatus,entry);
1478 *statusp = SvIVX(sv);
1479 sprintf(spid, "%d", pid);
1480 (void)hv_delete(pidstatus,spid,strlen(spid),G_DISCARD);
1485 return waitpid(pid,statusp,flags);
1488 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1493 croak("Can't do waitpid with flags");
1495 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1496 pidgone(result,*statusp);
1505 #endif /* !DOSISH */
1516 sprintf(spid, "%d", pid);
1517 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1518 (void)SvUPGRADE(sv,SVt_IV);
1534 repeatcpy(to,from,len,count)
1536 register char *from;
1541 register char *frombase = from;
1549 while (count-- > 0) {
1550 for (todo = len; todo > 0; todo--) {
1557 #ifndef CASTNEGFLOAT
1565 # define BIGDOUBLE 2147483648.0
1567 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1570 return (unsigned long)f;
1572 return (unsigned long)along;
1582 # define BIGDOUBLE 2147483647.0 /* Assume 32 bit int's ! */
1583 # define BIGNEGDOUBLE (-2147483648.0)
1585 return (I32) BIGDOUBLE;
1586 if (f <= BIGNEGDOUBLE)
1587 return (I32) BIGNEGDOUBLE;
1591 # undef BIGNEGDOUBLE
1597 /* XXX This should be fixed. It assumes 32 bit IV's. */
1598 # define BIGDOUBLE 2147483647.0 /* Assume 32 bit IV's ! */
1599 # define BIGNEGDOUBLE (-2147483648.0)
1601 return (IV) BIGDOUBLE;
1602 if (f <= BIGNEGDOUBLE)
1603 return (IV) BIGNEGDOUBLE;
1607 # undef BIGNEGDOUBLE
1616 char *fa = strrchr(a,'/');
1617 char *fb = strrchr(b,'/');
1618 struct stat tmpstatbuf1;
1619 struct stat tmpstatbuf2;
1621 #define MAXPATHLEN 1024
1623 char tmpbuf[MAXPATHLEN+1];
1638 strncpy(tmpbuf, a, fa - a);
1639 if (Stat(tmpbuf, &tmpstatbuf1) < 0)
1644 strncpy(tmpbuf, b, fb - b);
1645 if (Stat(tmpbuf, &tmpstatbuf2) < 0)
1647 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1648 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1650 #endif /* !HAS_RENAME */
1653 scan_oct(start, len, retlen)
1658 register char *s = start;
1659 register unsigned long retval = 0;
1661 while (len && *s >= '0' && *s <= '7') {
1663 retval |= *s++ - '0';
1666 if (dowarn && len && (*s == '8' || *s == '9'))
1667 warn("Illegal octal digit ignored");
1668 *retlen = s - start;
1673 scan_hex(start, len, retlen)
1678 register char *s = start;
1679 register unsigned long retval = 0;
1682 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1684 retval |= (tmp - hexdigit) & 15;
1687 *retlen = s - start;