1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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
This commit is contained in:
Peter Kokot
2024-07-22 10:00:14 +02:00
committed by GitHub
parent 7b25cac32b
commit fe9fdd4fc3

View File

@@ -11,35 +11,55 @@ AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io],
#endif
#include <string.h>
int main(int argc, char **argv)
int main(void)
{
char *filename = tmpnam(NULL);
char buffer[64];
int result = 0;
FILE *fp = fopen(filename, "wb");
if (NULL == fp)
if (NULL == fp) {
return 0;
}
fputs("line 1\n", fp);
fputs("line 2\n", fp);
fclose(fp);
fp = fopen(filename, "rb+");
if (NULL == fp)
if (NULL == fp) {
return 0;
fgets(buffer, sizeof(buffer), fp);
}
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
fclose(fp);
return 0;
}
fputs("line 3\n", fp);
rewind(fp);
fgets(buffer, sizeof(buffer), fp);
if (0 != strcmp(buffer, "line 1\n"))
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
fclose(fp);
return 0;
}
if (0 != strcmp(buffer, "line 1\n")) {
result = 1;
fgets(buffer, sizeof(buffer), fp);
if (0 != strcmp(buffer, "line 3\n"))
}
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
fclose(fp);
return 0;
}
if (0 != strcmp(buffer, "line 3\n")) {
result = 1;
}
fclose(fp);
unlink(filename);
exit(result);
return result;
}
]])],
[php_cv_have_flush_io=no],