Remove building with NOCRYPTO option
[minix.git] / minix / lib / libsys / env_get_prm.c
blob061c92e059e363f3cafb50a09837619704386a03
1 #include "sysutil.h"
2 #include <string.h>
4 int env_argc = 0;
5 char **env_argv = NULL;
7 static const char *find_key(const char *params, const char *key);
9 /*===========================================================================*
10 * env_setargs *
11 *===========================================================================*/
12 void env_setargs(int arg_c, char *arg_v[])
14 env_argc= arg_c;
15 env_argv= arg_v;
18 /*===========================================================================*
19 * env_get_param *
20 *===========================================================================*/
21 int env_get_param(const char *key, char *value, int max_len)
23 message m;
24 static char mon_params[MULTIBOOT_PARAM_BUF_SIZE]; /* copy parameters here */
25 const char *key_value;
26 int i, s;
27 size_t keylen;
29 if (key == NULL)
30 return EINVAL;
32 keylen= strlen(key);
33 for (i= 1; i<env_argc; i++)
35 if (strncmp(env_argv[i], key, keylen) != 0)
36 continue;
37 if (strlen(env_argv[i]) <= keylen)
38 continue;
39 if (env_argv[i][keylen] != '=')
40 continue;
41 key_value= env_argv[i]+keylen+1;
42 if (strlen(key_value)+1 > (size_t) max_len)
43 return(E2BIG);
44 strcpy(value, key_value);
45 return OK;
48 /* Get copy of boot monitor parameters. */
49 m.m_type = SYS_GETINFO;
50 m.m_lsys_krn_sys_getinfo.request = GET_MONPARAMS;
51 m.m_lsys_krn_sys_getinfo.endpt = SELF;
52 m.m_lsys_krn_sys_getinfo.val_len = sizeof(mon_params);
53 m.m_lsys_krn_sys_getinfo.val_ptr = (vir_bytes)mon_params;
54 if ((s=_kernel_call(SYS_GETINFO, &m)) != OK) {
55 printf("SYS_GETINFO: %d (size %zu)\n", s, sizeof(mon_params));
56 return(s);
59 /* We got a copy, now search requested key. */
60 if ((key_value = find_key(mon_params, key)) == NULL)
61 return(ESRCH);
63 /* Value found, see if it fits in the client's buffer. Callers assume that
64 * their buffer is unchanged on error, so don't make a partial copy.
66 if ((strlen(key_value)+1) > (size_t) max_len) return(E2BIG);
68 /* Make the actual copy. */
69 strcpy(value, key_value);
71 return(OK);
75 /*==========================================================================*
76 * find_key *
77 *==========================================================================*/
78 static const char *find_key(const char *params, const char *name)
80 const char *namep, *envp;
82 for (envp = params; *envp != 0;) {
83 for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
85 if (*namep == '\0' && *envp == '=')
86 return(envp + 1);
87 while (*envp++ != 0)
90 return(NULL);