libutil: Move some zdev file reading functions into util

In preparation for sharing some zdev udev code with other libraries, move
some file operation code from zdev into util_file.

Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Matthew Rosato
2021-09-15 11:49:44 -04:00
committed by Jan Höppner
parent a739584d6f
commit f64b4087dd
5 changed files with 152 additions and 72 deletions

View File

@@ -19,6 +19,8 @@
#include <sys/types.h>
#include <unistd.h>
#include "lib/util_file.h"
#include "attrib.h"
#include "ccw.h"
#include "ccwgroup.h"
@@ -187,7 +189,8 @@ static exit_code_t read_fw(struct fw_file *file, FILE *fd, const char *filename)
for (retry = 0; retry < READ_RETRY; retry++) {
/* Read complete file once */
rc = misc_read_fd(fd, (void **) &buffer, &size);
rc = (exit_code_t) util_file_read_fd_buf(fd, (void **) &buffer,
&size);
if (rc) {
warn("%s: Could not read file", filename);
return rc;
@@ -203,7 +206,8 @@ static exit_code_t read_fw(struct fw_file *file, FILE *fd, const char *filename)
/* Could be a pipe, socket, or FIFO - accept v1. */
break;
}
rc = misc_read_fd(fd, (void **) &buffer2, &size2);
rc = (exit_code_t) util_file_read_fd_buf(fd, (void **) &buffer2,
&size2);
if (rc || !buffer2) {
/* Could not get second version - accept v1. */
break;