[parted-devel] hfs.c: Detect write failure

Jim Meyering jim at meyering.net
Sun Mar 11 09:41:02 CET 2007


Checking fclose's return value is a must
for any file handle that might have been written to.
--------------------

hfs.c: Detect write failure
* libparted/fs/hfs/hfs.c (hfs_extract_file, hfs_extract_bitmap):
(hfs_extract_mdb, hfsplus_extract_file, hfsplus_extract_vh):
Fail when fclose fails for a written-to file handle.
---

 libparted/fs/hfs/hfs.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libparted/fs/hfs/hfs.c b/libparted/fs/hfs/hfs.c
index 4824a2e..3323cc0 100644
--- a/libparted/fs/hfs/hfs.c
+++ b/libparted/fs/hfs/hfs.c
@@ -1037,8 +1037,8 @@ hfs_extract_file(const char* filename, HfsPrivateFile* hfs_file)
 			goto err_close;
 	}
 
-	fclose(fout);
-	return 1;
+	return (fclose(fout) == 0 ? 1 : 0);
+
 err_close:
 	fclose(fout);
 	return 0;
@@ -1070,8 +1070,8 @@ hfs_extract_bitmap(const char* filename, PedFileSystem* fs)
 			goto err_close;
 	}
 
-	fclose(fout);
-	return 1;
+	return (fclose(fout) == 0 ? 1 : 0);
+
 err_close:
 	fclose(fout);
 	return 0;
@@ -1090,8 +1090,8 @@ hfs_extract_mdb (const char* filename, PedFileSystem* fs)
 	if (!fwrite(extract_buffer, PED_SECTOR_SIZE_DEFAULT, 1, fout))
 		goto err_close;
 
-	fclose(fout);
-	return 1;
+	return (fclose(fout) == 0 ? 1 : 0);
+
 err_close:
 	fclose(fout);
 	return 0;
@@ -1142,8 +1142,8 @@ hfsplus_extract_file(const char* filename, HfsPPrivateFile* hfsp_file)
 			goto err_close;
 	}
 
-	fclose(fout);
-	return 1;
+	return (fclose(fout) == 0 ? 1 : 0);
+
 err_close:
 	fclose(fout);
 	return 0;
@@ -1166,8 +1166,8 @@ hfsplus_extract_vh (const char* filename, PedFileSystem* fs)
 	if (!fwrite(extract_buffer, PED_SECTOR_SIZE_DEFAULT, 1, fout))
 		goto err_close;
 
-	fclose(fout);
-	return 1;
+	return (fclose(fout) == 0 ? 1 : 0);
+
 err_close:
 	fclose(fout);
 	return 0;



More information about the parted-devel mailing list