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.
36 # include <sys/file.h>
42 static void xstat _((void));
47 /* paranoid version of malloc */
49 /* NOTE: Do not call the next three routines directly. Use the macros
50 * in handy.h, so that we can easily redefine everything to do tracking of
51 * allocated hunks back to the original New to track down any memory leaks.
65 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
71 croak("panic: malloc");
73 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
74 #if !(defined(I286) || defined(atarist))
75 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
77 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
84 fputs(no_mem,stderr) FLUSH;
90 /* paranoid version of realloc */
93 saferealloc(where,size)
102 #if !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE)
104 #endif /* !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) */
108 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
113 croak("Null realloc");
116 croak("panic: realloc");
118 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
120 #if !(defined(I286) || defined(atarist))
122 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
123 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
127 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
128 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
137 fputs(no_mem,stderr) FLUSH;
143 /* safe version of free */
149 #if !(defined(I286) || defined(atarist))
150 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
152 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
160 #endif /* !safemalloc */
164 #define ALIGN sizeof(long)
171 register char *where;
173 where = safemalloc(size + ALIGN);
177 return where + ALIGN;
181 safexrealloc(where,size)
185 register char *new = saferealloc(where - ALIGN, size + ALIGN);
198 x = where[0] + 100 * where[1];
208 for (i = 0; i < MAXXCOUNT; i++) {
209 if (xcount[i] > lastxcount[i]) {
210 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
211 lastxcount[i] = xcount[i];
216 #endif /* LEAKTEST */
218 /* copy a string up to some (non-backslashed) delimiter, if any */
221 cpytill(to,from,fromend,delim,retlen)
224 register char *fromend;
230 for (; from < fromend; from++,to++) {
232 if (from[1] == delim)
234 else if (from[1] == '\\')
237 else if (*from == delim)
242 *retlen = to - origto;
246 /* return ptr to little string in big string, NULL if not found */
247 /* This routine was donated by Corey Satten. */
252 register char *little;
254 register char *s, *x;
265 for (x=big,s=little; *s; /**/ ) {
279 /* same as instr but allow embedded nulls */
282 ninstr(big, bigend, little, lend)
284 register char *bigend;
288 register char *s, *x;
289 register I32 first = *little;
290 register char *littleend = lend;
292 if (!first && little >= littleend)
294 if (bigend - big < littleend - little)
296 bigend -= littleend - little++;
297 while (big <= bigend) {
300 for (x=big,s=little; s < littleend; /**/ ) {
312 /* reverse of the above--find last substring */
315 rninstr(big, bigend, little, lend)
321 register char *bigbeg;
322 register char *s, *x;
323 register I32 first = *little;
324 register char *littleend = lend;
326 if (!first && little >= littleend)
329 big = bigend - (littleend - little++);
330 while (big >= bigbeg) {
333 for (x=big+2,s=little; s < littleend; /**/ ) {
346 fbm_compile(sv, iflag)
350 register unsigned char *s;
351 register unsigned char *table;
353 register U32 len = SvCUR(sv);
358 table = (unsigned char*)(SvPVX(sv) + len + 1);
360 for (i = 0; i < 256; i++) {
364 while (s >= (unsigned char*)(SvPVX(sv)))
366 if (table[*s] == len) {
369 table[*s] = table[fold[*s]] = i;
383 sv_upgrade(sv, SVt_PVBM);
384 sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
387 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
389 register U32 tmp, foldtmp;
391 for (i = 0; i < len; i++) {
393 foldtmp=freq[fold[s[i]]];
394 if (tmp < frequency && foldtmp < frequency) {
396 /* choose most frequent among the two */
397 frequency = (tmp > foldtmp) ? tmp : foldtmp;
402 for (i = 0; i < len; i++) {
403 if (freq[s[i]] < frequency) {
405 frequency = freq[s[i]];
409 BmRARE(sv) = s[rarest];
410 BmPREVIOUS(sv) = rarest;
411 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
415 fbm_instr(big, bigend, littlestr)
417 register unsigned char *bigend;
420 register unsigned char *s;
422 register I32 littlelen;
423 register unsigned char *little;
424 register unsigned char *table;
425 register unsigned char *olds;
426 register unsigned char *oldlittle;
428 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
430 char *l = SvPV(littlestr,len);
433 return ninstr((char*)big,(char*)bigend, l, l + len);
436 littlelen = SvCUR(littlestr);
437 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
438 if (littlelen > bigend - big)
440 little = (unsigned char*)SvPVX(littlestr);
441 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
442 big = bigend - littlelen; /* just start near end */
443 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
447 s = bigend - littlelen;
448 if (*s == *little && bcmp((char*)s,little,littlelen)==0)
449 return (char*)s; /* how sweet it is */
450 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
453 if (*s == *little && bcmp((char*)s,little,littlelen)==0)
459 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
460 if (--littlelen >= bigend - big)
463 oldlittle = little = table - 2;
464 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
468 if (tmp = table[*s]) {
470 if (bigend - s > tmp) {
475 if ((s += tmp) < bigend)
481 tmp = littlelen; /* less expensive than calling strncmp() */
484 if (*--s == *--little || fold[*s] == *little)
486 s = olds + 1; /* here we pay the price for failure */
488 if (s < bigend) /* fake up continue to outer loop */
500 if (tmp = table[*s]) {
502 if (bigend - s > tmp) {
507 if ((s += tmp) < bigend)
513 tmp = littlelen; /* less expensive than calling strncmp() */
516 if (*--s == *--little)
518 s = olds + 1; /* here we pay the price for failure */
520 if (s < bigend) /* fake up continue to outer loop */
532 screaminstr(bigstr, littlestr)
536 register unsigned char *s, *x;
537 register unsigned char *big;
539 register I32 previous;
541 register unsigned char *little;
542 register unsigned char *bigend;
543 register unsigned char *littleend;
545 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
547 little = (unsigned char *)(SvPVX(littlestr));
548 littleend = little + SvCUR(littlestr);
550 previous = BmPREVIOUS(littlestr);
551 big = (unsigned char *)(SvPVX(bigstr));
552 bigend = big + SvCUR(bigstr);
553 while (pos < previous) {
554 if (!(pos += screamnext[pos]))
558 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
560 if (big[pos-previous] != first && big[pos-previous] != fold[first])
562 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
565 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
571 return (char *)(big+pos-previous);
573 pos += screamnext[pos] /* does this goof up anywhere? */
578 if (big[pos-previous] != first)
580 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
589 return (char *)(big+pos-previous);
590 } while ( pos += screamnext[pos] );
592 #else /* !POINTERRIGOR */
594 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
596 if (big[pos] != first && big[pos] != fold[first])
598 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
601 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
607 return (char *)(big+pos);
609 pos += screamnext[pos] /* does this goof up anywhere? */
614 if (big[pos] != first)
616 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
625 return (char *)(big+pos);
627 pos += screamnext[pos]
630 #endif /* POINTERRIGOR */
645 if (fold[*a++] == *b++)
652 /* copy a string to a safe spot */
658 register char *newaddr;
660 New(902,newaddr,strlen(sv)+1,char);
661 (void)strcpy(newaddr,sv);
665 /* same thing but with a known length */
672 register char *newaddr;
674 New(903,newaddr,len+1,char);
675 Copy(sv,newaddr,len,char); /* might not be null terminated */
676 newaddr[len] = '\0'; /* is now */
680 #if !defined(I_STDARG) && !defined(I_VARARGS)
683 * Fallback on the old hackers way of doing varargs
688 mess(pat,a1,a2,a3,a4)
693 I32 usermess = strEQ(pat,"%s");
698 tmpstr = sv_newmortal();
699 sv_setpv(tmpstr, (char*)a1);
700 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
703 (void)sprintf(s,pat,a1,a2,a3,a4);
709 strcpy(s, " during global destruction.\n");
711 if (curcop->cop_line) {
712 (void)sprintf(s," at %s line %ld",
713 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
716 if (GvIO(last_in_gv) &&
717 IoLINES(GvIOp(last_in_gv)) ) {
718 (void)sprintf(s,", <%s> %s %ld",
719 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
720 strEQ(rs,"\n") ? "line" : "chunk",
721 (long)IoLINES(GvIOp(last_in_gv)));
724 (void)strcpy(s,".\n");
727 sv_catpv(tmpstr,buf+1);
730 return SvPVX(tmpstr);
736 void croak(pat,a1,a2,a3,a4)
743 message = mess(pat,a1,a2,a3,a4);
745 restartop = die_where(message);
748 fputs(message,stderr);
749 (void)fflush(stderr);
751 (void)UNLINK(e_tmpname);
753 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
757 void warn(pat,a1,a2,a3,a4)
763 message = mess(pat,a1,a2,a3,a4);
764 fputs(message,stderr);
768 (void)fflush(stderr);
771 #else /* !defined(I_STDARG) && !defined(I_VARARGS) */
775 mess(char *pat, va_list *args)
788 #ifdef USE_CHAR_VSPRINTF
796 usermess = strEQ(pat, "%s");
798 tmpstr = sv_newmortal();
799 sv_setpv(tmpstr, va_arg(*args, char *));
800 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
803 (void) vsprintf(s,pat,*args);
810 strcpy(s, " during global destruction.\n");
812 if (curcop->cop_line) {
813 (void)sprintf(s," at %s line %ld",
814 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
817 if (GvIO(last_in_gv) &&
818 IoLINES(GvIOp(last_in_gv)) ) {
819 (void)sprintf(s,", <%s> %s %ld",
820 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
821 strEQ(rs,"\n") ? "line" : "chunk",
822 (long)IoLINES(GvIOp(last_in_gv)));
825 (void)strcpy(s,".\n");
828 sv_catpv(tmpstr,buf+1);
832 return SvPVX(tmpstr);
839 croak(char* pat, ...)
856 message = mess(pat, &args);
859 restartop = die_where(message);
862 fputs(message,stderr);
863 (void)fflush(stderr);
865 (void)UNLINK(e_tmpname);
867 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
888 message = mess(pat, &args);
891 fputs(message,stderr);
895 (void)fflush(stderr);
897 #endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
899 #ifndef VMS /* VMS' my_setenv() is in VMS.c */
904 register I32 i=setenv_getix(nam); /* where does it go? */
906 if (environ == origenviron) { /* need we copy environment? */
912 for (max = i; environ[max]; max++) ;
913 New(901,tmpenv, max+2, char*);
914 for (j=0; j<max; j++) /* copy environment */
915 tmpenv[j] = savepv(environ[j]);
916 tmpenv[max] = Nullch;
917 environ = tmpenv; /* tell exec where it is now */
921 environ[i] = environ[i+1];
926 if (!environ[i]) { /* does not exist yet */
927 Renew(environ, i+2, char*); /* just expand it a bit */
928 environ[i+1] = Nullch; /* make sure it's null terminated */
931 Safefree(environ[i]);
932 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
934 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
936 /* MS-DOS requires environment variable names to be in uppercase */
937 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
938 * some utilities and applications may break because they only look
939 * for upper case strings. (Fixed strupr() bug here.)]
941 strcpy(environ[i],nam); strupr(environ[i]);
942 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
950 register I32 i, len = strlen(nam);
952 for (i = 0; environ[i]; i++) {
953 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
954 break; /* strnEQ must come first to avoid */
955 } /* potential SEGV's */
962 unlnk(f) /* unlink all versions of a file */
967 for (i = 0; unlink(f) >= 0; i++) ;
972 #if !defined(HAS_BCOPY) || !defined(HAS_SAFE_BCOPY)
974 my_bcopy(from,to,len)
981 if (from - to >= 0) {
995 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1011 my_memcmp(s1,s2,len)
1012 register unsigned char *s1;
1013 register unsigned char *s2;
1019 if (tmp = *s1++ - *s2++)
1024 #endif /* HAS_MEMCMP */
1029 #ifdef USE_CHAR_VSPRINTF
1034 vsprintf(dest, pat, args)
1035 char *dest, *pat, *args;
1039 fakebuf._ptr = dest;
1040 fakebuf._cnt = 32767;
1044 fakebuf._flag = _IOWRT|_IOSTRG;
1045 _doprnt(pat, args, &fakebuf); /* what a kludge */
1046 (void)putc('\0', &fakebuf);
1047 #ifdef USE_CHAR_VSPRINTF
1050 return 0; /* perl doesn't use return value */
1055 vfprintf(fd, pat, args)
1059 _doprnt(pat, args, fd);
1060 return 0; /* wrong, but perl doesn't use the return value */
1062 #endif /* HAS_VPRINTF */
1063 #endif /* I_VARARGS */
1066 * I think my_swap(), htonl() and ntohl() have never been used.
1067 * perl.h contains last-chance references to my_swap(), my_htonl()
1068 * and my_ntohl(). I presume these are the intended functions;
1069 * but htonl() and ntohl() have the wrong names. There are no
1070 * functions my_htonl() and my_ntohl() defined anywhere.
1074 #if BYTEORDER != 0x4321
1079 #if (BYTEORDER & 1) == 0
1082 result = ((s & 255) << 8) + ((s >> 8) & 255);
1095 char c[sizeof(long)];
1098 #if BYTEORDER == 0x1234
1099 u.c[0] = (l >> 24) & 255;
1100 u.c[1] = (l >> 16) & 255;
1101 u.c[2] = (l >> 8) & 255;
1105 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1106 croak("Unknown BYTEORDER\n");
1111 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1112 u.c[o & 0xf] = (l >> s) & 255;
1125 char c[sizeof(long)];
1128 #if BYTEORDER == 0x1234
1129 u.c[0] = (l >> 24) & 255;
1130 u.c[1] = (l >> 16) & 255;
1131 u.c[2] = (l >> 8) & 255;
1135 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1136 croak("Unknown BYTEORDER\n");
1143 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1144 l |= (u.c[o & 0xf] & 255) << s;
1151 #endif /* BYTEORDER != 0x4321 */
1155 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1156 * If these functions are defined,
1157 * the BYTEORDER is neither 0x1234 nor 0x4321.
1158 * However, this is not assumed.
1162 #define HTOV(name,type) \
1169 char c[sizeof(type)]; \
1173 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1174 u.c[i] = (n >> s) & 0xFF; \
1179 #define VTOH(name,type) \
1186 char c[sizeof(type)]; \
1192 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1193 n += (u.c[i] & 0xFF) << s; \
1198 #if defined(HAS_HTOVS) && !defined(htovs)
1201 #if defined(HAS_HTOVL) && !defined(htovl)
1204 #if defined(HAS_VTOHS) && !defined(vtohs)
1207 #if defined(HAS_VTOHL) && !defined(vtohl)
1211 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1218 register I32 this, that;
1221 I32 doexec = strNE(cmd,"-");
1225 this = (*mode == 'w');
1230 taint_proper("Insecure %s%s", "EXEC");
1233 while ((pid = (doexec?vfork():fork())) < 0) {
1234 if (errno != EAGAIN) {
1237 croak("Can't fork");
1248 if (p[THIS] != (*mode == 'r')) {
1249 dup2(p[THIS], *mode == 'r');
1253 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
1259 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1262 do_exec(cmd); /* may or may not use the shell */
1266 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
1267 sv_setiv(GvSV(tmpgv),(I32)getpid());
1269 hv_clear(pidstatus); /* we have no children */
1274 do_execfree(); /* free any memory malloced by child on vfork */
1276 if (p[that] < p[this]) {
1277 dup2(p[this], p[that]);
1281 sv = *av_fetch(fdpid,p[this],TRUE);
1282 (void)SvUPGRADE(sv,SVt_IV);
1285 return fdopen(p[this], mode);
1295 return popen(cmd, mode);
1299 #endif /* !DOSISH */
1306 struct stat tmpstatbuf;
1308 fprintf(stderr,"%s", s);
1309 for (fd = 0; fd < 32; fd++) {
1310 if (Fstat(fd,&tmpstatbuf) >= 0)
1311 fprintf(stderr," %d",fd);
1313 fprintf(stderr,"\n");
1322 #if defined(HAS_FCNTL) && defined(F_DUPFD)
1324 fcntl(oldfd, F_DUPFD, newfd);
1333 while ((fd = dup(oldfd)) != newfd) /* good enough for low fd's */
1336 close(fdtmp[--fdx]);
1342 #ifndef VMS /* VMS' my_pclose() is in VMS.c */
1347 Signal_t (*hstat)(), (*istat)(), (*qstat)();
1352 svp = av_fetch(fdpid,fileno(ptr),TRUE);
1358 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1360 hstat = signal(SIGHUP, SIG_IGN);
1361 istat = signal(SIGINT, SIG_IGN);
1362 qstat = signal(SIGQUIT, SIG_IGN);
1363 pid = wait4pid(pid, &status, 0);
1364 signal(SIGHUP, hstat);
1365 signal(SIGINT, istat);
1366 signal(SIGQUIT, qstat);
1367 return(pid < 0 ? pid : status);
1371 wait4pid(pid,statusp,flags)
1383 sprintf(spid, "%d", pid);
1384 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1385 if (svp && *svp != &sv_undef) {
1386 *statusp = SvIVX(*svp);
1387 hv_delete(pidstatus,spid,strlen(spid));
1394 hv_iterinit(pidstatus);
1395 if (entry = hv_iternext(pidstatus)) {
1396 pid = atoi(hv_iterkey(entry,(I32*)statusp));
1397 sv = hv_iterval(pidstatus,entry);
1398 *statusp = SvIVX(sv);
1399 sprintf(spid, "%d", pid);
1400 hv_delete(pidstatus,spid,strlen(spid));
1405 return waitpid(pid,statusp,flags);
1408 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1413 croak("Can't do waitpid with flags");
1415 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1416 pidgone(result,*statusp);
1425 #endif /* !DOSISH */
1436 sprintf(spid, "%d", pid);
1437 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1438 (void)SvUPGRADE(sv,SVt_IV);
1454 repeatcpy(to,from,len,count)
1456 register char *from;
1461 register char *frombase = from;
1469 while (count-- > 0) {
1470 for (todo = len; todo > 0; todo--) {
1477 #ifndef CASTNEGFLOAT
1485 # define BIGDOUBLE 2147483648.0
1487 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1490 return (unsigned long)f;
1492 return (unsigned long)along;
1502 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit int's ! */
1503 # define BIGNEGDOUBLE (-2147483648.0)
1505 return (I32)fmod(f, BIGDOUBLE);
1506 if (f <= BIGNEGDOUBLE)
1507 return (I32)fmod(f, BIGNEGDOUBLE);
1511 # undef BIGNEGDOUBLE
1517 /* XXX This should be fixed. It assumes 32 bit IV's. */
1518 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit IV's ! */
1519 # define BIGNEGDOUBLE (-2147483648.0)
1521 return (IV)fmod(f, BIGDOUBLE);
1522 if (f <= BIGNEGDOUBLE)
1523 return (IV)fmod(f, BIGNEGDOUBLE);
1527 # undef BIGNEGDOUBLE
1536 char *fa = strrchr(a,'/');
1537 char *fb = strrchr(b,'/');
1538 struct stat tmpstatbuf1;
1539 struct stat tmpstatbuf2;
1541 #define MAXPATHLEN 1024
1543 char tmpbuf[MAXPATHLEN+1];
1558 strncpy(tmpbuf, a, fa - a);
1559 if (Stat(tmpbuf, &tmpstatbuf1) < 0)
1564 strncpy(tmpbuf, b, fb - b);
1565 if (Stat(tmpbuf, &tmpstatbuf2) < 0)
1567 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1568 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1570 #endif /* !HAS_RENAME */
1573 scan_oct(start, len, retlen)
1578 register char *s = start;
1579 register unsigned long retval = 0;
1581 while (len-- && *s >= '0' && *s <= '7') {
1583 retval |= *s++ - '0';
1585 *retlen = s - start;
1590 scan_hex(start, len, retlen)
1595 register char *s = start;
1596 register unsigned long retval = 0;
1599 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1601 retval |= (tmp - hexdigit) & 15;
1604 *retlen = s - start;
1608 /* Amazingly enough, some systems (e.g. Dynix 3) don't have fmod.
1609 This is a slow, stupid, but working emulation. (AD)
1616 double i = 0.0; /* Can't use int because it can overflow */
1617 if ((x == 0) || (y == 0))
1619 /* The sign of fmod is the same as the sign of x. */
1620 if ( (x < 0 && y > 0) || (x > 0 && y < 0) )