Add image buffers without a temporary file

Use fmemopen to create an in-memory FILE for reading in image
attributes. This avoids creating a separate temporary file for every
image added to the worksheet.

Passing NULL as the first argument creates a buffer managed by fmemopen.
According to the system documentation, fclose will free the buffer, so
no further changes are needed.

fmemopen is defined by POSIX.1-2008, and on some platforms requires
_POSIX_C_SOURCE set to 200809L or greater. This is conditionally set in
the file (src/worksheet.c) where fmemopen is used.

This change includes a new USE_FMEMOPEN option for both CMake and make,
following the tradition set by USE_STANDARD_TMPFILE etc. This new option
is enabled on Travis.

See #287 #288
This commit is contained in:
Evan Miller 2020-05-06 14:05:44 -04:00 committed by John McNamara
parent cc83549bbb
commit b62653f382
4 changed files with 21 additions and 2 deletions

View file

@ -118,6 +118,7 @@ option(BUILD_EXAMPLES "Build libxlsxwriter examples" OFF)
option(USE_SYSTEM_MINIZIP "Use system minizip installation" OFF)
option(USE_STANDARD_TMPFILE "Use the C standard library's tmpfile()" OFF)
option(USE_NO_MD5 "Build libxlsxwriter without third party MD5 lib" OFF)
option(USE_FMEMOPEN "Use fmemopen() in place of some temporary files" OFF)
option(IOAPI_NO_64 "Disable 64-bit filesystem support" OFF)
if(MSVC)
@ -146,6 +147,9 @@ if(USE_NO_MD5)
list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_NO_MD5)
endif()
if(USE_FMEMOPEN)
list(APPEND LXW_PRIVATE_COMPILE_DEFINITIONS USE_FMEMOPEN)
endif()
if(NOT BUILD_SHARED_LIBS)
if(UNIX)