Annotation of 43BSDReno/lib/libcompat/4.3/lsearch.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1989 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * This code is derived from software contributed to Berkeley by
        !             6:  * Roger L. Snyder.
        !             7:  *
        !             8:  * Redistribution and use in source and binary forms are permitted
        !             9:  * provided that: (1) source distributions retain this entire copyright
        !            10:  * notice and comment, and (2) distributions including binaries display
        !            11:  * the following acknowledgement:  ``This product includes software
        !            12:  * developed by the University of California, Berkeley and its contributors''
        !            13:  * in the documentation or other materials provided with the distribution
        !            14:  * and in all advertising materials mentioning features or use of this
        !            15:  * software. Neither the name of the University nor the names of its
        !            16:  * contributors may be used to endorse or promote products derived
        !            17:  * from this software without specific prior written permission.
        !            18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            21:  */
        !            22: 
        !            23: #if defined(LIBC_SCCS) && !defined(lint)
        !            24: static char sccsid[] = "@(#)lsearch.c  5.3 (Berkeley) 6/1/90";
        !            25: #endif /* LIBC_SCCS and not lint */
        !            26: 
        !            27: #include <sys/types.h>
        !            28: #include <unistd.h>
        !            29: 
        !            30: char *linear_base();
        !            31: 
        !            32: char *
        !            33: lsearch(key, base, nelp, width, compar)
        !            34:        char *key, *base;
        !            35:        u_int *nelp, width;
        !            36:        int (*compar)();
        !            37: {
        !            38:        return(linear_base(key, base, nelp, width, compar, 1));
        !            39: }
        !            40: 
        !            41: char *
        !            42: lfind(key, base, nelp, width, compar)
        !            43:        char *key, *base;
        !            44:        u_int *nelp, width;
        !            45:        int (*compar)();
        !            46: {
        !            47:        return(linear_base(key, base, nelp, width, compar, 0));
        !            48: }
        !            49: 
        !            50: static char *
        !            51: linear_base(key, base, nelp, width, compar, add_flag)
        !            52:        char *key, *base;
        !            53:        u_int *nelp, width;
        !            54:        int (*compar)(), add_flag;
        !            55: {
        !            56:        register char *element, *end;
        !            57: 
        !            58:        end = base + *nelp * width;
        !            59:        for (element = base; element < end; element += width)
        !            60:                if (!compar(element, key))              /* key found */
        !            61:                        return(element);
        !            62: 
        !            63:        if (!add_flag)                                  /* key not found */
        !            64:                return(NULL);
        !            65: 
        !            66:        /*
        !            67:         * The UNIX System User's Manual, 1986 edition claims that
        !            68:         * a NULL pointer is returned by lsearch with errno set
        !            69:         * appropriately, if there is not enough room in the table
        !            70:         * to add a new item.  This can't be done as none of these
        !            71:         * routines have any method of determining the size of the
        !            72:         * table.  This comment was isn't in the 1986-87 System V
        !            73:         * manual.
        !            74:         */
        !            75:        ++*nelp;
        !            76:        bcopy(key, end, (int)width);
        !            77:        return(end);
        !            78: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.