]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
generator: modernize generator_open_unit_file()
authorLennart Poettering <lennart@poettering.net>
Sun, 16 Oct 2022 20:37:26 +0000 (22:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Oct 2022 06:06:55 +0000 (08:06 +0200)
src/shared/generator.c

index bba8e1eaae532a8a9425516581e52f63df0075cf..5d019f4f4e045594c854f71cc82ffaf1f329f224 100644 (file)
 #include "util.h"
 
 int generator_open_unit_file(
-                const char *dest,
+                const char *dir,
                 const char *source,
-                const char *name,
-                FILE **file) {
+                const char *fn,
+                FILE **ret) {
 
-        _cleanup_free_ char *unit = NULL;
+        _cleanup_free_ char *p = NULL;
         FILE *f;
         int r;
 
-        unit = path_join(dest, name);
-        if (!unit)
+        assert(dir);
+        assert(fn);
+        assert(ret);
+
+        p = path_join(dir, fn);
+        if (!p)
                 return log_oom();
 
-        r = fopen_unlocked(unit, "wxe", &f);
+        r = fopen_unlocked(p, "wxe", &f);
         if (r < 0) {
                 if (source && r == -EEXIST)
                         return log_error_errno(r,
-                                               "Failed to create unit file %s, as it already exists. Duplicate entry in %s?",
-                                               unit, source);
-                else
-                        return log_error_errno(r,
-                                               "Failed to create unit file %s: %m",
-                                               unit);
+                                               "Failed to create unit file '%s', as it already exists. Duplicate entry in '%s'?",
+                                               p, source);
+
+                return log_error_errno(r, "Failed to create unit file '%s': %m", p);
         }
 
         fprintf(f,
                 "# Automatically generated by %s\n\n",
                 program_invocation_short_name);
 
-        *file = f;
+        *ret = f;
         return 0;
 }