Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/runtime/c-libs/posix-error/posix-name-val.c
ViewVC logotype

View of /sml/trunk/src/runtime/c-libs/posix-error/posix-name-val.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (download) (as text) (annotate)
Thu Jun 1 18:34:03 2000 UTC (20 years, 2 months ago) by monnier
File size: 819 byte(s)
bring revisions from the vendor branch to the trunk
/* posix-name-val.c
 *
 * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
 *
 * Support for string to int lookup.
 */

#include <stdlib.h>
#include <string.h>
#include "posix-name-val.h"

static int cmp (const void *key, const void *item)
{
    return strcmp(((name_val_t*)key)->name, ((name_val_t*)item)->name);
}

/* _ml_posix_nv_lookup
 *
 * Given a string key, an array of name/value pairs and the size of the
 * array, find element in the array with matching key and return a pointer
 * to it. If not found, return NULL. We use binary search, so we assume
 * the array is sorted.
 */
name_val_t *_ml_posix_nv_lookup (char *key, name_val_t *array, int numelms)
{
    name_val_t   k;

    k.name = key;
    return ((name_val_t *)bsearch(&k,array,numelms,sizeof (name_val_t),cmp));

} /* end of _ml_posix_nv_lookup */


root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0