Re: How to use global and user related files?



Absolutilly correct your anwser to yourself ;)

(APPNAMEDIR="path1:path2").
> 
> There exist function g_getenv (); But does there exist simple and common
> way to parse PATH variable?

    #include <string.h>
    #include <stddef.h>
   
    gchar *env = PR_GetEnv("ENV_VARIABLE");
 
     ...
     /* as env variable follow a "standart format", like paths
separated by ':' */
     const char delimiters[] = ":";
     char *token, *cp;

     cp = strdupa (env);                /* Make writable copy.  */
     token = strtok (cp, delimiters);      /* token => "words" */
     token = strtok (NULL, delimiters);    /* token => "separated" */
     token = strtok (NULL, delimiters);    /* token => "by" */
     token = strtok (NULL, delimiters);    /* token => "spaces" */
     token = strtok (NULL, delimiters);    /* token => "and" */
     token = strtok (NULL, delimiters);    /* token => "punctuation" */
     token = strtok (NULL, delimiters);    /* token => NULL */

====> or a loop like this 
....
     while (token = strtok (cp, delimiters) != NULL ) {
             /* handle each 'token' as you want */
     };
....

I hope this help, I did something like this some time ago, but you can
try 'man strtok' to more details ..

Best Regards 

-- 
Antonio Gomes
E-mail: antonio gomes indt org br
Embedded Linux Lab - 10LE
INdT - Instituto Nokia de Tecnologia (Manaus/Br)
NOKIA's Technology Institute



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