Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(775)

Side by Side Diff: fusl/src/env/unsetenv.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <stdlib.h> 1 #include <stdlib.h>
2 #include <string.h> 2 #include <string.h>
3 #include <errno.h> 3 #include <errno.h>
4 4
5 extern char **__environ; 5 extern char** __environ;
6 extern char **__env_map; 6 extern char** __env_map;
7 7
8 int unsetenv(const char *name) 8 int unsetenv(const char* name) {
9 { 9 int i, j;
10 » int i, j; 10 size_t l = strlen(name);
11 » size_t l = strlen(name);
12 11
13 » if (!*name || strchr(name, '=')) { 12 if (!*name || strchr(name, '=')) {
14 » » errno = EINVAL; 13 errno = EINVAL;
15 » » return -1; 14 return -1;
16 » } 15 }
17 again: 16 again:
18 » for (i=0; __environ[i] && (memcmp(name, __environ[i], l) || __environ[i] [l] != '='); i++); 17 for (i = 0; __environ[i] &&
19 » if (__environ[i]) { 18 (memcmp(name, __environ[i], l) || __environ[i][l] != '=');
20 » » if (__env_map) { 19 i++)
21 » » » for (j=0; __env_map[j] && __env_map[j] != __environ[i]; j++); 20 ;
22 » » » free (__env_map[j]); 21 if (__environ[i]) {
23 » » » for (; __env_map[j]; j++) 22 if (__env_map) {
24 » » » » __env_map[j] = __env_map[j+1]; 23 for (j = 0; __env_map[j] && __env_map[j] != __environ[i]; j++)
25 » » } 24 ;
26 » » for (; __environ[i]; i++) 25 free(__env_map[j]);
27 » » » __environ[i] = __environ[i+1]; 26 for (; __env_map[j]; j++)
28 » » goto again; 27 __env_map[j] = __env_map[j + 1];
29 » } 28 }
30 » return 0; 29 for (; __environ[i]; i++)
30 __environ[i] = __environ[i + 1];
31 goto again;
32 }
33 return 0;
31 } 34 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698