# HG changeset patch # User John W. Eaton # Date 1322468828 18000 # Node ID c9a103882d2e6b75067f7799bc7249d0156ad8a2 # Parent acaf33ccc04f7f0caa4268f013576ace70a3f3b9 mkstemp: open file in binary mode (bug #33669) * file-io.cc (Fmkstemp): Use mkostemp to open temp file using O_BINARY option. Add "b" to fopen_mode in call to fdopen. * bootstrap.conf (gnulib_modules): Include mkostemp in the list. diff --git a/build-aux/bootstrap.conf b/build-aux/bootstrap.conf --- a/build-aux/bootstrap.conf +++ b/build-aux/bootstrap.conf @@ -40,6 +40,7 @@ lstat mkdir mkfifo + mkostemp mkstemp mktime nanosleep diff --git a/src/file-io.cc b/src/file-io.cc --- a/src/file-io.cc +++ b/src/file-io.cc @@ -1981,7 +1981,7 @@ filename unique. The file is then created with mode read/write and\n\ permissions that are system dependent (on GNU/Linux systems, the permissions\n\ will be 0600 for versions of glibc 2.0.7 and later). The file is opened\n\ -with the @w{@code{O_EXCL}} flag.\n\ +in binary mode and with the @w{@code{O_EXCL}} flag.\n\ \n\ If the optional argument @var{delete} is supplied and is true,\n\ the file will be deleted automatically when Octave exits, or when\n\ @@ -2011,7 +2011,11 @@ OCTAVE_LOCAL_BUFFER (char, tmp, tmpl8.size () + 1); strcpy (tmp, tmpl8.c_str ()); - int fd = gnulib::mkstemp (tmp); +#ifndef O_BINARY +#define O_BINARY 0 +#endif + + int fd = gnulib::mkostemp (tmp, O_BINARY); if (fd < 0) { @@ -2020,7 +2024,7 @@ } else { - const char *fopen_mode = "w+"; + const char *fopen_mode = "w+b"; FILE *fid = fdopen (fd, fopen_mode);