diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c index 69a3c2ed8152..1fe611186e68 100644 --- a/usr.bin/locate/locate/fastfind.c +++ b/usr.bin/locate/locate/fastfind.c @@ -1,352 +1,352 @@ /* * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1995-2022 Wolfram Schneider * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * James A. Woods. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _LOCATE_STATISTIC_ #define _LOCATE_STATISTIC_ void statistic (fp, path_fcodes) FILE *fp; /* open database */ char *path_fcodes; /* for error message */ { long lines, chars, size, big, zwerg, umlaut; - register u_char *p, *s; - register int c; + u_char *p, *s; + int c; int count, longest_path; int error = 0; u_char bigram1[NBG], bigram2[NBG], path[MAXPATHLEN]; for (c = 0, p = bigram1, s = bigram2; c < NBG; c++) { p[c] = check_bigram_char(getc(fp)); s[c] = check_bigram_char(getc(fp)); } lines = chars = big = zwerg = umlaut = longest_path = 0; size = NBG + NBG; for (c = getc(fp), count = 0; c != EOF; size++) { if (c == SWITCH) { count += getwf(fp) - OFFSET; size += sizeof(int); zwerg++; } else count += c - OFFSET; if (count < 0 || count >= MAXPATHLEN) { /* stop on error and display the statstics anyway */ warnx("corrupted database: %s", path_fcodes); error = 1; break; } for (p = path + count; (c = getc(fp)) > SWITCH; size++) if (c < PARITY) { if (c == UMLAUT) { c = getc(fp); size++; umlaut++; } p++; } else { /* bigram char */ big++; p += 2; } p++; lines++; chars += (p - path); if ((p - path) > longest_path) longest_path = p - path; } (void)printf("\nDatabase: %s\n", path_fcodes); (void)printf("Compression: Front: %2.2f%%, ", (size + big - (2 * NBG)) / (chars / (float)100)); (void)printf("Bigram: %2.2f%%, ", (size - big) / (size / (float)100)); (void)printf("Total: %2.2f%%\n", (size - (2 * NBG)) / (chars / (float)100)); (void)printf("Filenames: %ld, ", lines); (void)printf("Characters: %ld, ", chars); (void)printf("Database size: %ld\n", size); (void)printf("Bigram characters: %ld, ", big); (void)printf("Integers: %ld, ", zwerg); (void)printf("8-Bit characters: %ld\n", umlaut); printf("Longest path: %d\n", longest_path - 1); /* non zero exit on corrupt database */ if (error) exit(error); } #endif /* _LOCATE_STATISTIC_ */ extern char separator; void #ifdef FF_MMAP #ifdef FF_ICASE fastfind_mmap_icase #else fastfind_mmap #endif /* FF_ICASE */ (pathpart, paddr, len, database) char *pathpart; /* search string */ caddr_t paddr; /* mmap pointer */ off_t len; /* length of database */ char *database; /* for error message */ #else /* MMAP */ #ifdef FF_ICASE fastfind_icase #else fastfind #endif /* FF_ICASE */ (fp, pathpart, database) FILE *fp; /* open database */ char *pathpart; /* search string */ char *database; /* for error message */ #endif /* MMAP */ { - register u_char *p, *s, *patend, *q, *foundchar; - register int c, cc; + u_char *p, *s, *patend, *q, *foundchar; + int c, cc; int count, found, globflag; u_char *cutoff; u_char bigram1[NBG], bigram2[NBG], path[MAXPATHLEN + 2]; #ifdef FF_ICASE /* use a lookup table for case insensitive search */ u_char table[UCHAR_MAX + 1]; tolower_word(pathpart); #endif /* FF_ICASE*/ /* init bigram table */ #ifdef FF_MMAP for (c = 0, p = bigram1, s = bigram2; c < NBG; c++, len-= 2) { p[c] = check_bigram_char(*paddr++); s[c] = check_bigram_char(*paddr++); } #else for (c = 0, p = bigram1, s = bigram2; c < NBG; c++) { p[c] = check_bigram_char(getc(fp)); s[c] = check_bigram_char(getc(fp)); } #endif /* FF_MMAP */ /* find optimal (last) char for searching */ for (p = pathpart; *p != '\0'; p++) if (strchr(LOCATE_REG, *p) != NULL) break; if (*p == '\0') globflag = 0; else globflag = 1; p = pathpart; patend = patprep(p); cc = *patend; #ifdef FF_ICASE /* set patend char to true */ for (c = 0; c < UCHAR_MAX + 1; c++) table[c] = 0; table[TOLOWER(*patend)] = 1; table[toupper(*patend)] = 1; #endif /* FF_ICASE */ /* main loop */ found = count = 0; foundchar = 0; #ifdef FF_MMAP c = (u_char)*paddr++; len--; for (; len > 0; ) { #else c = getc(fp); for (; c != EOF; ) { #endif /* FF_MMAP */ /* go forward or backward */ if (c == SWITCH) { /* big step, an integer */ #ifdef FF_MMAP if (len < sizeof(int)) errx(1, "corrupted database: %s", database); count += getwm(paddr) - OFFSET; len -= INTSIZE; paddr += INTSIZE; #else count += getwf(fp) - OFFSET; #endif /* FF_MMAP */ } else { /* slow step, =< 14 chars */ count += c - OFFSET; } if (count < 0 || count >= MAXPATHLEN) errx(1, "corrupted database: %s %d", database, count); /* overlay old path */ p = path + count; foundchar = p - 1; #ifdef FF_MMAP for (; len > 0;) { c = (u_char)*paddr++; len--; #else for (;;) { c = getc(fp); #endif /* FF_MMAP */ /* * == UMLAUT: 8 bit char followed * <= SWITCH: offset * >= PARITY: bigram * rest: single ascii char * * offset < SWITCH < UMLAUT < ascii < PARITY < bigram */ if (c < PARITY) { if (c <= UMLAUT) { if (c == UMLAUT) { #ifdef FF_MMAP c = (u_char)*paddr++; len--; #else c = getc(fp); #endif /* FF_MMAP */ } else break; /* SWITCH */ } #ifdef FF_ICASE if (table[c]) #else if (c == cc) #endif /* FF_ICASE */ foundchar = p; *p++ = c; } else { /* bigrams are parity-marked */ TO7BIT(c); #ifndef FF_ICASE if (bigram1[c] == cc || bigram2[c] == cc) #else if (table[bigram1[c]] || table[bigram2[c]]) #endif /* FF_ICASE */ foundchar = p + 1; *p++ = bigram1[c]; *p++ = bigram2[c]; } if (p - path >= MAXPATHLEN) errx(1, "corrupted database: %s", database); } if (found) { /* previous line matched */ cutoff = path; *p-- = '\0'; foundchar = p; } else if (foundchar >= path + count) { /* a char matched */ *p-- = '\0'; cutoff = path + count; } else /* nothing to do */ continue; found = 0; for (s = foundchar; s >= cutoff; s--) { if (*s == cc #ifdef FF_ICASE || TOLOWER(*s) == cc #endif /* FF_ICASE */ ) { /* fast first char check */ for (p = patend - 1, q = s - 1; *p != '\0'; p--, q--) if (*q != *p #ifdef FF_ICASE && TOLOWER(*q) != *p #endif /* FF_ICASE */ ) break; if (*p == '\0') { /* fast match success */ found = 1; if (!globflag || #ifndef FF_ICASE !fnmatch(pathpart, path, 0)) #else !fnmatch(pathpart, path, FNM_CASEFOLD)) #endif /* !FF_ICASE */ { if (f_silent) counter++; else if (f_limit) { counter++; if (f_limit >= counter) (void)printf("%s%c",path,separator); else errx(0, "[show only %ld lines]", counter - 1); } else (void)printf("%s%c",path,separator); } break; } } } } } diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c index 40e183f8d45a..0bbd95ac696d 100644 --- a/usr.bin/locate/locate/locate.c +++ b/usr.bin/locate/locate/locate.c @@ -1,337 +1,337 @@ /* * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1995-2022 Wolfram Schneider * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * James A. Woods. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1995-1996 Wolfram Schneider, Berlin.\n\ @(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)locate.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ /* * Ref: Usenix ;login:, Vol 8, No 1, February/March, 1983, p. 8. * * Locate scans a file list for the full pathname of a file given only part * of the name. The list has been processed with with "front-compression" * and bigram coding. Front compression reduces space by a factor of 4-5, * bigram coding by a further 20-25%. * * The codes are: * * 0-28 likeliest differential counts + offset to make nonnegative * 30 switch code for out-of-range count to follow in next word * 31 an 8 bit char followed * 128-255 bigram codes (128 most common, as determined by 'updatedb') * 32-127 single character (printable) ascii residue (ie, literal) * * A novel two-tiered string search technique is employed: * * First, a metacharacter-free subpattern and partial pathname is matched * BACKWARDS to avoid full expansion of the pathname list. The time savings * is 40-50% over forward matching, which cannot efficiently handle * overlapped search patterns and compressed path residue. * * Then, the actual shell glob-style regular expression (if in this form) is * matched against the candidate pathnames using the slower routines provided * in the standard 'find'. */ #include #include #include #include #include #include #include #include #include #ifdef MMAP # include # include # include # include #endif #include "locate.h" #include "pathnames.h" int f_mmap; /* use mmap */ int f_icase; /* ignore case */ int f_stdin; /* read database from stdin */ int f_statistic; /* print statistic */ int f_silent; /* suppress output, show only count of matches */ long f_limit; /* limit number of output lines, 0 == infinite */ long counter; /* counter for matches [-c] */ char separator='\n'; /* line separator */ u_char myctype[UCHAR_MAX + 1]; void usage(void); void statistic(FILE *, char *); void fastfind(FILE *, char *, char *); void fastfind_icase(FILE *, char *, char *); void fastfind_mmap(char *, caddr_t, off_t, char *); void fastfind_mmap_icase(char *, caddr_t, off_t, char *); void search_mmap(char *, char **); void search_fopen(char *, char **); unsigned long cputime(void); extern char **colon(char **, char*, char*); extern int getwm(caddr_t); extern int getwf(FILE *); extern u_char *tolower_word(u_char *); extern int check_bigram_char(int); extern char *patprep(char *); int main(int argc, char **argv) { - register int ch; + int ch; char **dbv = NULL; char *path_fcodes; /* locate database */ #ifdef MMAP f_mmap = 1; /* mmap is default */ #endif (void) setlocale(LC_ALL, ""); while ((ch = getopt(argc, argv, "0Scd:il:ms")) != -1) switch(ch) { case '0': /* 'find -print0' style */ separator = '\0'; break; case 'S': /* statistic lines */ f_statistic = 1; break; case 'l': /* limit number of output lines, 0 == infinite */ f_limit = atol(optarg); if (f_limit < 0 ) errx(1, "invalid argument for -l: '%s'", optarg); break; case 'd': /* database */ dbv = colon(dbv, optarg, _PATH_FCODES); break; case 'i': /* ignore case */ f_icase = 1; break; case 'm': /* mmap */ #ifdef MMAP f_mmap = 1; #else warnx("mmap(2) not implemented"); #endif break; case 's': /* stdio lib */ f_mmap = 0; break; case 'c': /* suppress output, show only count of matches */ f_silent = 1; break; default: usage(); } argv += optind; argc -= optind; /* to few arguments */ if (argc < 1 && !(f_statistic)) usage(); /* no (valid) database as argument */ if (dbv == NULL || *dbv == NULL) { /* try to read database from environment */ if ((path_fcodes = getenv("LOCATE_PATH")) == NULL || *path_fcodes == '\0') /* use default database */ dbv = colon(dbv, _PATH_FCODES, _PATH_FCODES); else /* $LOCATE_PATH */ dbv = colon(dbv, path_fcodes, _PATH_FCODES); } if (f_icase && UCHAR_MAX < 4096) /* init tolower lookup table */ for (ch = 0; ch < UCHAR_MAX + 1; ch++) myctype[ch] = tolower(ch); /* foreach database ... */ while((path_fcodes = *dbv) != NULL) { dbv++; if (!strcmp(path_fcodes, "-")) f_stdin = 1; else f_stdin = 0; #ifndef MMAP f_mmap = 0; /* be paranoid */ #endif if (!f_mmap || f_stdin || f_statistic) search_fopen(path_fcodes, argv); else search_mmap(path_fcodes, argv); } if (f_silent) printf("%ld\n", counter); exit(0); } /* * Arguments: * db database * s search strings */ void search_fopen(char *db, char **s) { FILE *fp; /* can only read stdin once */ if (f_stdin) { fp = stdin; if (*(s+1) != NULL) { warnx("read database from stdin, use only `%s' as pattern", *s); *(s+1) = NULL; } } else if ((fp = fopen(db, "r")) == NULL) err(1, "`%s'", db); /* count only chars or lines */ if (f_statistic) { statistic(fp, db); (void)fclose(fp); return; } /* foreach search string ... */ while(*s != NULL) { if (!f_stdin && fseek(fp, (long)0, SEEK_SET) == -1) err(1, "fseek to begin of ``%s''\n", db); if (f_icase) fastfind_icase(fp, *s, db); else fastfind(fp, *s, db); s++; } (void)fclose(fp); } #ifdef MMAP /* * Arguments: * db database * s search strings */ void search_mmap(char *db, char **s) { struct stat sb; int fd; caddr_t p; off_t len; if ((fd = open(db, O_RDONLY)) == -1 || fstat(fd, &sb) == -1) err(1, "`%s'", db); len = sb.st_size; if (len < (2*NBG)) errx(1, "database too small: %s\nRun /usr/libexec/locate.updatedb", db); if ((p = mmap((caddr_t)0, (size_t)len, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) err(1, "mmap ``%s''", db); /* foreach search string ... */ while (*s != NULL) { if (f_icase) fastfind_mmap_icase(*s, p, len, db); else fastfind_mmap(*s, p, len, db); s++; } if (munmap(p, (size_t)len) == -1) warn("munmap %s\n", db); (void)close(fd); } #endif /* MMAP */ void usage () { (void)fprintf(stderr, "usage: locate [-0Scims] [-l limit] [-d database] pattern ...\n\n"); (void)fprintf(stderr, "default database: `%s' or $LOCATE_PATH\n", _PATH_FCODES); exit(1); } /* load fastfind functions */ /* statistic */ /* fastfind_mmap, fastfind_mmap_icase */ #ifdef MMAP #undef FF_MMAP #undef FF_ICASE #define FF_MMAP #include "fastfind.c" #define FF_ICASE #include "fastfind.c" #endif /* MMAP */ /* fopen */ /* fastfind, fastfind_icase */ #undef FF_MMAP #undef FF_ICASE #include "fastfind.c" #define FF_ICASE #include "fastfind.c" diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c index 77d8f7e58079..8482ec998f03 100644 --- a/usr.bin/locate/locate/util.c +++ b/usr.bin/locate/locate/util.c @@ -1,271 +1,271 @@ /* * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1995-2022 Wolfram Schneider * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * James A. Woods. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include "locate.h" char **colon(char **, char*, char*); char *patprep(char *); u_char *tolower_word(u_char *); int getwm(caddr_t); int getwf(FILE *); int check_bigram_char(int); /* * Validate bigram chars. If the test failed the database is corrupt * or the database is obviously not a locate database. */ int check_bigram_char(ch) int ch; { /* legal bigram: 0, ASCII_MIN ... ASCII_MAX */ if (ch == 0 || (ch >= ASCII_MIN && ch <= ASCII_MAX)) return(ch); errx(1, "locate database header corrupt, bigram char outside 0, %d-%d: %d", ASCII_MIN, ASCII_MAX, ch); exit(1); } /* split a colon separated string into a char vector * * "bla:foo" -> {"foo", "bla"} * "bla:" -> {"foo", dot} * "bla" -> {"bla"} * "" -> do nothing * */ char ** colon(char **dbv, char *path, char *dot) { int vlen, slen; char *c, *ch, *p; char **pv; if (dbv == NULL) { if ((dbv = malloc(sizeof(char *))) == NULL) err(1, "malloc"); *dbv = NULL; } /* empty string */ if (*path == '\0') { warnx("empty database name, ignored"); return(dbv); } /* length of string vector */ for(vlen = 0, pv = dbv; *pv != NULL; pv++, vlen++); for (ch = c = path; ; ch++) { if (*ch == ':' || (!*ch && !(*(ch - 1) == ':' && ch == 1+ path))) { /* single colon -> dot */ if (ch == c) p = dot; else { /* a string */ slen = ch - c; if ((p = malloc(sizeof(char) * (slen + 1))) == NULL) err(1, "malloc"); bcopy(c, p, slen); *(p + slen) = '\0'; } /* increase dbv with element p */ if ((dbv = realloc(dbv, sizeof(char *) * (vlen + 2))) == NULL) err(1, "realloc"); *(dbv + vlen) = p; *(dbv + ++vlen) = NULL; c = ch + 1; } if (*ch == '\0') break; } return (dbv); } /* * extract last glob-free subpattern in name for fast pre-match; prepend * '\0' for backwards match; return end of new pattern */ static char globfree[100]; char * patprep(name) char *name; { - register char *endmark, *p, *subp; + char *endmark, *p, *subp; subp = globfree; *subp++ = '\0'; /* set first element to '\0' */ p = name + strlen(name) - 1; /* skip trailing metacharacters */ for (; p >= name; p--) if (strchr(LOCATE_REG, *p) == NULL) break; /* * check if maybe we are in a character class * * 'foo.[ch]' * |----< p */ if (p >= name && (strchr(p, '[') != NULL || strchr(p, ']') != NULL)) { for (p = name; *p != '\0'; p++) if (*p == ']' || *p == '[') break; p--; /* * cannot find a non-meta character, give up * '*\*[a-z]' * |-------< p */ if (p >= name && strchr(LOCATE_REG, *p) != NULL) p = name - 1; } if (p < name) /* only meta chars: "???", force '/' search */ *subp++ = '/'; else { for (endmark = p; p >= name; p--) if (strchr(LOCATE_REG, *p) != NULL) break; for (++p; (p <= endmark) && subp < (globfree + sizeof(globfree));) *subp++ = *p++; } *subp = '\0'; return(--subp); } /* tolower word */ u_char * tolower_word(word) u_char *word; { - register u_char *p; + u_char *p; for(p = word; *p != '\0'; p++) *p = TOLOWER(*p); return(word); } /* * Read integer from mmap pointer. * Essentially a simple ``return *(int *)p'' but avoids sigbus * for integer alignment (SunOS 4.x, 5.x). * * Convert network byte order to host byte order if necessary. * So we can read a locate database on FreeBSD/i386 (little endian) * which was built on SunOS/sparc (big endian). */ int getwm(p) caddr_t p; { union { char buf[INTSIZE]; int i; } u; - register int i, hi; + int i, hi; /* the integer is stored by an offset of 14 (!!!) */ int i_max = MAXPATHLEN + OFFSET; int i_min = -(MAXPATHLEN - OFFSET); for (i = 0; i < (int)INTSIZE; i++) u.buf[i] = *p++; i = u.i; if (i >= i_max || i <= i_min) { hi = ntohl(i); if (hi >= i_max || hi <= i_min) errx(1, "integer out of range: %d < %d < %d", i_min, abs(i) < abs(hi) ? i : hi, i_max); return(hi); } return(i); } /* * Read integer from stream. * * Convert network byte order to host byte order if necessary. * So we can read on FreeBSD/i386 (little endian) a locate database * which was built on SunOS/sparc (big endian). */ int getwf(fp) FILE *fp; { - register int word, hword; + int word, hword; int i_max = MAXPATHLEN + OFFSET; int i_min = -(MAXPATHLEN - OFFSET); word = getw(fp); if (word >= i_max || word <= i_min) { hword = ntohl(word); if (hword >= i_max || hword <= i_min) errx(1, "integer out of range: %d < %d < %d", i_min, abs(word) < abs(hword) ? word : hword, i_max); return(hword); } return(word); }