]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/fileio.c
fileio: drop "newline" parameter for env file parsers
[thirdparty/systemd.git] / src / basic / fileio.c
index fa6084e602a86484ad7815ad543157003297afa9..45c0b4a840529ab288969ee09f9b93ed50d5b8d3 100644 (file)
@@ -368,7 +368,6 @@ int read_full_file(const char *fn, char **contents, size_t *size) {
 static int parse_env_file_internal(
                 FILE *f,
                 const char *fname,
-                const char *newline,
                 int (*push) (const char *filename, unsigned line,
                              const char *key, char *value, void *userdata, int *n_pushed),
                 void *userdata,
@@ -394,8 +393,6 @@ static int parse_env_file_internal(
                 COMMENT_ESCAPE
         } state = PRE_KEY;
 
-        assert(newline);
-
         if (f)
                 r = read_full_stream(f, &contents, NULL);
         else
@@ -423,7 +420,7 @@ static int parse_env_file_internal(
                         break;
 
                 case KEY:
-                        if (strchr(newline, c)) {
+                        if (strchr(NEWLINE, c)) {
                                 state = PRE_KEY;
                                 line++;
                                 n_key = 0;
@@ -445,7 +442,7 @@ static int parse_env_file_internal(
                         break;
 
                 case PRE_VALUE:
-                        if (strchr(newline, c)) {
+                        if (strchr(NEWLINE, c)) {
                                 state = PRE_KEY;
                                 line++;
                                 key[n_key] = 0;
@@ -483,7 +480,7 @@ static int parse_env_file_internal(
                         break;
 
                 case VALUE:
-                        if (strchr(newline, c)) {
+                        if (strchr(NEWLINE, c)) {
                                 state = PRE_KEY;
                                 line++;
 
@@ -528,7 +525,7 @@ static int parse_env_file_internal(
                 case VALUE_ESCAPE:
                         state = VALUE;
 
-                        if (!strchr(newline, c)) {
+                        if (!strchr(NEWLINE, c)) {
                                 /* Escaped newlines we eat up entirely */
                                 if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
                                         return -ENOMEM;
@@ -554,7 +551,7 @@ static int parse_env_file_internal(
                 case SINGLE_QUOTE_VALUE_ESCAPE:
                         state = SINGLE_QUOTE_VALUE;
 
-                        if (!strchr(newline, c)) {
+                        if (!strchr(NEWLINE, c)) {
                                 if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
                                         return -ENOMEM;
 
@@ -579,7 +576,7 @@ static int parse_env_file_internal(
                 case DOUBLE_QUOTE_VALUE_ESCAPE:
                         state = DOUBLE_QUOTE_VALUE;
 
-                        if (!strchr(newline, c)) {
+                        if (!strchr(NEWLINE, c)) {
                                 if (!GREEDY_REALLOC(value, value_alloc, n_value+2))
                                         return -ENOMEM;
 
@@ -590,7 +587,7 @@ static int parse_env_file_internal(
                 case COMMENT:
                         if (c == '\\')
                                 state = COMMENT_ESCAPE;
-                        else if (strchr(newline, c)) {
+                        else if (strchr(NEWLINE, c)) {
                                 state = PRE_KEY;
                                 line++;
                         }
@@ -699,17 +696,13 @@ static int parse_env_file_push(
 int parse_env_filev(
                 FILE *f,
                 const char *fname,
-                const char *newline,
                 va_list ap) {
 
         int r, n_pushed = 0;
         va_list aq;
 
-        if (!newline)
-                newline = NEWLINE;
-
         va_copy(aq, ap);
-        r = parse_env_file_internal(f, fname, newline, parse_env_file_push, &aq, &n_pushed);
+        r = parse_env_file_internal(f, fname, parse_env_file_push, &aq, &n_pushed);
         va_end(aq);
         if (r < 0)
                 return r;
@@ -720,14 +713,13 @@ int parse_env_filev(
 int parse_env_file(
                 FILE *f,
                 const char *fname,
-                const char *newline,
                 ...) {
 
         va_list ap;
         int r;
 
-        va_start(ap, newline);
-        r = parse_env_filev(f, fname, newline, ap);
+        va_start(ap, fname);
+        r = parse_env_filev(f, fname, ap);
         va_end(ap);
 
         return r;
@@ -763,14 +755,11 @@ static int load_env_file_push(
         return 0;
 }
 
-int load_env_file(FILE *f, const char *fname, const char *newline, char ***rl) {
+int load_env_file(FILE *f, const char *fname, char ***rl) {
         char **m = NULL;
         int r;
 
-        if (!newline)
-                newline = NEWLINE;
-
-        r = parse_env_file_internal(f, fname, newline, load_env_file_push, &m, NULL);
+        r = parse_env_file_internal(f, fname, load_env_file_push, &m, NULL);
         if (r < 0) {
                 strv_free(m);
                 return r;
@@ -812,14 +801,11 @@ static int load_env_file_push_pairs(
         return 0;
 }
 
-int load_env_file_pairs(FILE *f, const char *fname, const char *newline, char ***rl) {
+int load_env_file_pairs(FILE *f, const char *fname, char ***rl) {
         char **m = NULL;
         int r;
 
-        if (!newline)
-                newline = NEWLINE;
-
-        r = parse_env_file_internal(f, fname, newline, load_env_file_push_pairs, &m, NULL);
+        r = parse_env_file_internal(f, fname, load_env_file_push_pairs, &m, NULL);
         if (r < 0) {
                 strv_free(m);
                 return r;
@@ -872,7 +858,7 @@ int merge_env_file(
          * plus "extended" substitutions, unlike other exported parsing functions.
          */
 
-        return parse_env_file_internal(f, fname, NEWLINE, merge_env_file_push, env, NULL);
+        return parse_env_file_internal(f, fname, merge_env_file_push, env, NULL);
 }
 
 static void write_env_var(FILE *f, const char *v) {