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 table = (unsigned char*)(SvPVX(sv) + len + 1);
367 for (i = 0; i < 256; i++) {
371 while (s >= (unsigned char*)(SvPVX(sv)))
373 if (table[*s] == len) {
376 table[*s] = table[fold[*s]] = i;
390 sv_upgrade(sv, SVt_PVBM);
391 sv_magic(sv, Nullsv, 'B', Nullch, 0); /* deep magic */
394 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
396 register U32 tmp, foldtmp;
398 for (i = 0; i < len; i++) {
400 foldtmp=freq[fold[s[i]]];
401 if (tmp < frequency && foldtmp < frequency) {
403 /* choose most frequent among the two */
404 frequency = (tmp > foldtmp) ? tmp : foldtmp;
409 for (i = 0; i < len; i++) {
410 if (freq[s[i]] < frequency) {
412 frequency = freq[s[i]];
416 BmRARE(sv) = s[rarest];
417 BmPREVIOUS(sv) = rarest;
418 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
422 fbm_instr(big, bigend, littlestr)
424 register unsigned char *bigend;
427 register unsigned char *s;
429 register I32 littlelen;
430 register unsigned char *little;
431 register unsigned char *table;
432 register unsigned char *olds;
433 register unsigned char *oldlittle;
435 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
437 char *l = SvPV(littlestr,len);
440 return ninstr((char*)big,(char*)bigend, l, l + len);
443 littlelen = SvCUR(littlestr);
444 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
445 if (littlelen > bigend - big)
447 little = (unsigned char*)SvPVX(littlestr);
448 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
449 big = bigend - littlelen; /* just start near end */
450 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
454 s = bigend - littlelen;
455 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
456 return (char*)s; /* how sweet it is */
457 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
460 if (*s == *little && bcmp((char*)s,(char*)little,littlelen)==0)
466 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
467 if (--littlelen >= bigend - big)
470 oldlittle = little = table - 2;
471 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
475 if (tmp = table[*s]) {
477 if (bigend - s > tmp) {
482 if ((s += tmp) < bigend)
488 tmp = littlelen; /* less expensive than calling strncmp() */
491 if (*--s == *--little || fold[*s] == *little)
493 s = olds + 1; /* here we pay the price for failure */
495 if (s < bigend) /* fake up continue to outer loop */
507 if (tmp = table[*s]) {
509 if (bigend - s > tmp) {
514 if ((s += tmp) < bigend)
520 tmp = littlelen; /* less expensive than calling strncmp() */
523 if (*--s == *--little)
525 s = olds + 1; /* here we pay the price for failure */
527 if (s < bigend) /* fake up continue to outer loop */
539 screaminstr(bigstr, littlestr)
543 register unsigned char *s, *x;
544 register unsigned char *big;
546 register I32 previous;
548 register unsigned char *little;
549 register unsigned char *bigend;
550 register unsigned char *littleend;
552 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
554 little = (unsigned char *)(SvPVX(littlestr));
555 littleend = little + SvCUR(littlestr);
557 previous = BmPREVIOUS(littlestr);
558 big = (unsigned char *)(SvPVX(bigstr));
559 bigend = big + SvCUR(bigstr);
560 while (pos < previous) {
561 if (!(pos += screamnext[pos]))
565 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
567 if (big[pos-previous] != first && big[pos-previous] != fold[first])
569 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
572 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
578 return (char *)(big+pos-previous);
580 pos += screamnext[pos] /* does this goof up anywhere? */
585 if (big[pos-previous] != first)
587 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
596 return (char *)(big+pos-previous);
597 } while ( pos += screamnext[pos] );
599 #else /* !POINTERRIGOR */
601 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
603 if (big[pos] != first && big[pos] != fold[first])
605 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
608 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
614 return (char *)(big+pos);
616 pos += screamnext[pos] /* does this goof up anywhere? */
621 if (big[pos] != first)
623 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
632 return (char *)(big+pos);
634 pos += screamnext[pos]
637 #endif /* POINTERRIGOR */
652 if (fold[*a++] == *b++)
659 /* copy a string to a safe spot */
665 register char *newaddr;
667 New(902,newaddr,strlen(sv)+1,char);
668 (void)strcpy(newaddr,sv);
672 /* same thing but with a known length */
679 register char *newaddr;
681 New(903,newaddr,len+1,char);
682 Copy(sv,newaddr,len,char); /* might not be null terminated */
683 newaddr[len] = '\0'; /* is now */
687 #if !defined(I_STDARG) && !defined(I_VARARGS)
690 * Fallback on the old hackers way of doing varargs
695 mess(pat,a1,a2,a3,a4)
700 I32 usermess = strEQ(pat,"%s");
705 tmpstr = sv_newmortal();
706 sv_setpv(tmpstr, (char*)a1);
707 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
710 (void)sprintf(s,pat,a1,a2,a3,a4);
716 strcpy(s, " during global destruction.\n");
718 if (curcop->cop_line) {
719 (void)sprintf(s," at %s line %ld",
720 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
723 if (GvIO(last_in_gv) &&
724 IoLINES(GvIOp(last_in_gv)) ) {
725 (void)sprintf(s,", <%s> %s %ld",
726 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
727 strEQ(rs,"\n") ? "line" : "chunk",
728 (long)IoLINES(GvIOp(last_in_gv)));
731 (void)strcpy(s,".\n");
734 sv_catpv(tmpstr,buf+1);
737 return SvPVX(tmpstr);
743 void croak(pat,a1,a2,a3,a4)
750 message = mess(pat,a1,a2,a3,a4);
752 restartop = die_where(message);
755 fputs(message,stderr);
756 (void)fflush(stderr);
758 (void)UNLINK(e_tmpname);
760 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
764 void warn(pat,a1,a2,a3,a4)
770 message = mess(pat,a1,a2,a3,a4);
771 fputs(message,stderr);
775 (void)fflush(stderr);
778 #else /* !defined(I_STDARG) && !defined(I_VARARGS) */
782 mess(char *pat, va_list *args)
795 #ifdef USE_CHAR_VSPRINTF
803 usermess = strEQ(pat, "%s");
805 tmpstr = sv_newmortal();
806 sv_setpv(tmpstr, va_arg(*args, char *));
807 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
810 (void) vsprintf(s,pat,*args);
817 strcpy(s, " during global destruction.\n");
819 if (curcop->cop_line) {
820 (void)sprintf(s," at %s line %ld",
821 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
824 if (GvIO(last_in_gv) &&
825 IoLINES(GvIOp(last_in_gv)) ) {
826 (void)sprintf(s,", <%s> %s %ld",
827 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
828 strEQ(rs,"\n") ? "line" : "chunk",
829 (long)IoLINES(GvIOp(last_in_gv)));
832 (void)strcpy(s,".\n");
835 sv_catpv(tmpstr,buf+1);
839 return SvPVX(tmpstr);
846 croak(char* pat, ...)
863 message = mess(pat, &args);
866 restartop = die_where(message);
869 fputs(message,stderr);
870 (void)fflush(stderr);
872 (void)UNLINK(e_tmpname);
874 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
895 message = mess(pat, &args);
898 fputs(message,stderr);
902 (void)fflush(stderr);
904 #endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
906 #ifndef VMS /* VMS' my_setenv() is in VMS.c */
911 register I32 i=setenv_getix(nam); /* where does it go? */
913 if (environ == origenviron) { /* need we copy environment? */
919 for (max = i; environ[max]; max++) ;
920 New(901,tmpenv, max+2, char*);
921 for (j=0; j<max; j++) /* copy environment */
922 tmpenv[j] = savepv(environ[j]);
923 tmpenv[max] = Nullch;
924 environ = tmpenv; /* tell exec where it is now */
928 environ[i] = environ[i+1];
933 if (!environ[i]) { /* does not exist yet */
934 Renew(environ, i+2, char*); /* just expand it a bit */
935 environ[i+1] = Nullch; /* make sure it's null terminated */
938 Safefree(environ[i]);
939 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
941 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
943 /* MS-DOS requires environment variable names to be in uppercase */
944 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
945 * some utilities and applications may break because they only look
946 * for upper case strings. (Fixed strupr() bug here.)]
948 strcpy(environ[i],nam); strupr(environ[i]);
949 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
957 register I32 i, len = strlen(nam);
959 for (i = 0; environ[i]; i++) {
960 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
961 break; /* strnEQ must come first to avoid */
962 } /* potential SEGV's */
969 unlnk(f) /* unlink all versions of a file */
974 for (i = 0; unlink(f) >= 0; i++) ;
979 #if !defined(HAS_BCOPY) || !defined(HAS_SAFE_BCOPY)
981 my_bcopy(from,to,len)
988 if (from - to >= 0) {
1002 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1018 my_memcmp(s1,s2,len)
1019 register unsigned char *s1;
1020 register unsigned char *s2;
1026 if (tmp = *s1++ - *s2++)
1031 #endif /* HAS_MEMCMP */
1036 #ifdef USE_CHAR_VSPRINTF
1041 vsprintf(dest, pat, args)
1042 char *dest, *pat, *args;
1046 fakebuf._ptr = dest;
1047 fakebuf._cnt = 32767;
1051 fakebuf._flag = _IOWRT|_IOSTRG;
1052 _doprnt(pat, args, &fakebuf); /* what a kludge */
1053 (void)putc('\0', &fakebuf);
1054 #ifdef USE_CHAR_VSPRINTF
1057 return 0; /* perl doesn't use return value */
1062 vfprintf(fd, pat, args)
1066 _doprnt(pat, args, fd);
1067 return 0; /* wrong, but perl doesn't use the return value */
1069 #endif /* HAS_VPRINTF */
1070 #endif /* I_VARARGS */
1073 * I think my_swap(), htonl() and ntohl() have never been used.
1074 * perl.h contains last-chance references to my_swap(), my_htonl()
1075 * and my_ntohl(). I presume these are the intended functions;
1076 * but htonl() and ntohl() have the wrong names. There are no
1077 * functions my_htonl() and my_ntohl() defined anywhere.
1081 #if BYTEORDER != 0x4321
1086 #if (BYTEORDER & 1) == 0
1089 result = ((s & 255) << 8) + ((s >> 8) & 255);
1102 char c[sizeof(long)];
1105 #if BYTEORDER == 0x1234
1106 u.c[0] = (l >> 24) & 255;
1107 u.c[1] = (l >> 16) & 255;
1108 u.c[2] = (l >> 8) & 255;
1112 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1113 croak("Unknown BYTEORDER\n");
1118 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1119 u.c[o & 0xf] = (l >> s) & 255;
1132 char c[sizeof(long)];
1135 #if BYTEORDER == 0x1234
1136 u.c[0] = (l >> 24) & 255;
1137 u.c[1] = (l >> 16) & 255;
1138 u.c[2] = (l >> 8) & 255;
1142 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1143 croak("Unknown BYTEORDER\n");
1150 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1151 l |= (u.c[o & 0xf] & 255) << s;
1158 #endif /* BYTEORDER != 0x4321 */
1162 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1163 * If these functions are defined,
1164 * the BYTEORDER is neither 0x1234 nor 0x4321.
1165 * However, this is not assumed.
1169 #define HTOV(name,type) \
1176 char c[sizeof(type)]; \
1180 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1181 u.c[i] = (n >> s) & 0xFF; \
1186 #define VTOH(name,type) \
1193 char c[sizeof(type)]; \
1199 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1200 n += (u.c[i] & 0xFF) << s; \
1205 #if defined(HAS_HTOVS) && !defined(htovs)
1208 #if defined(HAS_HTOVL) && !defined(htovl)
1211 #if defined(HAS_VTOHS) && !defined(vtohs)
1214 #if defined(HAS_VTOHL) && !defined(vtohl)
1218 #if !defined(DOSISH) && !defined(VMS) /* VMS' my_popen() is in VMS.c */
1225 register I32 this, that;
1228 I32 doexec = strNE(cmd,"-");
1232 this = (*mode == 'w');
1237 taint_proper("Insecure %s%s", "EXEC");
1240 while ((pid = (doexec?vfork():fork())) < 0) {
1241 if (errno != EAGAIN) {
1244 croak("Can't fork");
1255 if (p[THIS] != (*mode == 'r')) {
1256 dup2(p[THIS], *mode == 'r');
1260 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
1266 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1269 do_exec(cmd); /* may or may not use the shell */
1273 if (tmpgv = gv_fetchpv("$",TRUE, SVt_PV))
1274 sv_setiv(GvSV(tmpgv),(I32)getpid());
1276 hv_clear(pidstatus); /* we have no children */
1281 do_execfree(); /* free any memory malloced by child on vfork */
1283 if (p[that] < p[this]) {
1284 dup2(p[this], p[that]);
1288 sv = *av_fetch(fdpid,p[this],TRUE);
1289 (void)SvUPGRADE(sv,SVt_IV);
1292 return fdopen(p[this], mode);
1302 return popen(cmd, mode);
1306 #endif /* !DOSISH */
1313 struct stat tmpstatbuf;
1315 fprintf(stderr,"%s", s);
1316 for (fd = 0; fd < 32; fd++) {
1317 if (Fstat(fd,&tmpstatbuf) >= 0)
1318 fprintf(stderr," %d",fd);
1320 fprintf(stderr,"\n");
1330 #if defined(HAS_FCNTL) && defined(F_DUPFD)
1334 return fcntl(oldfd, F_DUPFD, newfd);
1343 while ((fd = dup(oldfd)) != newfd && fd >= 0) /* good enough for low fd's */
1346 close(fdtmp[--fdx]);
1353 #ifndef VMS /* VMS' my_pclose() is in VMS.c */
1358 Signal_t (*hstat)(), (*istat)(), (*qstat)();
1363 svp = av_fetch(fdpid,fileno(ptr),TRUE);
1369 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1371 hstat = signal(SIGHUP, SIG_IGN);
1372 istat = signal(SIGINT, SIG_IGN);
1373 qstat = signal(SIGQUIT, SIG_IGN);
1374 pid = wait4pid(pid, &status, 0);
1375 signal(SIGHUP, hstat);
1376 signal(SIGINT, istat);
1377 signal(SIGQUIT, qstat);
1378 return(pid < 0 ? pid : status);
1382 wait4pid(pid,statusp,flags)
1394 sprintf(spid, "%d", pid);
1395 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1396 if (svp && *svp != &sv_undef) {
1397 *statusp = SvIVX(*svp);
1398 hv_delete(pidstatus,spid,strlen(spid));
1405 hv_iterinit(pidstatus);
1406 if (entry = hv_iternext(pidstatus)) {
1407 pid = atoi(hv_iterkey(entry,(I32*)statusp));
1408 sv = hv_iterval(pidstatus,entry);
1409 *statusp = SvIVX(sv);
1410 sprintf(spid, "%d", pid);
1411 hv_delete(pidstatus,spid,strlen(spid));
1416 return waitpid(pid,statusp,flags);
1419 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1424 croak("Can't do waitpid with flags");
1426 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1427 pidgone(result,*statusp);
1436 #endif /* !DOSISH */
1447 sprintf(spid, "%d", pid);
1448 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1449 (void)SvUPGRADE(sv,SVt_IV);
1465 repeatcpy(to,from,len,count)
1467 register char *from;
1472 register char *frombase = from;
1480 while (count-- > 0) {
1481 for (todo = len; todo > 0; todo--) {
1488 #ifndef CASTNEGFLOAT
1496 # define BIGDOUBLE 2147483648.0
1498 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1501 return (unsigned long)f;
1503 return (unsigned long)along;
1513 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit int's ! */
1514 # define BIGNEGDOUBLE (-2147483648.0)
1516 return (I32)fmod(f, BIGDOUBLE);
1517 if (f <= BIGNEGDOUBLE)
1518 return (I32)fmod(f, BIGNEGDOUBLE);
1522 # undef BIGNEGDOUBLE
1528 /* XXX This should be fixed. It assumes 32 bit IV's. */
1529 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit IV's ! */
1530 # define BIGNEGDOUBLE (-2147483648.0)
1532 return (IV)fmod(f, BIGDOUBLE);
1533 if (f <= BIGNEGDOUBLE)
1534 return (IV)fmod(f, BIGNEGDOUBLE);
1538 # undef BIGNEGDOUBLE
1547 char *fa = strrchr(a,'/');
1548 char *fb = strrchr(b,'/');
1549 struct stat tmpstatbuf1;
1550 struct stat tmpstatbuf2;
1552 #define MAXPATHLEN 1024
1554 char tmpbuf[MAXPATHLEN+1];
1569 strncpy(tmpbuf, a, fa - a);
1570 if (Stat(tmpbuf, &tmpstatbuf1) < 0)
1575 strncpy(tmpbuf, b, fb - b);
1576 if (Stat(tmpbuf, &tmpstatbuf2) < 0)
1578 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1579 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1581 #endif /* !HAS_RENAME */
1584 scan_oct(start, len, retlen)
1589 register char *s = start;
1590 register unsigned long retval = 0;
1592 while (len-- && *s >= '0' && *s <= '7') {
1594 retval |= *s++ - '0';
1596 *retlen = s - start;
1601 scan_hex(start, len, retlen)
1606 register char *s = start;
1607 register unsigned long retval = 0;
1610 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1612 retval |= (tmp - hexdigit) & 15;
1615 *retlen = s - start;
1619 /* Amazingly enough, some systems (e.g. Dynix 3) don't have fmod.
1620 This is a slow, stupid, but working emulation. (AD)
1627 double i = 0.0; /* Can't use int because it can overflow */
1628 if ((x == 0) || (y == 0))
1630 /* The sign of fmod is the same as the sign of x. */
1631 if ( (x < 0 && y > 0) || (x > 0 && y < 0) )