chiark / gitweb /
macro.h: let F_TYPE_CMP() macro fail to compile, if second parameter is not const
[elogind.git] / src / shared / fileio.c
index 4390726a9388b19f40d0353b7f5c6687540a0c9d..337b9e41476d2c418c14453d2f3a9f578ef072d6 100644 (file)
@@ -239,7 +239,7 @@ static int parse_env_file_internal(
                         break;
 
                 case PRE_VALUE:
-                        if (strchr(newline, c) || strchr(COMMENTS, c)) {
+                        if (strchr(newline, c)) {
                                 state = PRE_KEY;
                                 key[n_key] = 0;
 
@@ -247,7 +247,7 @@ static int parse_env_file_internal(
                                         value[n_value] = 0;
 
                                 /* strip trailing whitespace from key */
-                                while(strchr(WHITESPACE, key[--n_key]))
+                                while(n_key && strchr(WHITESPACE, key[--n_key]))
                                         key[n_key]=0;
 
                                 r = push(key, value, userdata);
@@ -279,6 +279,7 @@ static int parse_env_file_internal(
                 case VALUE:
                         if (strchr(newline, c)) {
                                 state = PRE_KEY;
+
                                 key[n_key] = 0;
 
                                 if (value)
@@ -289,7 +290,7 @@ static int parse_env_file_internal(
                                         value[last_whitespace] = 0;
 
                                 /* strip trailing whitespace from key */
-                                while(strchr(WHITESPACE, key[--n_key]))
+                                while(n_key && strchr(WHITESPACE, key[--n_key]))
                                         key[n_key]=0;
 
                                 r = push(key, value, userdata);
@@ -417,7 +418,7 @@ static int parse_env_file_internal(
                         value[n_value] = 0;
 
                 /* strip trailing whitespace from key */
-                while(strchr(WHITESPACE, key[--n_key]))
+                while(n_key && strchr(WHITESPACE, key[--n_key]))
                         key[n_key]=0;
 
                 r = push(key, value, userdata);
@@ -544,8 +545,8 @@ static void write_env_var(FILE *f, const char *v) {
 
 int write_env_file(const char *fname, char **l) {
         char **i;
-        char _cleanup_free_ *p = NULL;
-        FILE _cleanup_fclose_ *f = NULL;
+        _cleanup_free_ char *p = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         int r;
 
         r = fopen_temporary(fname, &f, &p);