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: strchr("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: strchr() 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)
74 # include <sys/file.h>
81 /* paranoid version of malloc */
83 /* NOTE: Do not call the next three routines directly. Use the macros
84 * in handy.h, so that we can easily redefine everything to do tracking of
85 * allocated hunks back to the original New to track down any memory leaks.
99 #endif /* ! STANDARD_C */
103 fprintf(stderr, "Allocation too large: %lx\n", size) FLUSH;
109 croak("panic: malloc");
111 ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */
112 #if !(defined(I286) || defined(atarist))
113 DEBUG_m(fprintf(stderr,"0x%x: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
115 DEBUG_m(fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",ptr,an++,(long)size));
122 fputs(no_mem,stderr) FLUSH;
128 /* paranoid version of realloc */
131 saferealloc(where,size)
142 #endif /* ! STANDARD_C */
146 fprintf(stderr, "Reallocation too large: %lx\n", size) FLUSH;
151 croak("Null realloc");
154 croak("panic: realloc");
156 ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */
158 #if !(defined(I286) || defined(atarist))
160 fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++);
161 fprintf(stderr,"0x%x: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
165 fprintf(stderr,"0x%lx: (%05d) rfree\n",where,an++);
166 fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",ptr,an++,(long)size);
175 fputs(no_mem,stderr) FLUSH;
181 /* safe version of free */
187 #if !(defined(I286) || defined(atarist))
188 DEBUG_m( fprintf(stderr,"0x%x: (%05d) free\n",where,an++));
190 DEBUG_m( fprintf(stderr,"0x%lx: (%05d) free\n",where,an++));
198 #endif /* !safemalloc */
202 #define ALIGN sizeof(long)
209 register char *where;
211 where = safemalloc(size + ALIGN);
215 return where + ALIGN;
219 safexrealloc(where,size)
223 return saferealloc(where - ALIGN, size + ALIGN) + ALIGN;
235 x = where[0] + 100 * where[1];
245 for (i = 0; i < MAXXCOUNT; i++) {
246 if (xcount[i] > lastxcount[i]) {
247 fprintf(stderr,"%2d %2d\t%ld\n", i / 100, i % 100, xcount[i]);
248 lastxcount[i] = xcount[i];
253 #endif /* LEAKTEST */
255 /* copy a string up to some (non-backslashed) delimiter, if any */
258 cpytill(to,from,fromend,delim,retlen)
261 register char *fromend;
267 for (; from < fromend; from++,to++) {
269 if (from[1] == delim)
271 else if (from[1] == '\\')
274 else if (*from == delim)
279 *retlen = to - origto;
283 /* return ptr to little string in big string, NULL if not found */
284 /* This routine was donated by Corey Satten. */
289 register char *little;
291 register char *s, *x;
302 for (x=big,s=little; *s; /**/ ) {
316 /* same as instr but allow embedded nulls */
319 ninstr(big, bigend, little, lend)
321 register char *bigend;
325 register char *s, *x;
326 register I32 first = *little;
327 register char *littleend = lend;
329 if (!first && little > littleend)
331 if (bigend - big < littleend - little)
333 bigend -= littleend - little++;
334 while (big <= bigend) {
337 for (x=big,s=little; s < littleend; /**/ ) {
349 /* reverse of the above--find last substring */
352 rninstr(big, bigend, little, lend)
358 register char *bigbeg;
359 register char *s, *x;
360 register I32 first = *little;
361 register char *littleend = lend;
363 if (!first && little > littleend)
366 big = bigend - (littleend - little++);
367 while (big >= bigbeg) {
370 for (x=big+2,s=little; s < littleend; /**/ ) {
383 fbm_compile(sv, iflag)
387 register unsigned char *s;
388 register unsigned char *table;
390 register U32 len = SvCUR(sv);
395 table = (unsigned char*)(SvPVX(sv) + len + 1);
397 for (i = 0; i < 256; i++) {
401 while (s >= (unsigned char*)(SvPVX(sv)))
403 if (table[*s] == len) {
406 table[*s] = table[fold[*s]] = i;
420 sv_upgrade(sv, SVt_PVBM);
421 sv_magic(sv, 0, 'B', 0, 0); /* deep magic */
424 s = (unsigned char*)(SvPVX(sv)); /* deeper magic */
426 register U32 tmp, foldtmp;
428 for (i = 0; i < len; i++) {
430 foldtmp=freq[fold[s[i]]];
431 if (tmp < frequency && foldtmp < frequency) {
433 /* choose most frequent among the two */
434 frequency = (tmp > foldtmp) ? tmp : foldtmp;
439 for (i = 0; i < len; i++) {
440 if (freq[s[i]] < frequency) {
442 frequency = freq[s[i]];
446 BmRARE(sv) = s[rarest];
447 BmPREVIOUS(sv) = rarest;
448 DEBUG_r(fprintf(stderr,"rarest char %c at %d\n",BmRARE(sv),BmPREVIOUS(sv)));
452 fbm_instr(big, bigend, littlestr)
454 register unsigned char *bigend;
457 register unsigned char *s;
459 register I32 littlelen;
460 register unsigned char *little;
461 register unsigned char *table;
462 register unsigned char *olds;
463 register unsigned char *oldlittle;
465 if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) {
466 if (!SvPOK(littlestr) || !SvPVX(littlestr))
468 return ninstr((char*)big,(char*)bigend,
469 SvPVX(littlestr), SvPVX(littlestr) + SvCUR(littlestr));
472 littlelen = SvCUR(littlestr);
473 if (SvTAIL(littlestr) && !multiline) { /* tail anchored? */
474 if (littlelen > bigend - big)
476 little = (unsigned char*)SvPVX(littlestr);
477 if (SvCASEFOLD(littlestr)) { /* oops, fake it */
478 big = bigend - littlelen; /* just start near end */
479 if (bigend[-1] == '\n' && little[littlelen-1] != '\n')
483 s = bigend - littlelen;
484 if (*s == *little && bcmp(s,little,littlelen)==0)
485 return (char*)s; /* how sweet it is */
486 else if (bigend[-1] == '\n' && little[littlelen-1] != '\n'
489 if (*s == *little && bcmp(s,little,littlelen)==0)
495 table = (unsigned char*)(SvPVX(littlestr) + littlelen + 1);
496 if (--littlelen >= bigend - big)
499 oldlittle = little = table - 2;
500 if (SvCASEFOLD(littlestr)) { /* case insensitive? */
504 if (tmp = table[*s]) {
506 if (bigend - s > tmp) {
511 if ((s += tmp) < bigend)
517 tmp = littlelen; /* less expensive than calling strncmp() */
520 if (*--s == *--little || fold[*s] == *little)
522 s = olds + 1; /* here we pay the price for failure */
524 if (s < bigend) /* fake up continue to outer loop */
536 if (tmp = table[*s]) {
538 if (bigend - s > tmp) {
543 if ((s += tmp) < bigend)
549 tmp = littlelen; /* less expensive than calling strncmp() */
552 if (*--s == *--little)
554 s = olds + 1; /* here we pay the price for failure */
556 if (s < bigend) /* fake up continue to outer loop */
568 screaminstr(bigstr, littlestr)
572 register unsigned char *s, *x;
573 register unsigned char *big;
575 register I32 previous;
577 register unsigned char *little;
578 register unsigned char *bigend;
579 register unsigned char *littleend;
581 if ((pos = screamfirst[BmRARE(littlestr)]) < 0)
583 little = (unsigned char *)(SvPVX(littlestr));
584 littleend = little + SvCUR(littlestr);
586 previous = BmPREVIOUS(littlestr);
587 big = (unsigned char *)(SvPVX(bigstr));
588 bigend = big + SvCUR(bigstr);
589 while (pos < previous) {
590 if (!(pos += screamnext[pos]))
594 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
596 if (big[pos-previous] != first && big[pos-previous] != fold[first])
598 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
601 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
607 return (char *)(big+pos-previous);
609 pos += screamnext[pos] /* does this goof up anywhere? */
614 if (big[pos-previous] != first)
616 for (x=big+pos+1-previous,s=little; s < littleend; /**/ ) {
625 return (char *)(big+pos-previous);
626 } while ( pos += screamnext[pos] );
628 #else /* !POINTERRIGOR */
630 if (SvCASEFOLD(littlestr)) { /* case insignificant? */
632 if (big[pos] != first && big[pos] != fold[first])
634 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
637 if (*s++ != *x++ && fold[*(s-1)] != *(x-1)) {
643 return (char *)(big+pos);
645 pos += screamnext[pos] /* does this goof up anywhere? */
650 if (big[pos] != first)
652 for (x=big+pos+1,s=little; s < littleend; /**/ ) {
661 return (char *)(big+pos);
663 pos += screamnext[pos]
666 #endif /* POINTERRIGOR */
681 if (fold[*a++] == *b++)
688 /* copy a string to a safe spot */
694 register char *newaddr;
696 New(902,newaddr,strlen(sv)+1,char);
697 (void)strcpy(newaddr,sv);
701 /* same thing but with a known length */
708 register char *newaddr;
710 New(903,newaddr,len+1,char);
711 Copy(sv,newaddr,len,char); /* might not be null terminated */
712 newaddr[len] = '\0'; /* is now */
716 #if !defined(STANDARD_C) && !defined(I_VARARGS)
719 * Fallback on the old hackers way of doing varargs
724 mess(pat,a1,a2,a3,a4)
729 I32 usermess = strEQ(pat,"%s");
734 tmpstr = sv_newmortal();
735 sv_setpv(tmpstr, (char*)a1);
736 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
739 (void)sprintf(s,pat,a1,a2,a3,a4);
744 if (curcop->cop_line) {
745 (void)sprintf(s," at %s line %ld",
746 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
751 IoLINES(GvIO(last_in_gv)) ) {
752 (void)sprintf(s,", <%s> %s %ld",
753 last_in_gv == argvgv ? "" : GvENAME(last_in_gv),
754 strEQ(rs,"\n") ? "line" : "chunk",
755 (long)IoLINES(GvIO(last_in_gv)));
758 (void)strcpy(s,".\n");
760 sv_catpv(tmpstr,buf+1);
763 return SvPVX(tmpstr);
769 void croak(pat,a1,a2,a3,a4)
776 message = mess(pat,a1,a2,a3,a4);
777 fputs(message,stderr);
778 (void)fflush(stderr);
780 (void)UNLINK(e_tmpname);
782 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
786 void warn(pat,a1,a2,a3,a4)
792 message = mess(pat,a1,a2,a3,a4);
793 fputs(message,stderr);
797 (void)fflush(stderr);
800 #else /* !defined(STANDARD_C) && !defined(I_VARARGS) */
804 mess(char *pat, va_list args)
825 usermess = strEQ(pat, "%s");
827 tmpstr = sv_newmortal();
828 sv_setpv(tmpstr, va_arg(args, char *));
829 *s++ = SvPVX(tmpstr)[SvCUR(tmpstr)-1];
832 (void) vsprintf(s,pat,args);
838 if (curcop->cop_line) {
839 (void)sprintf(s," at %s line %ld",
840 SvPVX(GvSV(curcop->cop_filegv)), (long)curcop->cop_line);
845 IoLINES(GvIO(last_in_gv)) ) {
846 (void)sprintf(s,", <%s> %s %ld",
847 last_in_gv == argvgv ? "" : GvNAME(last_in_gv),
848 strEQ(rs,"\n") ? "line" : "chunk",
849 (long)IoLINES(GvIO(last_in_gv)));
852 (void)strcpy(s,".\n");
854 sv_catpv(tmpstr,buf+1);
858 return SvPVX(tmpstr);
865 croak(char* pat, ...)
883 message = mess(pat, args);
885 if (restartop = die_where(message))
887 fputs(message,stderr);
888 (void)fflush(stderr);
890 (void)UNLINK(e_tmpname);
892 my_exit((I32)((errno&255)?errno:((statusvalue&255)?statusvalue:255)));
913 message = mess(pat, args);
916 fputs(message,stderr);
920 (void)fflush(stderr);
922 #endif /* !defined(STANDARD_C) && !defined(I_VARARGS) */
928 register I32 i=setenv_getix(nam); /* where does it go? */
930 if (environ == origenviron) { /* need we copy environment? */
936 for (max = i; environ[max]; max++) ;
937 New(901,tmpenv, max+2, char*);
938 for (j=0; j<max; j++) /* copy environment */
939 tmpenv[j] = savestr(environ[j]);
940 tmpenv[max] = Nullch;
941 environ = tmpenv; /* tell exec where it is now */
945 environ[i] = environ[i+1];
950 if (!environ[i]) { /* does not exist yet */
951 Renew(environ, i+2, char*); /* just expand it a bit */
952 environ[i+1] = Nullch; /* make sure it's null terminated */
955 Safefree(environ[i]);
956 New(904, environ[i], strlen(nam) + strlen(val) + 2, char);
958 (void)sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
960 /* MS-DOS requires environment variable names to be in uppercase */
961 /* [Tom Dinger, 27 August 1990: Well, it doesn't _require_ it, but
962 * some utilities and applications may break because they only look
963 * for upper case strings. (Fixed strupr() bug here.)]
965 strcpy(environ[i],nam); strupr(environ[i]);
966 (void)sprintf(environ[i] + strlen(nam),"=%s",val);
974 register I32 i, len = strlen(nam);
976 for (i = 0; environ[i]; i++) {
977 if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
978 break; /* strnEQ must come first to avoid */
979 } /* potential SEGV's */
985 unlnk(f) /* unlink all versions of a file */
990 for (i = 0; unlink(f) >= 0; i++) ;
995 #if !defined(HAS_BCOPY) || !defined(SAFE_BCOPY)
997 my_bcopy(from,to,len)
1004 if (from - to >= 0) {
1012 *(--to) = *(--from);
1018 #if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
1034 my_memcmp(s1,s2,len)
1035 register unsigned char *s1;
1036 register unsigned char *s2;
1042 if (tmp = *s1++ - *s2++)
1047 #endif /* HAS_MEMCMP */
1057 vsprintf(dest, pat, args)
1058 char *dest, *pat, *args;
1062 fakebuf._ptr = dest;
1063 fakebuf._cnt = 32767;
1067 fakebuf._flag = _IOWRT|_IOSTRG;
1068 _doprnt(pat, args, &fakebuf); /* what a kludge */
1069 (void)putc('\0', &fakebuf);
1073 return 0; /* perl doesn't use return value */
1078 vfprintf(fd, pat, args)
1082 _doprnt(pat, args, fd);
1083 return 0; /* wrong, but perl doesn't use the return value */
1085 #endif /* HAS_VPRINTF */
1086 #endif /* I_VARARGS */
1089 * I think my_swap(), htonl() and ntohl() have never been used.
1090 * perl.h contains last-chance references to my_swap(), my_htonl()
1091 * and my_ntohl(). I presume these are the intended functions;
1092 * but htonl() and ntohl() have the wrong names. There are no
1093 * functions my_htonl() and my_ntohl() defined anywhere.
1097 #if BYTEORDER != 0x4321
1102 #if (BYTEORDER & 1) == 0
1105 result = ((s & 255) << 8) + ((s >> 8) & 255);
1118 char c[sizeof(long)];
1121 #if BYTEORDER == 0x1234
1122 u.c[0] = (l >> 24) & 255;
1123 u.c[1] = (l >> 16) & 255;
1124 u.c[2] = (l >> 8) & 255;
1128 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1129 croak("Unknown BYTEORDER\n");
1134 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1135 u.c[o & 0xf] = (l >> s) & 255;
1148 char c[sizeof(long)];
1151 #if BYTEORDER == 0x1234
1152 u.c[0] = (l >> 24) & 255;
1153 u.c[1] = (l >> 16) & 255;
1154 u.c[2] = (l >> 8) & 255;
1158 #if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
1159 croak("Unknown BYTEORDER\n");
1166 for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
1167 l |= (u.c[o & 0xf] & 255) << s;
1174 #endif /* BYTEORDER != 0x4321 */
1178 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
1179 * If these functions are defined,
1180 * the BYTEORDER is neither 0x1234 nor 0x4321.
1181 * However, this is not assumed.
1185 #define HTOV(name,type) \
1192 char c[sizeof(type)]; \
1196 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1197 u.c[i] = (n >> s) & 0xFF; \
1202 #define VTOH(name,type) \
1209 char c[sizeof(type)]; \
1215 for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
1216 n += (u.c[i] & 0xFF) << s; \
1221 #if defined(HAS_HTOVS) && !defined(htovs)
1224 #if defined(HAS_HTOVL) && !defined(htovl)
1227 #if defined(HAS_VTOHS) && !defined(vtohs)
1230 #if defined(HAS_VTOHL) && !defined(vtohl)
1241 register I32 this, that;
1244 I32 doexec = strNE(cmd,"-");
1248 this = (*mode == 'w');
1253 taint_proper("Insecure %s%s", "EXEC");
1256 while ((pid = (doexec?vfork():fork())) < 0) {
1257 if (errno != EAGAIN) {
1260 croak("Can't fork");
1271 if (p[THIS] != (*mode == 'r')) {
1272 dup2(p[THIS], *mode == 'r');
1276 #if !defined(HAS_FCNTL) || !defined(FFt_SETFD)
1282 for (fd = maxsysfd + 1; fd < NOFILE; fd++)
1285 do_exec(cmd); /* may or may not use the shell */
1286 warn("Can't exec \"%s\": %s", cmd, strerror(errno));
1290 if (tmpgv = gv_fetchpv("$",TRUE))
1291 sv_setiv(GvSV(tmpgv),(I32)getpid());
1293 hv_clear(pidstatus); /* we have no children */
1298 do_execfree(); /* free any memory malloced by child on vfork */
1300 if (p[that] < p[this]) {
1301 dup2(p[this], p[that]);
1305 sv = *av_fetch(fdpid,p[this],TRUE);
1306 SvUPGRADE(sv,SVt_IV);
1309 return fdopen(p[this], mode);
1319 return popen(cmd, mode);
1323 #endif /* !DOSISH */
1330 struct stat tmpstatbuf;
1332 fprintf(stderr,"%s", s);
1333 for (fd = 0; fd < 32; fd++) {
1334 if (fstat(fd,&tmpstatbuf) >= 0)
1335 fprintf(stderr," %d",fd);
1337 fprintf(stderr,"\n");
1346 #if defined(HAS_FCNTL) && defined(FFt_DUPFD)
1348 fcntl(oldfd, FFt_DUPFD, newfd);
1357 while ((fd = dup(oldfd)) != newfd) /* good enough for low fd's */
1360 close(fdtmp[--fdx]);
1371 void (*hstat)(), (*istat)(), (*qstat)();
1373 int (*hstat)(), (*istat)(), (*qstat)();
1379 sv = *av_fetch(fdpid,fileno(ptr),TRUE);
1381 av_store(fdpid,fileno(ptr),Nullsv);
1384 if(kill(pid, 0) < 0) { return(pid); } /* HOM 12/23/91 */
1386 hstat = signal(SIGHUP, SIG_IGN);
1387 istat = signal(SIGINT, SIG_IGN);
1388 qstat = signal(SIGQUIT, SIG_IGN);
1389 pid = wait4pid(pid, &status, 0);
1390 signal(SIGHUP, hstat);
1391 signal(SIGINT, istat);
1392 signal(SIGQUIT, qstat);
1393 return(pid < 0 ? pid : status);
1397 wait4pid(pid,statusp,flags)
1410 sprintf(spid, "%d", pid);
1411 svp = hv_fetch(pidstatus,spid,strlen(spid),FALSE);
1412 if (svp && *svp != &sv_undef) {
1413 *statusp = SvIVX(*svp);
1414 hv_delete(pidstatus,spid,strlen(spid));
1421 hv_iterinit(pidstatus);
1422 if (entry = hv_iternext(pidstatus)) {
1423 pid = atoi(hv_iterkey(entry,statusp));
1424 sv = hv_iterval(pidstatus,entry);
1425 *statusp = SvIVX(sv);
1426 sprintf(spid, "%d", pid);
1427 hv_delete(pidstatus,spid,strlen(spid));
1432 return wait4((pid==-1)?0:pid,statusp,flags,Null(struct rusage *));
1435 return waitpid(pid,statusp,flags);
1438 croak("Can't do waitpid with flags");
1440 while ((result = wait(statusp)) != pid && pid > 0 && result >= 0)
1441 pidgone(result,*statusp);
1449 #endif /* !DOSISH */
1460 sprintf(spid, "%d", pid);
1461 sv = *hv_fetch(pidstatus,spid,strlen(spid),TRUE);
1462 SvUPGRADE(sv,SVt_IV);
1478 repeatcpy(to,from,len,count)
1480 register char *from;
1485 register char *frombase = from;
1493 while (count-- > 0) {
1494 for (todo = len; todo > 0; todo--) {
1501 #ifndef CASTNEGFLOAT
1509 # define BIGDOUBLE 2147483648.0
1511 return (unsigned long)(f-(long)(f/BIGDOUBLE)*BIGDOUBLE)|0x80000000;
1514 return (unsigned long)f;
1516 return (unsigned long)along;
1526 # define BIGDOUBLE 2147483648.0 /* Assume 32 bit int's ! */
1527 # define BIGNEGDOUBLE (-2147483648.0)
1529 return (I32)fmod(f, BIGDOUBLE);
1530 if (f <= BIGNEGDOUBLE)
1531 return (I32)fmod(f, BIGNEGDOUBLE);
1535 # undef BIGNEGDOUBLE
1544 char *fa = strrchr(a,'/');
1545 char *fb = strrchr(b,'/');
1546 struct stat tmpstatbuf1;
1547 struct stat tmpstatbuf2;
1549 #define MAXPATHLEN 1024
1551 char tmpbuf[MAXPATHLEN+1];
1566 strncpy(tmpbuf, a, fa - a);
1567 if (stat(tmpbuf, &tmpstatbuf1) < 0)
1572 strncpy(tmpbuf, b, fb - b);
1573 if (stat(tmpbuf, &tmpstatbuf2) < 0)
1575 return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev &&
1576 tmpstatbuf1.st_ino == tmpstatbuf2.st_ino;
1578 #endif /* !HAS_RENAME */
1581 scan_oct(start, len, retlen)
1586 register char *s = start;
1587 register unsigned long retval = 0;
1589 while (len-- && *s >= '0' && *s <= '7') {
1591 retval |= *s++ - '0';
1593 *retlen = s - start;
1598 scan_hex(start, len, retlen)
1603 register char *s = start;
1604 register unsigned long retval = 0;
1607 while (len-- && *s && (tmp = strchr(hexdigit, *s))) {
1609 retval |= (tmp - hexdigit) & 15;
1612 *retlen = s - start;