From 8f0496b26aae88e206ac9a95b317043e78d147b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B6ppner?= Date: Wed, 10 Oct 2018 11:21:18 +0200 Subject: [PATCH] zpcictl: Use fopen() instead of open() for writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Be consistent with the rest of the code and use fopen() rather than open(). Reviewed-by: Hendrik Brueckner Signed-off-by: Jan Höppner --- zpcictl/zpcictl.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zpcictl/zpcictl.c b/zpcictl/zpcictl.c index deb78d6a..51b49a6c 100644 --- a/zpcictl/zpcictl.c +++ b/zpcictl/zpcictl.c @@ -155,17 +155,19 @@ static unsigned int sysfs_read_value(struct zpci_device *pdev, const char *attr) static void sysfs_write_data(struct zpci_report_error *report, char *slot) { + size_t r_size; char *path; - int fd, rc; + FILE *fp; + + r_size = sizeof(*report); path = util_path_sysfs("bus/pci/devices/%s/report_error", slot); - fd = open(path, O_WRONLY); - if (!fd) + fp = fopen(path, "w"); + if (!fp) fopen_err(path); - rc = write(fd, report, sizeof(*report)); - if (rc == -1) + if (fwrite(report, 1, r_size, fp) != r_size) warnx("Could not write to file: %s: %s", path, strerror(errno)); - if (close(fd)) + if (fclose(fp)) warnx("Could not close file: %s: %s", path, strerror(errno)); free(path); }