1 /* $RCSfile: util.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:00 $
3 * Copyright (c) 1991, 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.
9 * Revision 4.1 92/08/07 18:29:00 lwall
11 * Revision 4.0.1.6 92/06/11 21:18:47 lwall
12 * patch34: boneheaded typo in my_bcopy()
14 * Revision 4.0.1.5 92/06/08 16:08:37 lwall
15 * patch20: removed implicit int declarations on functions
16 * patch20: Perl now distinguishes overlapped copies from non-overlapped
17 * patch20: fixed confusion between a *var's real name and its effective name
18 * patch20: bcopy() and memcpy() now tested for overlap safety
19 * patch20: added Atari ST portability
21 * Revision 4.0.1.4 91/11/11 16:48:54 lwall
22 * patch19: study was busted by 4.018
23 * patch19: added little-endian pack/unpack options
25 * Revision 4.0.1.3 91/11/05 19:18:26 lwall
26 * patch11: safe malloc code now integrated into Perl's malloc when possible
27 * patch11: index("little", "longer string") could visit faraway places
28 * patch11: warn '-' x 10000 dumped core
29 * patch11: forked exec on non-existent program now issues a warning
31 * Revision 4.0.1.2 91/06/07 12:10:42 lwall
32 * patch4: new copyright notice
33 * patch4: made some allowances for "semi-standard" C
34 * patch4: index() could blow up searching for null string
35 * patch4: taintchecks could improperly modify parent in vfork()
36 * patch4: exec would close files even if you cleared close-on-exec flag
38 * Revision 4.0.1.1 91/04/12 09:19:25 lwall
39 * patch1: random cleanup in cpp namespace
41 * Revision 4.0 91/03/20 01:56:39 lwall
50 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
66 # include <sys/file.h>
73 /* paranoid version of malloc */
75 /* NOTE: Do not call the next three routines directly. Use the macros
76 * in handy.h, so that we can easily redefine everything to do tracking of
77 * allocated hunks back to the original New to track down any memory leaks.
91 #endif /* ! STANDARD_C */
95 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
101 fatal("panic: malloc");
103 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
104 #if !(defined(I286) || defined(atarist))
105 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
107 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
114 fputs(no_mem,stderr) FLUSH;
120 /* paranoid version of realloc */
123 saferealloc(where,size)
134 #endif /* ! STANDARD_C */
138 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
143 fatal("Null realloc");
146 fatal("panic: realloc");
148 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
150 #if !(defined(I286) || defined(atarist))
152 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
153 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
157 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
158 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
167 fputs(no_mem,stderr) FLUSH;
173 /* safe version of free */
179 #if !(defined(I286) || defined(atarist))
180 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
182 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
190 #endif /* !safemalloc */
194 #define ALIGN sizeof(long)
201 register char *where;
203 where = safemalloc(size + ALIGN);
207 return where + ALIGN;
211 safexrealloc(where,size)
215 return saferealloc(where - ALIGN, size + ALIGN) + ALIGN;
227 x = where[0] + 100 * where[1];
237 for (i = 0; i < MAXXCOUNT; i++) {
238 if (xcount[i] > lastxcount[i]) {
239 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
240 lastxcount[i] = xcount[i];
245 #endif /* LEAKTEST */
247 /* copy a string up to some (non-backslashed) delimiter, if any */
250 cpytill(to,from,fromend,delim,retlen)
253 register char *fromend;
259 for (; from < fromend; from++,to++) {
261 if (from[1] == delim)
263 else if (from[1] == '\\')
266 else if (*from == delim)
271 *retlen = to - origto;
275 /* return ptr to little string in big string, NULL if not found */
276 /* This routine was donated by Corey Satten. */
281 register char *little;
283 register char *s, *x;
294 for (x=big,s=little; *s; /**/ ) {
308 /* same as instr but allow embedded nulls */
311 ninstr(big, bigend, little, lend)
313 register char *bigend;
317 register char *s, *x;
318 register I32 first = *little;
319 register char *littleend = lend;
321 if (!first && little > littleend)
323 if (bigend - big < littleend - little)
325 bigend -= littleend - little++;
326 while (big <= bigend) {
329 for (x=big,s=little; s < littleend; /**/ ) {
341 /* reverse of the above--find last substring */
344 rninstr(big, bigend, little, lend)
350 register char *bigbeg;
351 register char *s, *x;
352 register I32 first = *little;
353 register char *littleend = lend;
355 if (!first && little > littleend)
358 big = bigend - (littleend - little++);
359 while (big >= bigbeg) {
362 for (x=big+2,s=little; s < littleend; /**/ ) {
375 fbm_compile(sv, iflag)
379 register unsigned char *s;
380 register unsigned char *table;
382 register U32 len = SvCUR(sv);
387 table = (unsigned char*)(SvPV(sv) + len + 1);
389 for (i = 0; i < 256; i++) {
393 while (s >= (unsigned char*)(SvPV(sv)))
395 if (table[*s] == len) {
398 table[*s] = table[fold[*s]] = i;
412 sv_upgrade(sv, SVt_PVBM);
413 sv_magic(sv, 0, 'B', 0, 0); /* deep magic */
416 s = (unsigned char*)(SvPV(sv)); /* deeper magic */
418 register U32 tmp, foldtmp;
420 for (i = 0; i < len; i++) {
422 foldtmp=freq[fold[s[i]]];
423 if (tmp < frequency && foldtmp < frequency) {
425 /* choose most frequent among the two */
426 frequency = (tmp > foldtmp) ? tmp : foldtmp;
431 for (i = 0; i < len; i++) {
432 if (freq[s[i]] < frequency) {
434 frequency = freq[s[i]];
438 BmRARE(sv) = s[rarest];
439 BmPREVIOUS(sv) = rarest;
440 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
444 fbm_instr(big, bigend, littlestr)
446 register unsigned char *bigend;
449 register unsigned char *s;
451 register I32 littlelen;
452 register unsigned char *little;
453 register unsigned char *table;
454 register unsigned char *olds;
455 register unsigned char *oldlittle;
457 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
458 if (!SvPOK(littlestr) || !SvPV(littlestr))
460 return ninstr((char*)big,(char*)bigend,
461 SvPV(littlestr), SvPV(littlestr) + SvCUR(littlestr));
464 littlelen = SvCUR(littlestr);
465 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
466 if (littlelen > bigend - big)
468 little = (unsigned char*)SvPV(littlestr);
469 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
470 big = bigend - littlelen; /* just start near end */
471 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
475 s = bigend - littlelen;
476 if (*s == *little && bcmp(s,little,littlelen)==0)
477 return (char*)s; /* how sweet it is */
478 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
481 if (*s == *little && bcmp(s,little,littlelen)==0)
487 table = (unsigned char*)(SvPV(littlestr) + littlelen + 1);
488 if (--littlelen >= bigend - big)
491 oldlittle = little = table - 2;
492 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
496 if (tmp = table[*s]) {
498 if (bigend - s > tmp) {
503 if ((s += tmp) < bigend)
509 tmp = littlelen; /* less expensive than calling strncmp() */
512 if (*--s == *--little || fold[*s] == *little)
514 s = olds + 1; /* here we pay the price for failure */
516 if (s < bigend) /* fake up continue to outer loop */
528 if (tmp = table[*s]) {
530 if (bigend - s > tmp) {
535 if ((s += tmp) < bigend)
541 tmp = littlelen; /* less expensive than calling strncmp() */
544 if (*--s == *--little)
546 s = olds + 1; /* here we pay the price for failure */
548 if (s < bigend) /* fake up continue to outer loop */
560 screaminstr(bigstr, littlestr)
564 register unsigned char *s, *x;
565 register unsigned char *big;
567 register I32 previous;
569 register unsigned char *little;
570 register unsigned char *bigend;
571 register unsigned char *littleend;
573 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
575 little = (unsigned char *)(SvPV(littlestr));
576 littleend = little + SvCUR(littlestr);
578 previous = BmPREVIOUS(littlestr);
579 big = (unsigned char *)(SvPV(bigstr));
580 bigend = big + SvCUR(bigstr);
581 while (pos < previous) {
582 if (!(pos += screamnext[pos]))
586 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
588 if (big[pos-previous] != first && big[pos-previous] != fold[first])
590 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
593 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
599 return (char *)(big+pos-previous);
601 pos += screamnext[pos] /* does this goof up anywhere? */
606 if (big[pos-previous] != first)
608 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
617 return (char *)(big+pos-previous);
618 } while ( pos += screamnext[pos] );
620 #else /* !POINTERRIGOR */
622 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
624 if (big[pos] != first && big[pos] != fold[first])
626 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
629 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
635 return (char *)(big+pos);
637 pos += screamnext[pos] /* does this goof up anywhere? */
642 if (big[pos] != first)
644 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
653 return (char *)(big+pos);
655 pos += screamnext[pos]
658 #endif /* POINTERRIGOR */
673 if (fold[*a++] == *b++)
680 /* copy a string to a safe spot */
686 register char *newaddr;
688 New(902,newaddr,strlen(sv)+1,char);
689 (void)strcpy(newaddr,sv);
693 /* same thing but with a known length */
700 register char *newaddr;
702 New(903,newaddr,len+1,char);
703 Copy(sv,newaddr,len,char); /* might not be null terminated */
704 newaddr[len] = '\0'; /* is now */
708 /* grow a static string to at least a certain length */
711 pv_grow(strptr,curlen,newlen)
716 if (newlen > *curlen) { /* need more room? */
718 Renew(*strptr,newlen,char);
720 New(905,*strptr,newlen,char);
728 mess(pat,a1,a2,a3,a4)
733 I32 usermess = strEQ(pat,"%s");
738 tmpstr = sv_mortalcopy(&sv_undef);
739 sv_setpv(tmpstr, (char*)a1);
740 *s++ = SvPV(tmpstr)[SvCUR(tmpstr)-1];
743 (void)sprintf(s,pat,a1,a2,a3,a4);
748 if (curcop->cop_line) {
749 (void)sprintf(s," at %s line %ld",
750 SvPV(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
755 GvIO(last_in_gv)->lines ) {
756 (void)sprintf(s,", <%s> %s %ld",
757 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
758 strEQ(rs,"\n") ? "line" : "chunk",
759 (long)GvIO(last_in_gv)->lines);
762 (void)strcpy(s,".\n");
764 sv_catpv(tmpstr,buf+1);
773 void fatal(pat,a1,a2,a3,a4)
780 message = mess(pat,a1,a2,a3,a4);
782 fputs(message,stderr);
783 (void)fflush(stderr);
785 (void)UNLINK(e_tmpname);
787 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
791 void warn(pat,a1,a2,a3,a4)
797 message = mess(pat,a1,a2,a3,a4);
798 fputs(message,stderr);
802 (void)fflush(stderr);
822 pat = va_arg(args, char *);
824 usermess = strEQ(pat, "%s");
826 tmpstr = sv_mortalcopy(&sv_undef);
827 sv_setpv(tmpstr, va_arg(args, char *));
828 *s++ = SvPV(tmpstr)[SvCUR(tmpstr)-1];
831 (void) vsprintf(s,pat,args);
836 if (curcop->cop_line) {
837 (void)sprintf(s," at %s line %ld",
838 SvPV(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
843 GvIO(last_in_gv)->lines ) {
844 (void)sprintf(s,", <%s> %s %ld",
845 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
846 strEQ(rs,"\n") ? "line" : "chunk",
847 (long)GvIO(last_in_gv)->lines);
850 (void)strcpy(s,".\n");
852 sv_catpv(tmpstr,buf+1);
871 message = mess(args);
873 if (restartop = die_where(message))
875 fputs(message,stderr);
876 (void)fflush(stderr);
878 (void)UNLINK(e_tmpname);
880 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
891 message = mess(args);
894 fputs(message,stderr);
898 (void)fflush(stderr);
906 register I32 i=setenv_getix(nam); /* where does it go? */
908 if (environ == origenviron) { /* need we copy environment? */
914 for (max = i; environ[max]; max++) ;
915 New(901,tmpenv, max+2, char*);
916 for (j=0; j<max; j++) /* copy environment */
917 tmpenv[j] = savestr(environ[j]);
918 tmpenv[max] = Nullch;
919 environ = tmpenv; /* tell exec where it is now */
923 environ[i] = environ[i+1];
928 if (!environ[i]) { /* does not exist yet */
929 Renew(environ, i+2, char*); /* just expand it a bit */
930 environ[i+1] = Nullch; /* make sure it's null terminated */
933 Safefree(environ[i]);
934 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
936 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
938 /* MS-DOS requires environment variable names to be in uppercase */
939 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
940 * some utilities and applications may break because they only look
941 * for upper case strings. (Fixed strupr() bug here.)]
943 strcpy(environ[i],nam); strupr(environ[i]);
944 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
952 register I32 i, len = strlen(nam);
954 for (i = 0; environ[i]; i++) {
955 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
956 break; /* strnEQ must come first to avoid */
957 } /* potential SEGV's */
963 unlnk(f) /* unlink all versions of a file */
968 for (i = 0; unlink(f) >= 0; i++) ;
973 #if !defined(HAS_BCOPY) || !defined(SAFE_BCOPY)
975 my_bcopy(from,to,len)
982 if (from - to >= 0) {
996 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1012 my_memcmp(s1,s2,len)
1013 register unsigned char *s1;
1014 register unsigned char *s2;
1020 if (tmp = *s1++ - *s2++)
1025 #endif /* HAS_MEMCMP */
1035 vsprintf(dest, pat, args)
1036 char *dest, *pat, *args;
1040 fakebuf._ptr = dest;
1041 fakebuf._cnt = 32767;
1045 fakebuf._flag = _IOWRT|_IOSTRG;
1046 _doprnt(pat, args, &fakebuf); /* what a kludge */
1047 (void)putc('\0', &fakebuf);
1051 return 0; /* perl doesn't use return value */
1056 vfprintf(fd, pat, args)
1060 _doprnt(pat, args, fd);
1061 return 0; /* wrong, but perl doesn't use the return value */
1063 #endif /* HAS_VPRINTF */
1064 #endif /* I_VARARGS */
1067 * I think my_swap(), htonl() and ntohl() have never been used.
1068 * perl.h contains last-chance references to my_swap(), my_htonl()
1069 * and my_ntohl(). I presume these are the intended functions;
1070 * but htonl() and ntohl() have the wrong names. There are no
1071 * functions my_htonl() and my_ntohl() defined anywhere.
1075 #if BYTEORDER != 0x4321
1080 #if (BYTEORDER & 1) == 0
1083 result = ((s & 255) << 8) + ((s >> 8) & 255);
1096 char c[sizeof(long)];
1099 #if BYTEORDER == 0x1234
1100 u.c[0] = (l >> 24) & 255;
1101 u.c[1] = (l >> 16) & 255;
1102 u.c[2] = (l >> 8) & 255;
1106 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1107 fatal("Unknown BYTEORDER\n");
1112 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1113 u.c[o & 0xf] = (l >> s) & 255;
1126 char c[sizeof(long)];
1129 #if BYTEORDER == 0x1234
1130 u.c[0] = (l >> 24) & 255;
1131 u.c[1] = (l >> 16) & 255;
1132 u.c[2] = (l >> 8) & 255;
1136 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1137 fatal("Unknown BYTEORDER\n");
1144 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1145 l |= (u.c[o & 0xf] & 255) << s;
1152 #endif /* BYTEORDER != 0x4321 */
1156 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1157 * If these functions are defined,
1158 * the BYTEORDER is neither 0x1234 nor 0x4321.
1159 * However, this is not assumed.
1163 #define HTOV(name,type) \
1170 char c[sizeof(type)]; \
1174 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1175 u.c[i] = (n >> s) & 0xFF; \
1180 #define VTOH(name,type) \
1187 char c[sizeof(type)]; \
1193 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1194 n += (u.c[i] & 0xFF) << s; \
1199 #if defined(HAS_HTOVS) && !defined(htovs)
1202 #if defined(HAS_HTOVL) && !defined(htovl)
1205 #if defined(HAS_VTOHS) && !defined(vtohs)
1208 #if defined(HAS_VTOHL) && !defined(vtohl)
1219 register I32 this, that;
1222 I32 doexec = strNE(cmd,"-");
1226 this = (*mode == 'w');
1231 TAINT_PROPER("exec");
1234 while ((pid = (doexec?vfork():fork())) < 0) {
1235 if (errno != EAGAIN) {
1238 fatal("Can't fork");
1249 if (p[THIS] != (*mode == 'r')) {
1250 dup2(p[THIS], *mode == 'r');
1254 #if !defined(HAS_FCNTL) || !defined(FFt_SETFD)
1260 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1263 do_exec(cmd); /* may or may not use the shell */
1264 warn("Can't exec \"%s\": %s", cmd, strerror(errno));
1268 if (tmpgv = gv_fetchpv("$",allgvs))
1269 sv_setiv(GvSV(tmpgv),(I32)getpid());
1271 hv_clear(pidstatus, FALSE); /* we have no children */
1276 do_execfree(); /* free any memory malloced by child on vfork */
1278 if (p[that] < p[this]) {
1279 dup2(p[this], p[that]);
1283 sv = *av_fetch(fdpid,p[this],TRUE);
1284 SvUPGRADE(sv,SVt_IV);
1287 return fdopen(p[this], mode);
1297 return popen(cmd, mode);
1301 #endif /* !DOSISH */
1308 struct stat tmpstatbuf;
1310 fprintf(stderr,"%s", s);
1311 for (fd = 0; fd < 32; fd++) {
1312 if (fstat(fd,&tmpstatbuf) >= 0)
1313 fprintf(stderr," %d",fd);
1315 fprintf(stderr,"\n");
1324 #if defined(HAS_FCNTL) && defined(FFt_DUPFD)
1326 fcntl(oldfd, FFt_DUPFD, newfd);
1335 while ((fd = dup(oldfd)) != newfd) /* good enough for low fd's */
1338 close(fdtmp[--fdx]);
1349 void (*hstat)(), (*istat)(), (*qstat)();
1351 int (*hstat)(), (*istat)(), (*qstat)();
1357 sv = *av_fetch(fdpid,fileno(ptr),TRUE);
1359 av_store(fdpid,fileno(ptr),Nullsv);
1362 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1364 hstat = signal(SIGHUP, SIG_IGN);
1365 istat = signal(SIGINT, SIG_IGN);
1366 qstat = signal(SIGQUIT, SIG_IGN);
1367 pid = wait4pid(pid, &status, 0);
1368 signal(SIGHUP, hstat);
1369 signal(SIGINT, istat);
1370 signal(SIGQUIT, qstat);
1371 return(pid < 0 ? pid : status);
1375 wait4pid(pid,statusp,flags)
1388 sprintf(spid, "%d", pid);
1389 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1390 if (svp && *svp != &sv_undef) {
1391 *statusp = SvIV(*svp);
1392 hv_delete(pidstatus,spid,strlen(spid));
1399 hv_iterinit(pidstatus);
1400 if (entry = hv_iternext(pidstatus)) {
1401 pid = atoi(hv_iterkey(entry,statusp));
1402 sv = hv_iterval(pidstatus,entry);
1403 *statusp = SvIV(sv);
1404 sprintf(spid, "%d", pid);
1405 hv_delete(pidstatus,spid,strlen(spid));
1410 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1413 return waitpid(pid,statusp,flags);
1416 fatal("Can't do waitpid with flags");
1418 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1419 pidgone(result,*statusp);
1427 #endif /* !DOSISH */
1438 sprintf(spid, "%d", pid);
1439 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1440 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 char *fa = rindex(a,'/');
1505 char *fb = rindex(b,'/');
1506 struct stat tmpstatbuf1;
1507 struct stat tmpstatbuf2;
1509 #define MAXPATHLEN 1024
1511 char tmpbuf[MAXPATHLEN+1];
1526 strncpy(tmpbuf, a, fa - a);
1527 if (stat(tmpbuf, &tmpstatbuf1) < 0)
1532 strncpy(tmpbuf, b, fb - b);
1533 if (stat(tmpbuf, &tmpstatbuf2) < 0)
1535 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1536 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1538 #endif /* !HAS_RENAME */
1541 scan_oct(start, len, retlen)
1546 register char *s = start;
1547 register unsigned long retval = 0;
1549 while (len-- && *s >= '0' && *s <= '7') {
1551 retval |= *s++ - '0';
1553 *retlen = s - start;
1558 scan_hex(start, len, retlen)
1563 register char *s = start;
1564 register unsigned long retval = 0;
1567 while (len-- && *s && (tmp = index(hexdigit, *s))) {
1569 retval |= (tmp - hexdigit) & 15;
1572 *retlen = s - start;