source: trunk/minix/lib/other/paramvalue.c@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.3 KB
Line 
1/* paramvalue() - decode kernel parameter values Author: Kees J. Bot
2 * 7 May 1994
3 * The kernel returns the results of parameter queries
4 * by the XXQUERYPARAM svrctl calls as an array of hex digits, like this:
5 * "75020000,080C0000". These are the values of two four-byte variables.
6 * Paramvalue() decodes such a string.
7 */
8#define nil 0
9#include <stddef.h>
10#include <stdlib.h>
11#include <string.h>
12#include <sys/types.h>
13#include <minix/queryparam.h>
14
15size_t paramvalue(char **value, void *address, size_t size)
16/* Decode the string *value storing the result in the object at address with
17 * the given size. *value is left at the next parameter, *address is padded
18 * with zeros if needed, and the actual size of the value is returned.
19 */
20{
21 unsigned char *addr= address;
22 char *v= *value;
23 int nibble;
24 size_t n;
25
26 n= 0;
27
28 while (*v != 0 && *v != ',') {
29 nibble= *v++ - '0';
30 if (nibble > 0x9) nibble= nibble + '0' - 'A' + 0xA;
31 if (nibble > 0xF) nibble= nibble + 'A' - 'a';
32 if (size > 0) {
33 if (n % 2 == 0) {
34 *addr= nibble << 4;
35 } else {
36 *addr++|= nibble;
37 size--;
38 }
39 n++;
40 }
41 }
42 while (size > 0) { *addr++= 0; size--; }
43 while (*v != 0 && *v++ != ',') {}
44 *value= v;
45 return n / 2;
46}
47
48
49/*
50 * $PchId: paramvalue.c,v 1.3 1996/02/22 09:15:56 philip Exp $
51 */
Note: See TracBrowser for help on using the repository browser.