Here's a short atoi-funtion:
include it in your source and everything wil work fine !
#define is_digit(c) ((c) >= '0' && (c) <= '9')
static int atoi(const char *s)
{
int i=0;
while (is_digit(*s))
i = i*10 + *(s++) - '0';
return i;
}
Phil Daly wrote:
>
> I am trying to pass command line arguments into a module (doesn't have to be
> a real time module, of course). I can get around the well-known problem of
> not being able to pass numeric values by hiding them in strings. The question
> is how to convert them back after - atoi does not work in the module.
>
> To run the code (after compiling it):
>
> % insmod args arg1='dset=1024' arg2='freq=256' arg3='rate=8' arg4='time=4'
>
> Here's the code
>
> #include <linux/kernel.h> /* printk */
> #include <linux/module.h> /* module stuff */
> #include <stdlib.h> /* atoi */
>
> char *arg1 = "";
> char *arg2 = "";
> char *arg3 = "";
> char *arg4 = "";
> int dset = 0;
> int freq = 0;
> int rate = 0;
> int time = 0;
>
> int cliParse( char *ptr )
> {
> switch (ptr[0]) {
> case 'd':
> case 'D':
> while ( *ptr != '=' ) ptr++;
> ptr++;
> /*
> the following line fails - why?0
> dset = atoi( ptr );
> (void) printk("Decoded value = %d\n", dset);
> */
> ptr++;
> (void) printk("Dset: %s\n",ptr);
> break;
> case 'f':
> case 'F':
> (void) printk("Freq: %s\n",ptr);
> break;
> case 'r':
> case 'R':
> (void) printk("Rate: %s\n",ptr);
> break;
> case 't':
> case 'T':
> (void) printk("Time: %s\n",ptr);
> break;
> }
> return (0);
> }
>
> int init_module( void )
> {
> (void) cliParse(arg1);
> (void) cliParse(arg2);
> (void) cliParse(arg3);
> (void) cliParse(arg4);
> return (0);
> }
>
> void cleanup_module( void )
> {
> }
--
|\/\/\/|
| | Kay-Ulrich Scholl |
| | scholl@fzi.de |
| (o)(o) Forschungszentrum Informatik |
C _) Haid-und Neu-Str. 10-14 |
| ,___| D-76131 Karlsruhe |
| / 0721/9654-218 |
/____\ FAX: 0721 / 9654 - 209 |
/ \ -----------------------------------------+