From fd5c9f1259d0191af57b20f06dda35e62acb6275 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 13 Jun 2023 23:44:19 +0200 Subject: Overhaul sqfs_istream_t/sqfs_ostream_t error handling Report an error number from the implementations, change the users to forward that error number (which also means libtar write header/link now returns an error code) and all subsequent binaries to use sqfs_perror() instead of relying on the function to print an error internally. Also, make sure to preserve errno/GetLastError() in the implementations and print out a stringified error in sqfs_perror() if the error code indicates an I/O error. Signed-off-by: David Oberhollenzer --- bin/sqfsdiff/src/extract.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'bin/sqfsdiff') diff --git a/bin/sqfsdiff/src/extract.c b/bin/sqfsdiff/src/extract.c index 43e9b97..d51096f 100644 --- a/bin/sqfsdiff/src/extract.c +++ b/bin/sqfsdiff/src/extract.c @@ -11,6 +11,7 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, { char *ptr, *temp; sqfs_ostream_t *fp; + int ret; temp = alloca(strlen(prefix) + strlen(path) + 2); sprintf(temp, "%s/%s", prefix, path); @@ -21,9 +22,9 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, return -1; *ptr = '/'; - fp = ostream_open_file(temp, SQFS_FILE_OPEN_OVERWRITE); - if (fp == NULL) { - perror(temp); + ret = ostream_open_file(&fp, temp, SQFS_FILE_OPEN_OVERWRITE); + if (ret) { + sqfs_perror(temp, NULL, ret); return -1; } @@ -32,7 +33,13 @@ static int extract(sqfs_data_reader_t *data, const sqfs_inode_generic_t *inode, return -1; } - fp->flush(fp); + ret = fp->flush(fp); + if (ret) { + sqfs_perror(fp->get_filename(fp), NULL, ret); + sqfs_drop(fp); + return -1; + } + sqfs_drop(fp); return 0; } -- cgit v1.2.3