2010-02-11 15 views
6

Ho bisogno di fare un'analisi dei dati scritti sul mio modulo, e l'uso della funzione strtok() di string.h sarebbe utile. Tuttavia Ho provatoPosso usare strtok() in un modulo Kernel Linux?

#include <string.h> 

e

#include <linux/string.h> 

senza successo. È possibile? O dovrò scrivere la mia funzione strtok?

Grazie

risposta

7

Non c'è strtok nel valida API Kernel Linux. Dovrai scrivere il tuo. Vedere la sezione String Manipulation nell'API del kernel Linux.

BTW, vorrei suggerire di stare lontano da strtok (o qualsiasi cosa strtok -like). Non è rientranti e non è sicuro nel codice del kernel (che è intrinsecamente multithread).

Se si intende duplicare la funzione, considerare la duplicazione di strtok_r.

+0

Ok fantastico, almeno so per certo che devo scrivere il mio proprio ora, grazie! – cheesysam

14

L'ultima biblioteca kernel ha questo, che può fare quello che ti serve:

/** 
* strsep - Split a string into tokens 
* @s: The string to be searched 
* @ct: The characters to search for 
* 
* strsep() updates @s to point after the token, ready for the next call. 
* 
* It returns empty tokens, too, behaving exactly like the libc function 
* of that name. In fact, it was stolen from glibc2 and de-fancy-fied. 
* Same semantics, slimmer shape. ;) 
*/ 
Problemi correlati