Merge pull request #31048 from YHNdnzj/fstab-modernization

fstab-util/generator: a few cleanups/improvements
This commit is contained in:
Daan De Meyer
2024-01-26 09:01:19 +01:00
committed by GitHub
10 changed files with 167 additions and 164 deletions
+16 -18
View File
@@ -1327,33 +1327,31 @@ int read_timestamp_file(const char *fn, usec_t *ret) {
return 0;
}
int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space) {
int r;
int fputs_with_separator(FILE *f, const char *s, const char *separator, bool *space) {
assert(s);
assert(space);
/* Outputs the specified string with fputs(), but optionally prefixes it with a separator. The *space parameter
* when specified shall initially point to a boolean variable initialized to false. It is set to true after the
* first invocation. This call is supposed to be use in loops, where a separator shall be inserted between each
* element, but not before the first one. */
/* Outputs the specified string with fputs(), but optionally prefixes it with a separator.
* The *space parameter when specified shall initially point to a boolean variable initialized
* to false. It is set to true after the first invocation. This call is supposed to be use in loops,
* where a separator shall be inserted between each element, but not before the first one. */
if (!f)
f = stdout;
if (space) {
if (!separator)
separator = " ";
if (!separator)
separator = " ";
if (*space) {
r = fputs(separator, f);
if (r < 0)
return r;
}
if (*space)
if (fputs(separator, f) < 0)
return -EIO;
*space = true;
}
*space = true;
return fputs(s, f);
if (fputs(s, f) < 0)
return -EIO;
return 0;
}
/* A bitmask of the EOL markers we know */
+1 -1
View File
@@ -143,7 +143,7 @@ int fflush_sync_and_check(FILE *f);
int write_timestamp_file_atomic(const char *fn, usec_t n);
int read_timestamp_file(const char *fn, usec_t *ret);
int fputs_with_space(FILE *f, const char *s, const char *separator, bool *space);
int fputs_with_separator(FILE *f, const char *s, const char *separator, bool *space);
typedef enum ReadLineFlags {
READ_LINE_ONLY_NUL = 1 << 0,
+4 -1
View File
@@ -91,13 +91,16 @@ void ordered_set_print(FILE *f, const char *field, OrderedSet *s) {
bool space = false;
char *p;
assert(f);
assert(field);
if (ordered_set_isempty(s))
return;
fputs(field, f);
ORDERED_SET_FOREACH(p, s)
fputs_with_space(f, p, NULL, &space);
fputs_with_separator(f, p, NULL, &space);
fputc('\n', f);
}
+3 -1
View File
@@ -894,13 +894,15 @@ int fputstrv(FILE *f, char * const *l, const char *separator, bool *space) {
bool b = false;
int r;
assert(f);
/* Like fputs(), but for strv, and with a less stupid argument order */
if (!space)
space = &b;
STRV_FOREACH(s, l) {
r = fputs_with_space(f, *s, separator, space);
r = fputs_with_separator(f, *s, separator, space);
if (r < 0)
return r;
}