From: Philip Homburg Date: Tue, 8 Nov 2005 13:59:27 +0000 (+0000) Subject: Added paramvalue to the library. X-Git-Tag: v3.1.2a~512 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-keyfromlabel.html?a=commitdiff_plain;h=7394f38ed71877d843fda684ee173a3febd2b726;p=minix.git Added paramvalue to the library. --- diff --git a/include/minix/queryparam.h b/include/minix/queryparam.h new file mode 100644 index 000000000..7415fab43 --- /dev/null +++ b/include/minix/queryparam.h @@ -0,0 +1,45 @@ +/* queryparam.h - query program parameters Author: Kees J. Bot + * 22 Apr 1994 + */ +#ifndef _MINIX__QUERYPARAM_H +#define _MINIX__QUERYPARAM_H + +#include + +typedef size_t _mnx_size_t; + +struct export_param_list { + char *name; /* "variable", "[", ".field", or NULL. */ + void *offset; /* Address of a variable or field offset. */ + size_t size; /* Size of the resulting object. */ +}; + +struct export_params { + struct export_param_list *list; /* List of exported parameters. */ + struct export_params *next; /* Link several sets of parameters. */ +}; + +#ifdef __STDC__ +#define qp_stringize(var) #var +#define qp_dotstringize(var) "." #var +#else +#define qp_stringize(var) "var" +#define qp_dotstringize(var) ".var" +#endif +#define QP_VARIABLE(var) { qp_stringize(var), &(var), sizeof(var) } +#define QP_ARRAY(var) { "[", 0, sizeof((var)[0]) } +#define QP_VECTOR(var,ptr,len) { qp_stringize(var), &(ptr), -1 },\ + { "[", &(len), sizeof(*(ptr)) } +#define QP_FIELD(field, type) { qp_dotstringize(field), \ + (void *)offsetof(type, field), \ + sizeof(((type *)0)->field) } +#define QP_END() { 0, 0, 0 } + +void qp_export _ARGS((struct export_params *_ex_params)); +int queryparam _ARGS((int (*_qgetc) _ARGS((void)), void **_paddress, + _mnx_size_t *_psize)); +_mnx_size_t paramvalue _ARGS((char **_value, void *_address, + _mnx_size_t _size)); +#endif /* _MINIX__QUERYPARAM_H */ + +/* $PchId: queryparam.h,v 1.1 2005/06/28 14:31:26 philip Exp $ */ diff --git a/lib/other/Makefile b/lib/other/Makefile index b77275814..fc02d2f2f 100755 --- a/lib/other/Makefile +++ b/lib/other/Makefile @@ -49,6 +49,7 @@ libc_OBJECTS = \ mstats.o \ mtab.o \ nlist.o \ + paramvalue.o \ peekpoke.o \ popen.o \ putenv.o \ diff --git a/lib/other/paramvalue.c b/lib/other/paramvalue.c new file mode 100644 index 000000000..ae76ee9d9 --- /dev/null +++ b/lib/other/paramvalue.c @@ -0,0 +1,51 @@ +/* paramvalue() - decode kernel parameter values Author: Kees J. Bot + * 7 May 1994 + * The kernel returns the results of parameter queries + * by the XXQUERYPARAM svrctl calls as an array of hex digits, like this: + * "75020000,080C0000". These are the values of two four-byte variables. + * Paramvalue() decodes such a string. + */ +#define nil 0 +#include +#include +#include +#include +#include + +size_t paramvalue(char **value, void *address, size_t size) +/* Decode the string *value storing the result in the object at address with + * the given size. *value is left at the next parameter, *address is padded + * with zeros if needed, and the actual size of the value is returned. + */ +{ + unsigned char *addr= address; + char *v= *value; + int nibble; + size_t n; + + n= 0; + + while (*v != 0 && *v != ',') { + nibble= *v++ - '0'; + if (nibble > 0x9) nibble= nibble + '0' - 'A' + 0xA; + if (nibble > 0xF) nibble= nibble + 'A' - 'a'; + if (size > 0) { + if (n % 2 == 0) { + *addr= nibble << 4; + } else { + *addr++|= nibble; + size--; + } + n++; + } + } + while (size > 0) { *addr++= 0; size--; } + while (*v != 0 && *v++ != ',') {} + *value= v; + return n / 2; +} + + +/* + * $PchId: paramvalue.c,v 1.3 1996/02/22 09:15:56 philip Exp $ + */