Advertisement
agudelo1200

getpatch

Apr 15th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. void _getenv(const char *name)
  2. {
  3.     int count = 0, cmp = 0, size = 0;
  4.     char *copy;
  5.     const char del[] = "=";
  6.     char *token;
  7.  
  8.     copy = strdup(name);
  9.     size = strlen(name);
  10.     size++;
  11.  
  12.     while (environ[count])
  13.     {
  14.         /* get the first token */
  15.         token = strtok(environ[count], del);
  16.         /* walk through other tokens */
  17.         while (token != NULL)
  18.         {
  19.             cmp = strcmp(token, copy);
  20.             if (cmp == 0)
  21.             {
  22.                 if (token)
  23.                 {
  24.                     token = strtok(token + size, ":");
  25.                     while (token != NULL)
  26.                     {
  27.                         printf("%s\n", token);
  28.                         token = strtok(NULL, ":");
  29.                     }
  30.                 }
  31.             }
  32.             token = strtok(NULL, del);
  33.         }
  34.         count++;
  35.     }
  36. }
  37.  
  38. int main(void)
  39. {
  40.     const char *name = "PATH";
  41.  
  42.     _getenv(name);
  43.     return (0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement