8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libsocket / inet / bootparams_getbyname.c
blobd071a81c2aba9008fe96f02a97656905e0ece4e5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <string.h>
30 #include <ctype.h>
31 #include <sys/types.h>
32 #include <nss_dbdefs.h>
34 static int str2bootent(const char *, int, void *, char *, int);
36 static DEFINE_NSS_DB_ROOT(db_root);
38 static void
39 _nss_initf_bootparams(nss_db_params_t *p)
41 p->name = NSS_DBNAM_BOOTPARAMS;
42 p->default_config = NSS_DEFCONF_BOOTPARAMS;
45 int
46 bootparams_getbyname(
47 char *name, /* lookup key */
48 char *linebuf, /* buffer to put the answer in */
49 int linelen /* max # of bytes to put into linebuf */
52 nss_XbyY_args_t arg;
53 nss_status_t res;
55 NSS_XbyY_INIT(&arg, linebuf, linebuf, linelen, str2bootent);
56 arg.key.name = name;
57 res = nss_search(&db_root, _nss_initf_bootparams,
58 NSS_DBOP_BOOTPARAMS_BYNAME, &arg);
59 (void) NSS_XbyY_FINI(&arg);
60 return (arg.status = res);
64 * Return values: 0 = success, 1 = parse error, 2 = erange ...
65 * The structure pointer passed in is a buffer in the caller's space.
66 * instring and buffer should be separate areas.
67 * The calling routine does all the real parsing; we just check limits and
68 * store the entry in the buffer we were passed by the caller.
69 * NOTE: we expect the data we're passed (in instr) has had the host's name
70 * stripped off the begining.
72 /* ARGSUSED */
73 static int
74 str2bootent(
75 const char *instr,
76 int lenstr,
77 void *ent, /* really (char *) */
78 char *buffer,
79 int buflen
82 const char *p, *limit;
84 if ((instr >= buffer && (buffer + buflen) > instr) ||
85 (buffer >= instr && (instr + lenstr) > buffer)) {
86 return (NSS_STR_PARSE_PARSE);
88 p = instr;
89 limit = p + lenstr;
91 /* Skip over leading whitespace */
92 while (p < limit && isspace(*p)) {
93 p++;
95 if (p >= limit) {
96 /* Syntax error -- no data! */
97 return (NSS_STR_PARSE_PARSE);
99 lenstr -= (p - instr);
100 if (buflen <= lenstr) { /* not enough buffer */
101 return (NSS_STR_PARSE_ERANGE);
103 (void) memcpy(buffer, p, lenstr);
104 buffer[lenstr] = '\0';
106 return (NSS_STR_PARSE_SUCCESS);