[sane-devel] [RFC] mksotemp

Olaf Meeuwissen paddy-hack at member.fsf.org
Mon May 2 02:57:58 UTC 2016

Alessandro Zummo writes:

>  Some platforms have no mksotemp, the following
>  patch should solve that. 
>  However my autoconf won't generate a correct configure
>  (it removes the INCLUDES statement), so I have omitted it
> diff --git a/backend/pieusb_buffer.c b/backend/pieusb_buffer.c
> index 0718238..9a04de9 100644
> --- a/backend/pieusb_buffer.c
> +++ b/backend/pieusb_buffer.c
> @@ -156,7 +156,11 @@ sanei_pieusb_buffer_create(struct Pieusb_Read_Buffer* buffer, SANE_Int width, SA
>      snprintf(buffer->buffer_name, L_tmpnam, "/tmp/sane.XXXXXX");
>      if (buffer->data_file != 0) /* might still be open from previous invocation */
>        close(buffer->data_file);
>      buffer->data_file = mkostemp(buffer->buffer_name, O_RDWR | O_CREAT | O_EXCL | O_TRUNC);

Hmm, from the manpage:

  The mkostemp() function is like mkstemp(), with the difference that
  the following bits―with the same meaning as for open(2)―may be
  specified in flags: O_APPEND, O_CLOEXEC, and O_SYNC.  Note that when
  creating the file, mkostemp() includes the values O_RDWR, O_CREAT, and
  O_EXCL in the flags argument given to open(2); including these values
  in the flags argument given to mkostemp() is unnecessary, and produces
  errors on some systems.

So the first three flags shouldn't be specified to begin with.  The last
flag, O_TRUNC, is not mentioned as supported but, given the fact that
mkostemp() is supposed to create a file that does not exist yet, the
flag does not achieve anything.

That leaves zero flags to be passed, so the mkostemp() call reduces to

I would simply call mkstemp() unconditionally.  That way you also don't
have to add it to AC_CHEC_FUNCS() in configure.in anymore.

BTW, backend/pieusb_buffer.c is the only place where mkostemp() is used
at the moment.

> +#else
> +    buffer->data_file = mkstemp(buffer->buffer_name);
> +#endif
>      if (buffer->data_file == -1) {
>          buffer->data_file = 0;
>          buffer->data = NULL;
> diff --git a/configure.in b/configure.in
> index b55e7be..d868722 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -309,7 +309,7 @@ AC_FUNC_MMAP
>  AC_CHECK_FUNCS(atexit ioperm i386_set_ioperm \
>      mkdir strftime strstr strtod  \
>      cfmakeraw tcsendbreak strcasecmp strncasecmp _portaccess \
> -    getaddrinfo getnameinfo poll setitimer iopl getuid getpass)
> +    getaddrinfo getnameinfo poll setitimer iopl getuid getpass mkostemp)
>  AC_REPLACE_FUNCS(getenv isfdtype sigprocmask snprintf \
>      strcasestr strdup strndup strsep usleep sleep syslog vsyslog)

Hope this helps,
Olaf Meeuwissen, LPIC-2            FSF Associate Member since 2004-01-27
 GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13  F43E B8A4 A88A F84A 2DD9
 Support Free Software                        https://my.fsf.org/donate
 Join the Free Software Foundation              https://my.fsf.org/join

More information about the sane-devel mailing list