Skip to content

Commit fe9fdd4

Browse files
authored
Autotools: Fix unused result and variables warnings in flush IO check (#15056)
- exit() replaced with regular return since these two behave the same in main() - main(void) used as argc and argv aren't used - if sentences wrapped in curly brackets for readability - fgets wrapped in if to check for the return result and omit the "ignoring return value of 'fgets' declared with attribute 'warn_unused_result'..." warnings in the config.log - fclose(fp) added before returning
1 parent 7b25cac commit fe9fdd4

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

ext/standard/config.m4

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,55 @@ AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io],
1111
#endif
1212
#include <string.h>
1313
14-
int main(int argc, char **argv)
14+
int main(void)
1515
{
1616
char *filename = tmpnam(NULL);
1717
char buffer[64];
1818
int result = 0;
1919
2020
FILE *fp = fopen(filename, "wb");
21-
if (NULL == fp)
21+
if (NULL == fp) {
2222
return 0;
23+
}
24+
2325
fputs("line 1\n", fp);
2426
fputs("line 2\n", fp);
2527
fclose(fp);
2628
2729
fp = fopen(filename, "rb+");
28-
if (NULL == fp)
30+
if (NULL == fp) {
31+
return 0;
32+
}
33+
34+
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
35+
fclose(fp);
2936
return 0;
30-
fgets(buffer, sizeof(buffer), fp);
37+
}
38+
3139
fputs("line 3\n", fp);
3240
rewind(fp);
33-
fgets(buffer, sizeof(buffer), fp);
34-
if (0 != strcmp(buffer, "line 1\n"))
41+
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
42+
fclose(fp);
43+
return 0;
44+
}
45+
46+
if (0 != strcmp(buffer, "line 1\n")) {
3547
result = 1;
36-
fgets(buffer, sizeof(buffer), fp);
37-
if (0 != strcmp(buffer, "line 3\n"))
48+
}
49+
50+
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
51+
fclose(fp);
52+
return 0;
53+
}
54+
55+
if (0 != strcmp(buffer, "line 3\n")) {
3856
result = 1;
57+
}
58+
3959
fclose(fp);
4060
unlink(filename);
4161
42-
exit(result);
62+
return result;
4363
}
4464
]])],
4565
[php_cv_have_flush_io=no],

0 commit comments

Comments
 (0)