]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: make return parameters of read_virtual_file() optional
authorLennart Poettering <lennart@poettering.net>
Thu, 20 May 2021 19:26:56 +0000 (21:26 +0200)
committerDan Streetman <ddstreet@canonical.com>
Thu, 20 May 2021 19:39:03 +0000 (15:39 -0400)
Prompted by: #19647

src/basic/fileio.c

index 0df03077d3c594f3fbc131f39d060a51b8831b46..853e679aaa849f105750fea1fe5838d27466d98c 100644 (file)
@@ -371,8 +371,6 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents
         int n_retries;
         bool truncated = false;
 
-        assert(ret_contents);
-
         /* Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work with two sorts of
          * virtual files. One sort uses "seq_file", and the results of the first read are buffered for the
          * second read. The other sort uses "raw" reads which always go direct to the device. In the latter
@@ -486,7 +484,9 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents
                 return -EBADMSG;
 
         buf[n] = 0;
-        *ret_contents = TAKE_PTR(buf);
+
+        if (ret_contents)
+                *ret_contents = TAKE_PTR(buf);
 
         return !truncated;
 }