]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Disable buffered IO in isc_stdio API
authorOndřej Surý <ondrej@isc.org>
Thu, 6 Apr 2023 12:24:36 +0000 (14:24 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 27 Nov 2024 17:55:33 +0000 (18:55 +0100)
Instead of doing excessive flushes when using isc_stdio API, disable the
buffered IO for the FILE * pointer completely and disable the guts of
the isc_stdio_flush() function as there are no buffered data now.

lib/isc/stdio.c

index 99c0c100b1b8e41fd2a3979827fd35ce90e5d2c0..ecb9ca6313624608efed62dc1f2ef24dad292130 100644 (file)
@@ -28,6 +28,13 @@ isc_stdio_open(const char *filename, const char *mode, FILE **fp) {
        if (f == NULL) {
                return isc__errno2result(errno);
        }
+
+       int r = setvbuf(f, NULL, _IONBF, 0);
+       if (r != 0) {
+               fclose(f);
+               return isc__errno2result(errno);
+       }
+
        *fp = f;
        return ISC_R_SUCCESS;
 }
@@ -105,15 +112,9 @@ isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f,
 }
 
 isc_result_t
-isc_stdio_flush(FILE *f) {
-       int r;
-
-       r = fflush(f);
-       if (r == 0) {
-               return ISC_R_SUCCESS;
-       } else {
-               return isc__errno2result(errno);
-       }
+isc_stdio_flush(FILE *f ISC_ATTR_UNUSED) {
+       /* We disable buffering when opening the file */
+       return ISC_R_SUCCESS;
 }
 
 isc_result_t