at_wini also needs a pci_reserve() for the pci compatability device, if
[minix3.git] / lib / sysutil / env_get_prm.c
blobcad5aead0941e9e1c5cd77b2837c830bc788b3ff
1 #include "sysutil.h"
2 #include <minix/config.h>
3 #include <string.h>
5 PRIVATE int argc = 0;
6 PRIVATE char **argv = NULL;
8 FORWARD _PROTOTYPE( char *find_key, (const char *params, const char *key));
10 /*===========================================================================*
11 * env_setargs *
12 *===========================================================================*/
13 PUBLIC void env_setargs(arg_c, arg_v)
14 int arg_c;
15 char *arg_v[];
17 argc= arg_c;
18 argv= arg_v;
21 /*===========================================================================*
22 * env_get_param *
23 *===========================================================================*/
24 PUBLIC int env_get_param(key, value, max_len)
25 char *key; /* which key to look up */
26 char *value; /* where to store value */
27 int max_len; /* maximum length of value */
29 message m;
30 static char mon_params[128*sizeof(char *)]; /* copy parameters here */
31 char *key_value;
32 int i, s, keylen;
34 if (key == NULL)
35 return EINVAL;
37 keylen= strlen(key);
38 for (i= 1; i<argc; i++)
40 if (strncmp(argv[i], key, keylen) != 0)
41 continue;
42 if (strlen(argv[i]) <= keylen)
43 continue;
44 if (argv[i][keylen] != '=')
45 continue;
46 key_value= argv[i]+keylen+1;
47 if (strlen(key_value)+1 > EP_BUF_SIZE)
48 return(E2BIG);
49 strcpy(value, key_value);
50 return OK;
53 /* Get copy of boot monitor parameters. */
54 m.m_type = SYS_GETINFO;
55 m.I_REQUEST = GET_MONPARAMS;
56 m.I_ENDPT = SELF;
57 m.I_VAL_LEN = sizeof(mon_params);
58 m.I_VAL_PTR = mon_params;
59 if ((s=_taskcall(SYSTASK, SYS_GETINFO, &m)) != OK) {
60 printf("SYS_GETINFO: %d (size %u)\n", s, sizeof(mon_params));
61 return(s);
64 /* We got a copy, now search requested key. */
65 if ((key_value = find_key(mon_params, key)) == NULL)
66 return(ESRCH);
68 /* Value found, make the actual copy (as far as possible). */
69 strncpy(value, key_value, max_len);
71 /* See if it fits in the client's buffer. */
72 if ((strlen(key_value)+1) > max_len) return(E2BIG);
73 return(OK);
77 /*==========================================================================*
78 * find_key *
79 *==========================================================================*/
80 PRIVATE char *find_key(params,name)
81 const char *params;
82 const char *name;
84 register const char *namep;
85 register char *envp;
87 for (envp = (char *) params; *envp != 0;) {
88 for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
90 if (*namep == '\0' && *envp == '=')
91 return(envp + 1);
92 while (*envp++ != 0)
95 return(NULL);