@@ -29,9 +29,8 @@ FILE *safe_fopen(const char *file, const int lineno, void (cleanup_fn)(void),
29
29
FILE * f = fopen (path , mode );
30
30
31
31
if (f == NULL ) {
32
- tst_brkm (TBROK | TERRNO , cleanup_fn ,
33
- "%s:%d: fopen(%s,%s) failed" ,
34
- file , lineno , path , mode );
32
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
33
+ "fopen(%s,%s) failed" , path , mode );
35
34
}
36
35
37
36
return f ;
@@ -44,9 +43,12 @@ int safe_fclose(const char *file, const int lineno, void (cleanup_fn)(void),
44
43
45
44
ret = fclose (f );
46
45
47
- if (ret ) {
48
- tst_brkm (TBROK | TERRNO , cleanup_fn ,
49
- "%s:%d: fclose(%p) failed" , file , lineno , f );
46
+ if (ret == EOF ) {
47
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
48
+ "fclose(%p) failed" , f );
49
+ } else if (ret ) {
50
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
51
+ "Invalid fclose(%p) return value %d" , f , ret );
50
52
}
51
53
52
54
return ret ;
@@ -62,9 +64,12 @@ int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),
62
64
ret = vasprintf (strp , fmt , va );
63
65
va_end (va );
64
66
65
- if (ret < 0 ) {
66
- tst_brkm (TBROK | TERRNO , cleanup_fn ,
67
- "%s:%d: asprintf(%s,...) failed" , file , lineno , fmt );
67
+ if (ret == -1 ) {
68
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
69
+ "asprintf(%s,...) failed" , fmt );
70
+ } else if (ret < 0 ) {
71
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
72
+ "Invalid asprintf(%s,...) return value %d" , fmt , ret );
68
73
}
69
74
70
75
return ret ;
@@ -81,13 +86,12 @@ FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
81
86
82
87
if (stream == NULL ) {
83
88
if (errno != 0 ) {
84
- tst_brkm (TBROK | TERRNO , cleanup_fn ,
85
- "%s:%d: popen(%s,%s) failed" ,
86
- file , lineno , command , type );
89
+ tst_brkm_ (file , lineno , TBROK | TERRNO , cleanup_fn ,
90
+ "popen(%s,%s) failed" , command , type );
87
91
} else {
88
- tst_brkm ( TBROK , cleanup_fn ,
89
- "%s:%d: popen(%s,%s) failed: Out of memory" ,
90
- file , lineno , command , type );
92
+ tst_brkm_ ( file , lineno , TBROK , cleanup_fn ,
93
+ " popen(%s,%s) failed: Out of memory" ,
94
+ command , type );
91
95
}
92
96
}
93
97
0 commit comments