Search

Parsing integer argument to functions in linux kernel

Kernel API provides functions to help making parsing of integer arguments being passed to functions easier. One of the functions is



Ref: Kernel API

To understand what has been passed as the argument we need to look at the return value of the function.

To understand the working a function is implemented as an example which tests for all the 4 possible return values and prints the option received.



In the function above the argument is received in *str, which is passed to the get_option function which, which in turn assigns the values to pint from the str.

To see the function in action, we can call the function in the init function with different arguments as shown in the example below.



In the code, we have called the function "getargs" with no arguments,one argument,argument and a comma and specified a range.

To compile code,save it as readOptions.c use the following makefile



To comple and insert the code.



To see the output run the command dmesg



In the above output we can see that, the first call to getargs did not have any arguments in it, hence we see the output as no arguments. The calls after that print out exactly as they are passed.


No comments:

Post a Comment