I am writing a kernel module and I am wondering what system call function would I use to compare if the user entered string is an int or not?
I am writing a kernel module and I am wondering what system call function would I use to compare if the user entered string is an int or not?
See the manpg of strtol(), atoi(), atol(), or strtoul() routine.
There's also isdigit() in ctype.h - if every character is a digit, it's an integer.
It seems possible to me, at least in theory.Originally Posted by brewbuck
But I guess that this is in practice and concerns Linux. Moved to Linux Programming forum.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I know that, with respect to Linux. However, I gather from your response that it is impossible to implement an operating system for which the C library, or at least parts of it, is available in the kernel? Why is that so?Originally Posted by brewbuck
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It's not impossible, and in fact if you linked the kernel with the C library just to get a function like atoi(), it would probably work (not that I recommend it).
A kernel is really one of the most non-standard, non-portable things you can write. It doesn't seem to make much sense to try to impose a concept like a standard library on top of it.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Right, so we were actually just saying the same thing. That said, I note that sean's suggestion also relies on the standard library, so NuNn's question has not been answered yet (other than with a "write your own function" suggestion).Originally Posted by brewbuck
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Kernel API String Conversion Functions
Call simple_strtol and check the end pointer.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law