File: 07_detect_failure_to_write_key

package info (click to toggle)
chntpw 140201-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,100 kB
  • sloc: ansic: 23,909; makefile: 137
file content (20 lines) | stat: -rw-r--r-- 510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Description: Detect stream write failure.
Forwarded: no
--- a/ntreg.c
+++ b/ntreg.c
@@ -3493,7 +3493,14 @@
 
     fprintf(file,"\r\n"); /* Must end file with an empty line, windows does that */
 
-    fclose(file);
+    if (ferror (file)) {
+	printf("failed to write file '%s'\n", filename);
+	fclose (file);
+	return;
+    }
+    if (fclose(file))
+      printf("failed to write file '%s': %s\n", filename,
+	     strerror(errno));
 }
 
 /* ================================================================ */