]> granicus.if.org Git - graphviz/commitdiff
Lasi plugin: fix: use buffered I/O instead of raw I/O
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 4 Apr 2022 02:33:29 +0000 (19:33 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 10 Apr 2022 23:38:16 +0000 (16:38 -0700)
On non-Windows operating systems that lack `mmap`, this code fell back to
calling `read` but was not #including unistd.h. The result was a compilation
failure:

  plugin/lasi/gvloadimage_lasi.c:78:17: error: implicit declaration of function
    'read'; did you mean 'fread'? [-Werror=implicit-function-declaration]
   78 |                 read(fd, us->data, statbuf.st_size);
      |                 ^~~~
      |                 fread

By moving to the higher level `fread` function we fix this problem as well as
enabling prefetching optimizations and avoiding `EINTR` complications.

This issue was discovered while attempting to enable this plugin in the CMake
build system.

Gitlab: related to #1836

plugin/lasi/gvloadimage_lasi.c

index 0d320726338f2b896f20bb5df9136a8cb48eb792..54de8cac74383239159473a4c93125af39397cd5 100644 (file)
@@ -11,6 +11,7 @@
 #include "config.h"
 
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -75,7 +76,7 @@ static void lasi_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, bool filled)
                        us->data = NULL;
 #else
                us->data = malloc(statbuf.st_size);
-               read(fd, us->data, statbuf.st_size);
+               fread(us->data, 1, (size_t)statbuf.st_size, us->f);
 #endif
                us->must_inline = true;
                 break;