# HG changeset patch # User magedrifaat # Date 1660157216 -7200 # Node ID 28817158ca86b6ad9e7a92e84594d9daaeb7f8ef # Parent b731c8f6db95998e70310fe327fdba0d72bdaf88 Tiff: changed write functions to use fcntl wrappers. diff -r b731c8f6db95 -r 28817158ca86 libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Wed Aug 10 16:01:51 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Wed Aug 10 20:46:56 2022 +0200 @@ -5,12 +5,6 @@ #include #include -// Workaround to not have to include fcntl which doesn't exist on windows -// TODO(maged): see what octave does for this (fcntl) -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif - #include "defun.h" #include "ov.h" #include "ovl.h" @@ -18,6 +12,8 @@ #include "errwarn.h" +#include "fcntl-wrappers.h" + #if defined (HAVE_TIFF) # include TIFFErrorHandler tiff_default_handler = NULL; @@ -65,6 +61,16 @@ } }; + void + check_readonly (TIFF *tif) + { + // This can't use O_RDONLY directly because its header file "fcntl.h" + // isn't available on Windows. The wrapper, however, seems to return + // the right thing even on Windows. + if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ()) + error ("Can't write data to a file opened in read-only mode"); + } + // Error if status is not 1 (success status for TIFFGetField) void validate_tiff_get_field (bool status, void *p_to_free=NULL) @@ -1837,6 +1843,8 @@ error ("Too few arguments provided\n"); TIFF *tif = (TIFF *)(args(0).uint64_value ()); + + check_readonly (tif); if (args(1).isstruct ()) { @@ -2036,9 +2044,7 @@ TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // TODO(maged): check on windows - if (TIFFGetMode (tif) == O_RDONLY) - error ("Can't write data to a file opened in read-only mode"); + check_readonly (tif); // Obtain all necessary tags tiff_image_data image_data (tif); @@ -2130,9 +2136,7 @@ TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // TODO(maged): check on windows - if (TIFFGetMode (tif) == O_RDONLY) - error ("Can't write data to a file opened in read-only mode"); + check_readonly (tif); // Obtain all necessary tags tiff_image_data image_data (tif); @@ -2164,9 +2168,7 @@ TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // TODO(maged): check on windows - if (TIFFGetMode (tif) == O_RDONLY) - error ("Can't write data to a file opened in read-only mode"); + check_readonly (tif); // Obtain all necessary tags tiff_image_data image_data (tif);