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)
34 # include <sys/file.h>
40 static void xstat _((void));
45 /* paranoid version of malloc */
47 /* NOTE: Do not call the next three routines directly. Use the macros
48 * in handy.h, so that we can easily redefine everything to do tracking of
49 * allocated hunks back to the original New to track down any memory leaks.
63 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
69 croak("panic: malloc");
71 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
72 #if !(defined(I286) || defined(atarist))
73 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
75 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
82 fputs(no_mem,stderr) FLUSH;
88 /* paranoid version of realloc */
91 saferealloc(where,size)
102 #endif /* ! STANDARD_C */
106 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
111 croak("Null realloc");
114 croak("panic: realloc");
116 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
118 #if !(defined(I286) || defined(atarist))
120 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
121 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
125 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
126 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
135 fputs(no_mem,stderr) FLUSH;
141 /* safe version of free */
147 #if !(defined(I286) || defined(atarist))
148 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
150 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
158 #endif /* !safemalloc */
162 #define ALIGN sizeof(long)
169 register char *where;
171 where = safemalloc(size + ALIGN);
175 return where + ALIGN;
179 safexrealloc(where,size)
183 register char *new = saferealloc(where - ALIGN, size + ALIGN);
196 x = where[0] + 100 * where[1];
206 for (i = 0; i < MAXXCOUNT; i++) {
207 if (xcount[i] > lastxcount[i]) {
208 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
209 lastxcount[i] = xcount[i];
214 #endif /* LEAKTEST */
216 /* copy a string up to some (non-backslashed) delimiter, if any */
219 cpytill(to,from,fromend,delim,retlen)
222 register char *fromend;
228 for (; from < fromend; from++,to++) {
230 if (from[1] == delim)
232 else if (from[1] == '\\')
235 else if (*from == delim)
240 *retlen = to - origto;
244 /* return ptr to little string in big string, NULL if not found */
245 /* This routine was donated by Corey Satten. */
250 register char *little;
252 register char *s, *x;
263 for (x=big,s=little; *s; /**/ ) {
277 /* same as instr but allow embedded nulls */
280 ninstr(big, bigend, little, lend)
282 register char *bigend;
286 register char *s, *x;
287 register I32 first = *little;
288 register char *littleend = lend;
290 if (!first && little >= littleend)
292 if (bigend - big < littleend - little)
294 bigend -= littleend - little++;
295 while (big <= bigend) {
298 for (x=big,s=little; s < littleend; /**/ ) {
310 /* reverse of the above--find last substring */
313 rninstr(big, bigend, little, lend)
319 register char *bigbeg;
320 register char *s, *x;
321 register I32 first = *little;
322 register char *littleend = lend;
324 if (!first && little >= littleend)
327 big = bigend - (littleend - little++);
328 while (big >= bigbeg) {
331 for (x=big+2,s=little; s < littleend; /**/ ) {
344 fbm_compile(sv, iflag)
348 register unsigned char *s;
349 register unsigned char *table;
351 register U32 len = SvCUR(sv);
356 table = (unsigned char*)(SvPVX(sv) + len + 1);
358 for (i = 0; i < 256; i++) {
362 while (s >= (unsigned char*)(SvPVX(sv)))
364 if (table[*s] == len) {
367 table[*s] = table[fold[*s]] = i;
381 sv_upgrade(sv, SVt_PVBM);
382 sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
385 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
387 register U32 tmp, foldtmp;
389 for (i = 0; i < len; i++) {
391 foldtmp=freq[fold[s[i]]];
392 if (tmp < frequency && foldtmp < frequency) {
394 /* choose most frequent among the two */
395 frequency = (tmp > foldtmp) ? tmp : foldtmp;
400 for (i = 0; i < len; i++) {
401 if (freq[s[i]] < frequency) {
403 frequency = freq[s[i]];
407 BmRARE(sv) = s[rarest];
408 BmPREVIOUS(sv) = rarest;
409 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
413 fbm_instr(big, bigend, littlestr)
415 register unsigned char *bigend;
418 register unsigned char *s;
420 register I32 littlelen;
421 register unsigned char *little;
422 register unsigned char *table;
423 register unsigned char *olds;
424 register unsigned char *oldlittle;
426 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
428 char *l = SvPV(littlestr,len);
431 return ninstr((char*)big,(char*)bigend, l, l + len);
434 littlelen = SvCUR(littlestr);
435 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
436 if (littlelen > bigend - big)
438 little = (unsigned char*)SvPVX(littlestr);
439 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
440 big = bigend - littlelen; /* just start near end */
441 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
445 s = bigend - littlelen;
446 if (*s == *little && bcmp(s,little,littlelen)==0)
447 return (char*)s; /* how sweet it is */
448 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
451 if (*s == *little && bcmp(s,little,littlelen)==0)
457 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
458 if (--littlelen >= bigend - big)
461 oldlittle = little = table - 2;
462 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
466 if (tmp = table[*s]) {
468 if (bigend - s > tmp) {
473 if ((s += tmp) < bigend)
479 tmp = littlelen; /* less expensive than calling strncmp() */
482 if (*--s == *--little || fold[*s] == *little)
484 s = olds + 1; /* here we pay the price for failure */
486 if (s < bigend) /* fake up continue to outer loop */
498 if (tmp = table[*s]) {
500 if (bigend - s > tmp) {
505 if ((s += tmp) < bigend)
511 tmp = littlelen; /* less expensive than calling strncmp() */
514 if (*--s == *--little)
516 s = olds + 1; /* here we pay the price for failure */
518 if (s < bigend) /* fake up continue to outer loop */
530 screaminstr(bigstr, littlestr)
534 register unsigned char *s, *x;
535 register unsigned char *big;
537 register I32 previous;
539 register unsigned char *little;
540 register unsigned char *bigend;
541 register unsigned char *littleend;
543 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
545 little = (unsigned char *)(SvPVX(littlestr));
546 littleend = little + SvCUR(littlestr);
548 previous = BmPREVIOUS(littlestr);
549 big = (unsigned char *)(SvPVX(bigstr));
550 bigend = big + SvCUR(bigstr);
551 while (pos < previous) {
552 if (!(pos += screamnext[pos]))
556 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
558 if (big[pos-previous] != first && big[pos-previous] != fold[first])
560 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
563 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
569 return (char *)(big+pos-previous);
571 pos += screamnext[pos] /* does this goof up anywhere? */
576 if (big[pos-previous] != first)
578 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
587 return (char *)(big+pos-previous);
588 } while ( pos += screamnext[pos] );
590 #else /* !POINTERRIGOR */
592 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
594 if (big[pos] != first && big[pos] != fold[first])
596 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
599 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
605 return (char *)(big+pos);
607 pos += screamnext[pos] /* does this goof up anywhere? */
612 if (big[pos] != first)
614 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
623 return (char *)(big+pos);
625 pos += screamnext[pos]
628 #endif /* POINTERRIGOR */
643 if (fold[*a++] == *b++)
650 /* copy a string to a safe spot */
656 register char *newaddr;
658 New(902,newaddr,strlen(sv)+1,char);
659 (void)strcpy(newaddr,sv);
663 /* same thing but with a known length */
670 register char *newaddr;
672 New(903,newaddr,len+1,char);
673 Copy(sv,newaddr,len,char); /* might not be null terminated */
674 newaddr[len] = '\0'; /* is now */
678 #if !defined(I_STDARG) && !defined(I_VARARGS)
681 * Fallback on the old hackers way of doing varargs
686 mess(pat,a1,a2,a3,a4)
691 I32 usermess = strEQ(pat,"%s");
696 tmpstr = sv_newmortal();
697 sv_setpv(tmpstr, (char*)a1);
698 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
701 (void)sprintf(s,pat,a1,a2,a3,a4);
707 strcpy(s, " during global destruction.\n");
709 if (curcop->cop_line) {
710 (void)sprintf(s," at %s line %ld",
711 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
714 if (GvIO(last_in_gv) &&
715 IoLINES(GvIOp(last_in_gv)) ) {
716 (void)sprintf(s,", <%s> %s %ld",
717 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
718 strEQ(rs,"\n") ? "line" : "chunk",
719 (long)IoLINES(GvIOp(last_in_gv)));
722 (void)strcpy(s,".\n");
725 sv_catpv(tmpstr,buf+1);
728 return SvPVX(tmpstr);
734 void croak(pat,a1,a2,a3,a4)
741 message = mess(pat,a1,a2,a3,a4);
743 restartop = die_where(message);
746 fputs(message,stderr);
747 (void)fflush(stderr);
749 (void)UNLINK(e_tmpname);
751 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
755 void warn(pat,a1,a2,a3,a4)
761 message = mess(pat,a1,a2,a3,a4);
762 fputs(message,stderr);
766 (void)fflush(stderr);
769 #else /* !defined(I_STDARG) && !defined(I_VARARGS) */
773 mess(char *pat, va_list *args)
786 #ifdef USE_CHAR_VSPRINTF
794 usermess = strEQ(pat, "%s");
796 tmpstr = sv_newmortal();
797 sv_setpv(tmpstr, va_arg(*args, char *));
798 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
801 (void) vsprintf(s,pat,*args);
808 strcpy(s, " during global destruction.\n");
810 if (curcop->cop_line) {
811 (void)sprintf(s," at %s line %ld",
812 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
815 if (GvIO(last_in_gv) &&
816 IoLINES(GvIOp(last_in_gv)) ) {
817 (void)sprintf(s,", <%s> %s %ld",
818 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
819 strEQ(rs,"\n") ? "line" : "chunk",
820 (long)IoLINES(GvIOp(last_in_gv)));
823 (void)strcpy(s,".\n");
826 sv_catpv(tmpstr,buf+1);
830 return SvPVX(tmpstr);
837 croak(char* pat, ...)
854 message = mess(pat, &args);
857 restartop = die_where(message);
860 fputs(message,stderr);
861 (void)fflush(stderr);
863 (void)UNLINK(e_tmpname);
865 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
886 message = mess(pat, &args);
889 fputs(message,stderr);
893 (void)fflush(stderr);
895 #endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
897 #ifndef VMS /* VMS' my_setenv() is in VMS.c */
902 register I32 i=setenv_getix(nam); /* where does it go? */
904 if (environ == origenviron) { /* need we copy environment? */
910 for (max = i; environ[max]; max++) ;
911 New(901,tmpenv, max+2, char*);
912 for (j=0; j<max; j++) /* copy environment */
913 tmpenv[j] = savepv(environ[j]);
914 tmpenv[max] = Nullch;
915 environ = tmpenv; /* tell exec where it is now */
919 environ[i] = environ[i+1];
924 if (!environ[i]) { /* does not exist yet */
925 Renew(environ, i+2, char*); /* just expand it a bit */
926 environ[i+1] = Nullch; /* make sure it's null terminated */
929 Safefree(environ[i]);
930 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
932 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
934 /* MS-DOS requires environment variable names to be in uppercase */
935 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
936 * some utilities and applications may break because they only look
937 * for upper case strings. (Fixed strupr() bug here.)]
939 strcpy(environ[i],nam); strupr(environ[i]);
940 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
948 register I32 i, len = strlen(nam);
950 for (i = 0; environ[i]; i++) {
951 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
952 break; /* strnEQ must come first to avoid */
953 } /* potential SEGV's */
960 unlnk(f) /* unlink all versions of a file */
965 for (i = 0; unlink(f) >= 0; i++) ;
970 #if !defined(HAS_BCOPY) || !defined(HAS_SAFE_BCOPY)
972 my_bcopy(from,to,len)
979 if (from - to >= 0) {
993 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1009 my_memcmp(s1,s2,len)
1010 register unsigned char *s1;
1011 register unsigned char *s2;
1017 if (tmp = *s1++ - *s2++)
1022 #endif /* HAS_MEMCMP */
1027 #ifdef USE_CHAR_VSPRINTF
1032 vsprintf(dest, pat, args)
1033 char *dest, *pat, *args;
1037 fakebuf._ptr = dest;
1038 fakebuf._cnt = 32767;
1042 fakebuf._flag = _IOWRT|_IOSTRG;
1043 _doprnt(pat, args, &fakebuf); /* what a kludge */
1044 (void)putc('\0', &fakebuf);
1045 #ifdef USE_CHAR_VSPRINTF
1048 return 0; /* perl doesn't use return value */
1053 vfprintf(fd, pat, args)
1057 _doprnt(pat, args, fd);
1058 return 0; /* wrong, but perl doesn't use the return value */
1060 #endif /* HAS_VPRINTF */
1061 #endif /* I_VARARGS */
1064 * I think my_swap(), htonl() and ntohl() have never been used.
1065 * perl.h contains last-chance references to my_swap(), my_htonl()
1066 * and my_ntohl(). I presume these are the intended functions;
1067 * but htonl() and ntohl() have the wrong names. There are no
1068 * functions my_htonl() and my_ntohl() defined anywhere.
1072 #if BYTEORDER != 0x4321
1077 #if (BYTEORDER & 1) == 0
1080 result = ((s & 255) << 8) + ((s >> 8) & 255);
1093 char c[sizeof(long)];
1096 #if BYTEORDER == 0x1234
1097 u.c[0] = (l >> 24) & 255;
1098 u.c[1] = (l >> 16) & 255;
1099 u.c[2] = (l >> 8) & 255;
1103 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1104 croak("Unknown BYTEORDER\n");
1109 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1110 u.c[o & 0xf] = (l >> s) & 255;
1123 char c[sizeof(long)];
1126 #if BYTEORDER == 0x1234
1127 u.c[0] = (l >> 24) & 255;
1128 u.c[1] = (l >> 16) & 255;
1129 u.c[2] = (l >> 8) & 255;
1133 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1134 croak("Unknown BYTEORDER\n");
1141 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1142 l |= (u.c[o & 0xf] & 255) << s;
1149 #endif /* BYTEORDER != 0x4321 */
1153 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1154 * If these functions are defined,
1155 * the BYTEORDER is neither 0x1234 nor 0x4321.
1156 * However, this is not assumed.
1160 #define HTOV(name,type) \
1167 char c[sizeof(type)]; \
1171 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1172 u.c[i] = (n >> s) & 0xFF; \
1177 #define VTOH(name,type) \
1184 char c[sizeof(type)]; \
1190 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1191 n += (u.c[i] & 0xFF) << s; \
1196 #if defined(HAS_HTOVS) && !defined(htovs)
1199 #if defined(HAS_HTOVL) && !defined(htovl)
1202 #if defined(HAS_VTOHS) && !defined(vtohs)
1205 #if defined(HAS_VTOHL) && !defined(vtohl)
1209 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1216 register I32 this, that;
1219 I32 doexec = strNE(cmd,"-");
1223 this = (*mode == 'w');
1228 taint_proper("Insecure %s%s", "EXEC");
1231 while ((pid = (doexec?vfork():fork())) < 0) {
1232 if (errno != EAGAIN) {
1235 croak("Can't fork");
1246 if (p[THIS] != (*mode == 'r')) {
1247 dup2(p[THIS], *mode == 'r');
1251 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
1257 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1260 do_exec(cmd); /* may or may not use the shell */
1264 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
1265 sv_setiv(GvSV(tmpgv),(I32)getpid());
1267 hv_clear(pidstatus); /* we have no children */
1272 do_execfree(); /* free any memory malloced by child on vfork */
1274 if (p[that] < p[this]) {
1275 dup2(p[this], p[that]);
1279 sv = *av_fetch(fdpid,p[this],TRUE);
1280 (void)SvUPGRADE(sv,SVt_IV);
1283 return fdopen(p[this], mode);
1293 return popen(cmd, mode);
1297 #endif /* !DOSISH */
1304 struct stat tmpstatbuf;
1306 fprintf(stderr,"%s", s);
1307 for (fd = 0; fd < 32; fd++) {
1308 if (Fstat(fd,&tmpstatbuf) >= 0)
1309 fprintf(stderr," %d",fd);
1311 fprintf(stderr,"\n");
1320 #if defined(HAS_FCNTL) && defined(F_DUPFD)
1322 fcntl(oldfd, F_DUPFD, newfd);
1331 while ((fd = dup(oldfd)) != newfd) /* good enough for low fd's */
1334 close(fdtmp[--fdx]);
1340 #ifndef VMS /* VMS' my_pclose() is in VMS.c */
1346 void (*hstat)(), (*istat)(), (*qstat)();
1348 int (*hstat)(), (*istat)(), (*qstat)();
1354 svp = av_fetch(fdpid,fileno(ptr),TRUE);
1360 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1362 hstat = signal(SIGHUP, SIG_IGN);
1363 istat = signal(SIGINT, SIG_IGN);
1364 qstat = signal(SIGQUIT, SIG_IGN);
1365 pid = wait4pid(pid, &status, 0);
1366 signal(SIGHUP, hstat);
1367 signal(SIGINT, istat);
1368 signal(SIGQUIT, qstat);
1369 return(pid < 0 ? pid : status);
1373 wait4pid(pid,statusp,flags)
1385 sprintf(spid, "%d", pid);
1386 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1387 if (svp && *svp != &sv_undef) {
1388 *statusp = SvIVX(*svp);
1389 hv_delete(pidstatus,spid,strlen(spid));
1396 hv_iterinit(pidstatus);
1397 if (entry = hv_iternext(pidstatus)) {
1398 pid = atoi(hv_iterkey(entry,(I32*)statusp));
1399 sv = hv_iterval(pidstatus,entry);
1400 *statusp = SvIVX(sv);
1401 sprintf(spid, "%d", pid);
1402 hv_delete(pidstatus,spid,strlen(spid));
1407 return waitpid(pid,statusp,flags);
1410 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1415 croak("Can't do waitpid with flags");
1417 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1418 pidgone(result,*statusp);
1427 #endif /* !DOSISH */
1438 sprintf(spid, "%d", pid);
1439 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1440 (void)SvUPGRADE(sv,SVt_IV);
1456 repeatcpy(to,from,len,count)
1458 register char *from;
1463 register char *frombase = from;
1471 while (count-- > 0) {
1472 for (todo = len; todo > 0; todo--) {
1479 #ifndef CASTNEGFLOAT
1487 # define BIGDOUBLE 2147483648.0
1489 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1492 return (unsigned long)f;
1494 return (unsigned long)along;
1504 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit int's ! */
1505 # define BIGNEGDOUBLE (-2147483648.0)
1507 return (I32)fmod(f, BIGDOUBLE);
1508 if (f <= BIGNEGDOUBLE)
1509 return (I32)fmod(f, BIGNEGDOUBLE);
1513 # undef BIGNEGDOUBLE
1519 /* XXX This should be fixed. It assumes 32 bit IV's. */
1520 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit IV's ! */
1521 # define BIGNEGDOUBLE (-2147483648.0)
1523 return (IV)fmod(f, BIGDOUBLE);
1524 if (f <= BIGNEGDOUBLE)
1525 return (IV)fmod(f, BIGNEGDOUBLE);
1529 # undef BIGNEGDOUBLE
1538 char *fa = strrchr(a,'/');
1539 char *fb = strrchr(b,'/');
1540 struct stat tmpstatbuf1;
1541 struct stat tmpstatbuf2;
1543 #define MAXPATHLEN 1024
1545 char tmpbuf[MAXPATHLEN+1];
1560 strncpy(tmpbuf, a, fa - a);
1561 if (Stat(tmpbuf, &tmpstatbuf1) < 0)
1566 strncpy(tmpbuf, b, fb - b);
1567 if (Stat(tmpbuf, &tmpstatbuf2) < 0)
1569 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1570 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1572 #endif /* !HAS_RENAME */
1575 scan_oct(start, len, retlen)
1580 register char *s = start;
1581 register unsigned long retval = 0;
1583 while (len-- && *s >= '0' && *s <= '7') {
1585 retval |= *s++ - '0';
1587 *retlen = s - start;
1592 scan_hex(start, len, retlen)
1597 register char *s = start;
1598 register unsigned long retval = 0;
1601 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1603 retval |= (tmp - hexdigit) & 15;
1606 *retlen = s - start;