Re: Itoa and atoi functions in kernel space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

While answering, please to answer to the list.

Vincenzo Mallozzi a écrit :

> how can I use snprintf()? 
> I have to execute, in a kernel module, an instruction like this:
> 
>   temp = (char *) Itoa((int) pid);

How could your Itoa() function work ? Would it allocate the memory to
contain the character string ?

> where pid is of type pid_t.

Basically, do something like :

 char pid_string [16];

 snprintf (pid_string, sizeof(pid_string), "%d", pid);

Maybe "%d" should be adapted to match better the pid_t (might be
unsigned for example).

> For example, I need strtok() to extract tokenized substrings for a given 
> string.

As said in
http://janitor.kernelnewbies.org/docs/driver-howto.html#3.3.1, one
shouldn't use strtok() which is not thread-safe nor SMP-safe. You should
use strsep() instead, available in <linux/string.h>.

Basically, I found these informations with 2 minutes of Googling. Google
*really* is your friend.

Sincerly,

Thomas
-- 
PETAZZONI Thomas - thomas.petazzoni@xxxxxxxx
http://thomas.enix.org - Jabber: thomas.petazzoni@xxxxxxxxx
KOS: http://kos.enix.org/ - SOS: http://sos.enix.org
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux