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 #ifdef I_LIMITS /* Needed for cast_xxx() functions below. */
36 /* Put this after #includes because fork and vfork prototypes may
47 # include <sys/file.h>
53 static void xstat _((void));
58 /* paranoid version of malloc */
60 /* NOTE: Do not call the next three routines directly. Use the macros
61 * in handy.h, so that we can easily redefine everything to do tracking of
62 * allocated hunks back to the original New to track down any memory leaks.
76 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
82 croak("panic: malloc");
84 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
85 #if !(defined(I286) || defined(atarist))
86 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
88 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
95 fputs(no_mem,stderr) FLUSH;
101 /* paranoid version of realloc */
104 saferealloc(where,size)
113 #if !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE)
115 #endif /* !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) */
119 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
124 croak("Null realloc");
127 croak("panic: realloc");
129 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
131 #if !(defined(I286) || defined(atarist))
133 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
134 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
138 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
139 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
148 fputs(no_mem,stderr) FLUSH;
154 /* safe version of free */
160 #if !(defined(I286) || defined(atarist))
161 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
163 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
171 #endif /* !safemalloc */
175 #define ALIGN sizeof(long)
182 register char *where;
184 where = safemalloc(size + ALIGN);
188 return where + ALIGN;
192 safexrealloc(where,size)
196 register char *new = saferealloc(where - ALIGN, size + ALIGN);
209 x = where[0] + 100 * where[1];
219 for (i = 0; i < MAXXCOUNT; i++) {
220 if (xcount[i] > lastxcount[i]) {
221 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
222 lastxcount[i] = xcount[i];
227 #endif /* LEAKTEST */
229 /* copy a string up to some (non-backslashed) delimiter, if any */
232 cpytill(to,from,fromend,delim,retlen)
235 register char *fromend;
241 for (; from < fromend; from++,to++) {
243 if (from[1] == delim)
245 else if (from[1] == '\\')
248 else if (*from == delim)
253 *retlen = to - origto;
257 /* return ptr to little string in big string, NULL if not found */
258 /* This routine was donated by Corey Satten. */
263 register char *little;
265 register char *s, *x;
276 for (x=big,s=little; *s; /**/ ) {
290 /* same as instr but allow embedded nulls */
293 ninstr(big, bigend, little, lend)
295 register char *bigend;
299 register char *s, *x;
300 register I32 first = *little;
301 register char *littleend = lend;
303 if (!first && little >= littleend)
305 if (bigend - big < littleend - little)
307 bigend -= littleend - little++;
308 while (big <= bigend) {
311 for (x=big,s=little; s < littleend; /**/ ) {
323 /* reverse of the above--find last substring */
326 rninstr(big, bigend, little, lend)
332 register char *bigbeg;
333 register char *s, *x;
334 register I32 first = *little;
335 register char *littleend = lend;
337 if (!first && little >= littleend)
340 big = bigend - (littleend - little++);
341 while (big >= bigbeg) {
344 for (x=big+2,s=little; s < littleend; /**/ ) {
357 fbm_compile(sv, iflag)
361 register unsigned char *s;
362 register unsigned char *table;
364 register U32 len = SvCUR(sv);
369 return; /* can't have offsets that big */
371 table = (unsigned char*)(SvPVX(sv) + len + 1);
373 for (i = 0; i < 256; i++) {
377 while (s >= (unsigned char*)(SvPVX(sv)))
379 if (table[*s] == len) {
382 table[*s] = table[fold[*s]] = i;
396 sv_upgrade(sv, SVt_PVBM);
397 sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
400 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
402 register U32 tmp, foldtmp;
404 for (i = 0; i < len; i++) {
406 foldtmp=freq[fold[s[i]]];
407 if (tmp < frequency && foldtmp < frequency) {
409 /* choose most frequent among the two */
410 frequency = (tmp > foldtmp) ? tmp : foldtmp;
415 for (i = 0; i < len; i++) {
416 if (freq[s[i]] < frequency) {
418 frequency = freq[s[i]];
422 BmRARE(sv) = s[rarest];
423 BmPREVIOUS(sv) = rarest;
424 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
428 fbm_instr(big, bigend, littlestr)
430 register unsigned char *bigend;
433 register unsigned char *s;
435 register I32 littlelen;
436 register unsigned char *little;
437 register unsigned char *table;
438 register unsigned char *olds;
439 register unsigned char *oldlittle;
441 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
443 char *l = SvPV(littlestr,len);
446 return ninstr((char*)big,(char*)bigend, l, l + len);
449 littlelen = SvCUR(littlestr);
450 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
451 if (littlelen > bigend - big)
453 little = (unsigned char*)SvPVX(littlestr);
454 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
455 big = bigend - littlelen; /* just start near end */
456 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
460 s = bigend - littlelen;
461 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
462 return (char*)s; /* how sweet it is */
463 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
466 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
472 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
473 if (--littlelen >= bigend - big)
476 oldlittle = little = table - 2;
477 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
481 if (tmp = table[*s]) {
483 if (bigend - s > tmp) {
488 if ((s += tmp) < bigend)
494 tmp = littlelen; /* less expensive than calling strncmp() */
497 if (*--s == *--little || fold[*s] == *little)
499 s = olds + 1; /* here we pay the price for failure */
501 if (s < bigend) /* fake up continue to outer loop */
513 if (tmp = table[*s]) {
515 if (bigend - s > tmp) {
520 if ((s += tmp) < bigend)
526 tmp = littlelen; /* less expensive than calling strncmp() */
529 if (*--s == *--little)
531 s = olds + 1; /* here we pay the price for failure */
533 if (s < bigend) /* fake up continue to outer loop */
545 screaminstr(bigstr, littlestr)
549 register unsigned char *s, *x;
550 register unsigned char *big;
552 register I32 previous;
554 register unsigned char *little;
555 register unsigned char *bigend;
556 register unsigned char *littleend;
558 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
560 little = (unsigned char *)(SvPVX(littlestr));
561 littleend = little + SvCUR(littlestr);
563 previous = BmPREVIOUS(littlestr);
564 big = (unsigned char *)(SvPVX(bigstr));
565 bigend = big + SvCUR(bigstr);
566 while (pos < previous) {
567 if (!(pos += screamnext[pos]))
571 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
573 if (big[pos-previous] != first && big[pos-previous] != fold[first])
575 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
578 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
584 return (char *)(big+pos-previous);
586 pos += screamnext[pos] /* does this goof up anywhere? */
591 if (big[pos-previous] != first)
593 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
602 return (char *)(big+pos-previous);
603 } while ( pos += screamnext[pos] );
605 #else /* !POINTERRIGOR */
607 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
609 if (big[pos] != first && big[pos] != fold[first])
611 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
614 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
620 return (char *)(big+pos);
622 pos += screamnext[pos] /* does this goof up anywhere? */
627 if (big[pos] != first)
629 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
638 return (char *)(big+pos);
640 pos += screamnext[pos]
643 #endif /* POINTERRIGOR */
658 if (fold[*a++] == *b++)
665 /* copy a string to a safe spot */
671 register char *newaddr;
673 New(902,newaddr,strlen(sv)+1,char);
674 (void)strcpy(newaddr,sv);
678 /* same thing but with a known length */
685 register char *newaddr;
687 New(903,newaddr,len+1,char);
688 Copy(sv,newaddr,len,char); /* might not be null terminated */
689 newaddr[len] = '\0'; /* is now */
693 #if !defined(I_STDARG) && !defined(I_VARARGS)
696 * Fallback on the old hackers way of doing varargs
701 mess(pat,a1,a2,a3,a4)
706 I32 usermess = strEQ(pat,"%s");
711 tmpstr = sv_newmortal();
712 sv_setpv(tmpstr, (char*)a1);
713 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
716 (void)sprintf(s,pat,a1,a2,a3,a4);
722 strcpy(s, " during global destruction.\n");
724 if (curcop->cop_line) {
725 (void)sprintf(s," at %s line %ld",
726 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
729 if (GvIO(last_in_gv) &&
730 IoLINES(GvIOp(last_in_gv)) ) {
731 (void)sprintf(s,", <%s> %s %ld",
732 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
733 strEQ(rs,"\n") ? "line" : "chunk",
734 (long)IoLINES(GvIOp(last_in_gv)));
737 (void)strcpy(s,".\n");
740 sv_catpv(tmpstr,buf+1);
743 return SvPVX(tmpstr);
749 void croak(pat,a1,a2,a3,a4)
759 message = mess(pat,a1,a2,a3,a4);
760 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
765 PUSHs(sv_2mortal(newSVpv(message,0)));
767 perl_call_sv((SV*)cv, G_DISCARD);
770 restartop = die_where(message);
773 fputs(message,stderr);
774 (void)fflush(stderr);
776 (void)UNLINK(e_tmpname);
777 statusvalue = SHIFTSTATUS(statusvalue);
779 my_exit((U32)vaxc$errno?vaxc$errno:errno?errno:statusvalue?statusvalue:SS$_ABORT);
781 my_exit((U32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
786 void warn(pat,a1,a2,a3,a4)
796 message = mess(pat,a1,a2,a3,a4);
797 if (warnhook && (cv = sv_2cv(warnhook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
802 PUSHs(sv_2mortal(newSVpv(message,0)));
804 perl_call_sv((SV*)cv, G_DISCARD);
807 fputs(message,stderr);
811 (void)fflush(stderr);
815 #else /* !defined(I_STDARG) && !defined(I_VARARGS) */
819 mess(char *pat, va_list *args)
832 #ifdef USE_CHAR_VSPRINTF
840 usermess = strEQ(pat, "%s");
842 tmpstr = sv_newmortal();
843 sv_setpv(tmpstr, va_arg(*args, char *));
844 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
847 (void) vsprintf(s,pat,*args);
854 strcpy(s, " during global destruction.\n");
856 if (curcop->cop_line) {
857 (void)sprintf(s," at %s line %ld",
858 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
861 if (GvIO(last_in_gv) &&
862 IoLINES(GvIOp(last_in_gv)) ) {
863 (void)sprintf(s,", <%s> %s %ld",
864 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
865 strEQ(rs,"\n") ? "line" : "chunk",
866 (long)IoLINES(GvIOp(last_in_gv)));
869 (void)strcpy(s,".\n");
872 sv_catpv(tmpstr,buf+1);
876 return SvPVX(tmpstr);
883 croak(char* pat, ...)
903 message = mess(pat, &args);
905 if (diehook && (cv = sv_2cv(diehook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
910 PUSHs(sv_2mortal(newSVpv(message,0)));
912 perl_call_sv((SV*)cv, G_DISCARD);
915 restartop = die_where(message);
918 fputs(message,stderr);
919 (void)fflush(stderr);
921 (void)UNLINK(e_tmpname);
922 statusvalue = SHIFTSTATUS(statusvalue);
924 my_exit((U32)(vaxc$errno?vaxc$errno:(statusvalue?statusvalue:44)));
926 my_exit((U32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
951 message = mess(pat, &args);
954 if (warnhook && (cv = sv_2cv(warnhook, &stash, &gv, 0)) && !CvDEPTH(cv)) {
959 PUSHs(sv_2mortal(newSVpv(message,0)));
961 perl_call_sv((SV*)cv, G_DISCARD);
964 fputs(message,stderr);
968 (void)fflush(stderr);
971 #endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
973 #ifndef VMS /* VMS' my_setenv() is in VMS.c */
978 register I32 i=setenv_getix(nam); /* where does it go? */
980 if (environ == origenviron) { /* need we copy environment? */
986 for (max = i; environ[max]; max++) ;
987 New(901,tmpenv, max+2, char*);
988 for (j=0; j<max; j++) /* copy environment */
989 tmpenv[j] = savepv(environ[j]);
990 tmpenv[max] = Nullch;
991 environ = tmpenv; /* tell exec where it is now */
995 environ[i] = environ[i+1];
1000 if (!environ[i]) { /* does not exist yet */
1001 Renew(environ, i+2, char*); /* just expand it a bit */
1002 environ[i+1] = Nullch; /* make sure it's null terminated */
1005 Safefree(environ[i]);
1006 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
1008 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
1010 /* MS-DOS requires environment variable names to be in uppercase */
1011 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
1012 * some utilities and applications may break because they only look
1013 * for upper case strings. (Fixed strupr() bug here.)]
1015 strcpy(environ[i],nam); strupr(environ[i]);
1016 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
1024 register I32 i, len = strlen(nam);
1026 for (i = 0; environ[i]; i++) {
1027 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
1028 break; /* strnEQ must come first to avoid */
1029 } /* potential SEGV's */
1034 #ifdef UNLINK_ALL_VERSIONS
1036 unlnk(f) /* unlink all versions of a file */
1041 for (i = 0; unlink(f) >= 0; i++) ;
1046 #if !defined(HAS_BCOPY) || !defined(HAS_SAFE_BCOPY)
1048 my_bcopy(from,to,len)
1049 register char *from;
1055 if (from - to >= 0) {
1063 *(--to) = *(--from);
1069 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1085 my_memcmp(s1,s2,len)
1086 register unsigned char *s1;
1087 register unsigned char *s2;
1093 if (tmp = *s1++ - *s2++)
1098 #endif /* HAS_MEMCMP */
1100 #if defined(I_STDARG) || defined(I_VARARGS)
1103 #ifdef USE_CHAR_VSPRINTF
1108 vsprintf(dest, pat, args)
1109 char *dest, *pat, *args;
1113 fakebuf._ptr = dest;
1114 fakebuf._cnt = 32767;
1118 fakebuf._flag = _IOWRT|_IOSTRG;
1119 _doprnt(pat, args, &fakebuf); /* what a kludge */
1120 (void)putc('\0', &fakebuf);
1121 #ifdef USE_CHAR_VSPRINTF
1124 return 0; /* perl doesn't use return value */
1129 vfprintf(fd, pat, args)
1133 _doprnt(pat, args, fd);
1134 return 0; /* wrong, but perl doesn't use the return value */
1136 #endif /* HAS_VPRINTF */
1137 #endif /* I_VARARGS || I_STDARGS */
1140 #if BYTEORDER != 0x4321
1142 #ifndef CAN_PROTOTYPE
1149 #if (BYTEORDER & 1) == 0
1152 result = ((s & 255) << 8) + ((s >> 8) & 255);
1160 #ifndef CAN_PROTOTYPE
1169 char c[sizeof(long)];
1172 #if BYTEORDER == 0x1234
1173 u.c[0] = (l >> 24) & 255;
1174 u.c[1] = (l >> 16) & 255;
1175 u.c[2] = (l >> 8) & 255;
1179 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1180 croak("Unknown BYTEORDER\n");
1185 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1186 u.c[o & 0xf] = (l >> s) & 255;
1194 #ifndef CAN_PROTOTYPE
1203 char c[sizeof(long)];
1206 #if BYTEORDER == 0x1234
1207 u.c[0] = (l >> 24) & 255;
1208 u.c[1] = (l >> 16) & 255;
1209 u.c[2] = (l >> 8) & 255;
1213 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1214 croak("Unknown BYTEORDER\n");
1221 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1222 l |= (u.c[o & 0xf] & 255) << s;
1229 #endif /* BYTEORDER != 0x4321 */
1233 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1234 * If these functions are defined,
1235 * the BYTEORDER is neither 0x1234 nor 0x4321.
1236 * However, this is not assumed.
1240 #define HTOV(name,type) \
1247 char c[sizeof(type)]; \
1251 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1252 u.c[i] = (n >> s) & 0xFF; \
1257 #define VTOH(name,type) \
1264 char c[sizeof(type)]; \
1270 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1271 n += (u.c[i] & 0xFF) << s; \
1276 #if defined(HAS_HTOVS) && !defined(htovs)
1279 #if defined(HAS_HTOVL) && !defined(htovl)
1282 #if defined(HAS_VTOHS) && !defined(vtohs)
1285 #if defined(HAS_VTOHL) && !defined(vtohl)
1289 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1296 register I32 this, that;
1299 I32 doexec = strNE(cmd,"-");
1303 this = (*mode == 'w');
1308 taint_proper("Insecure %s%s", "EXEC");
1311 while ((pid = (doexec?vfork():fork())) < 0) {
1312 if (errno != EAGAIN) {
1315 croak("Can't fork");
1326 if (p[THIS] != (*mode == 'r')) {
1327 dup2(p[THIS], *mode == 'r');
1331 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
1337 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1340 do_exec(cmd); /* may or may not use the shell */
1344 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
1345 sv_setiv(GvSV(tmpgv),(I32)getpid());
1347 hv_clear(pidstatus); /* we have no children */
1352 do_execfree(); /* free any memory malloced by child on vfork */
1354 if (p[that] < p[this]) {
1355 dup2(p[this], p[that]);
1359 sv = *av_fetch(fdpid,p[this],TRUE);
1360 (void)SvUPGRADE(sv,SVt_IV);
1363 return fdopen(p[this], mode);
1366 #if defined(atarist) || defined(OS2)
1373 return popen(cmd, mode);
1377 #endif /* !DOSISH */
1384 struct stat tmpstatbuf;
1386 fprintf(stderr,"%s", s);
1387 for (fd = 0; fd < 32; fd++) {
1388 if (Fstat(fd,&tmpstatbuf) >= 0)
1389 fprintf(stderr," %d",fd);
1391 fprintf(stderr,"\n");
1401 #if defined(HAS_FCNTL) && defined(F_DUPFD)
1405 return fcntl(oldfd, F_DUPFD, newfd);
1414 while ((fd = dup(oldfd)) != newfd && fd >= 0) /* good enough for low fd's */
1417 close(fdtmp[--fdx]);
1423 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1428 Signal_t (*hstat)(), (*istat)(), (*qstat)();
1433 svp = av_fetch(fdpid,fileno(ptr),TRUE);
1434 pid = (int)SvIVX(*svp);
1439 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1441 hstat = signal(SIGHUP, SIG_IGN);
1442 istat = signal(SIGINT, SIG_IGN);
1443 qstat = signal(SIGQUIT, SIG_IGN);
1445 pid = wait4pid(pid, &status, 0);
1446 } while (pid == -1 && errno == EINTR);
1447 signal(SIGHUP, hstat);
1448 signal(SIGINT, istat);
1449 signal(SIGQUIT, qstat);
1450 return(pid < 0 ? pid : status);
1452 #endif /* !DOSISH */
1454 #if !defined(DOSISH) || defined(OS2)
1456 wait4pid(pid,statusp,flags)
1468 sprintf(spid, "%d", pid);
1469 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1470 if (svp && *svp != &sv_undef) {
1471 *statusp = SvIVX(*svp);
1472 (void)hv_delete(pidstatus,spid,strlen(spid),G_DISCARD);
1479 hv_iterinit(pidstatus);
1480 if (entry = hv_iternext(pidstatus)) {
1481 pid = atoi(hv_iterkey(entry,(I32*)statusp));
1482 sv = hv_iterval(pidstatus,entry);
1483 *statusp = SvIVX(sv);
1484 sprintf(spid, "%d", pid);
1485 (void)hv_delete(pidstatus,spid,strlen(spid),G_DISCARD);
1490 return waitpid(pid,statusp,flags);
1493 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1498 croak("Can't do waitpid with flags");
1500 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1501 pidgone(result,*statusp);
1510 #endif /* !DOSISH */
1521 sprintf(spid, "%d", pid);
1522 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1523 (void)SvUPGRADE(sv,SVt_IV);
1528 #if defined(atarist) || defined(OS2)
1539 repeatcpy(to,from,len,count)
1541 register char *from;
1546 register char *frombase = from;
1554 while (count-- > 0) {
1555 for (todo = len; todo > 0; todo--) {
1562 #ifndef CASTNEGFLOAT
1570 # define BIGDOUBLE 2147483648.0
1572 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1575 return (unsigned long)f;
1577 return (unsigned long)along;
1584 /* Look for MAX and MIN integral values. If we can't find them,
1585 we'll use 32-bit two's complement defaults.
1588 # ifdef MAXLONG /* Often used in <values.h> */
1589 # define LONG_MAX MAXLONG
1591 # define LONG_MAX 2147483647L
1596 # define LONG_MIN (-LONG_MAX - 1)
1601 # define LONG_MAX MAXULONG
1603 # define ULONG_MAX 4294967295L
1607 /* Unfortunately, on some systems the cast_uv() function doesn't
1608 work with the system-supplied definition of ULONG_MAX. The
1609 comparison (f >= ULONG_MAX) always comes out true. It must be a
1610 problem with the compiler constant folding.
1612 In any case, this workaround should be fine on any two's complement
1613 system. If it's not, supply a '-DMY_ULONG_MAX=whatever' in your
1615 --Andy Dougherty <doughera@lafcol.lafayette.edu>
1617 #ifndef MY_ULONG_MAX
1618 # define MY_ULONG_MAX ((UV)LONG_MAX * (UV)2 + (UV)1)
1626 return (I32) LONG_MAX;
1628 return (I32) LONG_MIN;
1637 return (IV) LONG_MAX;
1639 return (IV) LONG_MIN;
1647 if (f >= MY_ULONG_MAX)
1648 return (UV) MY_ULONG_MAX;
1660 char *fa = strrchr(a,'/');
1661 char *fb = strrchr(b,'/');
1662 struct stat tmpstatbuf1;
1663 struct stat tmpstatbuf2;
1665 #define MAXPATHLEN 1024
1667 char tmpbuf[MAXPATHLEN+1];
1682 strncpy(tmpbuf, a, fa - a);
1683 if (Stat(tmpbuf, &tmpstatbuf1) < 0)
1688 strncpy(tmpbuf, b, fb - b);
1689 if (Stat(tmpbuf, &tmpstatbuf2) < 0)
1691 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1692 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1694 #endif /* !HAS_RENAME */
1697 scan_oct(start, len, retlen)
1702 register char *s = start;
1703 register unsigned long retval = 0;
1705 while (len && *s >= '0' && *s <= '7') {
1707 retval |= *s++ - '0';
1710 if (dowarn && len && (*s == '8' || *s == '9'))
1711 warn("Illegal octal digit ignored");
1712 *retlen = s - start;
1717 scan_hex(start, len, retlen)
1722 register char *s = start;
1723 register unsigned long retval = 0;
1726 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1728 retval |= (tmp - hexdigit) & 15;
1731 *retlen = s - start;