summaryrefslogtreecommitdiffstats
path: root/commands/edit.c
diff options
context:
space:
mode:
authorEnrico Jorns <ejo@pengutronix.de>2015-11-04 15:31:42 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-11-05 09:15:53 +0100
commit79f04b235c5d161deea7eed01706d5fd3d0416e9 (patch)
tree7979459d76cc735e0dcbc2f3089b92085d79e797 /commands/edit.c
parentdbd7190295298acfb4996ec1aba5165a7be28fdc (diff)
downloadbarebox-79f04b235c5d161deea7eed01706d5fd3d0416e9.tar.gz
barebox-79f04b235c5d161deea7eed01706d5fd3d0416e9.tar.xz
edit: handle write() call errors in save_file()
save_file() did ignore possible errors of its write() calls. Now the error code is used as return code for save_file(). write_full() is used instead of write() as it does not perform partial writes which would require to check for returned size, too. Signed-off-by: Enrico Jorns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/edit.c')
-rw-r--r--commands/edit.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/commands/edit.c b/commands/edit.c
index b28e2b92a1..af3338affa 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -258,6 +258,7 @@ static int save_file(const char *path)
{
struct line *line, *tmp;
int fd;
+ int ret = 0;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
if (fd < 0) {
@@ -269,12 +270,20 @@ static int save_file(const char *path)
while(line) {
tmp = line->next;
- write(fd, line->data, strlen(line->data));
- write(fd, "\n", 1);
+ ret = write_full(fd, line->data, strlen(line->data));
+ if (ret < 0)
+ goto out;
+ ret = write_full(fd, "\n", 1);
+ if (ret < 0)
+ goto out;
line = tmp;
}
+
+ ret = 0;
+
+out:
close(fd);
- return 0;
+ return ret;
}
static void insert_char(char c)