This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH v2 1/7] common: add scoped_fd
- From: "Metzger, Markus T" <markus dot t dot metzger at intel dot com>
- To: Yao Qi <qiyaoltc at gmail dot com>
- Cc: GDB Patches <gdb-patches at sourceware dot org>
- Date: Mon, 19 Feb 2018 15:28:46 +0000
- Subject: RE: [PATCH v2 1/7] common: add scoped_fd
- Authentication-results: sourceware.org; auth=none
- Dlp-product: dlpe-windows
- Dlp-reaction: no-action
- Dlp-version: 11.0.0.116
- References: <1516976072-19282-1-git-send-email-markus.t.metzger@intel.com> <1516976072-19282-2-git-send-email-markus.t.metzger@intel.com> <CAH=s-PMr4qeZ3JodCAtQy_Xh53pwHLEkf-7u2t8wWgj8NnU0Ag@mail.gmail.com> <A78C989F6D9628469189715575E55B2369647D3E@IRSMSX104.ger.corp.intel.com> <CAH=s-PNtuXjnRF3sa7gEbwnkJdyS-cexRX9KvDB59PDkiJ_LXQ@mail.gmail.com> <A78C989F6D9628469189715575E55B23696484A5@IRSMSX104.ger.corp.intel.com>
Hello Yao,
Looks like they added mkstemp() in 2015 after a few complaints:
https://sourceforge.net/u/jeisele123/mingw-w64/ci/f713f639f6f017371c5176f4deab07d1a92473b4/
How about checking for mkstemp and, if not available, falling back to tmpnam.
Something like this:
#ifndef HAVE_MKSTEMP
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
/* Define a racy version of mkstemp based on tmpnam for systems that do not
support mkstemp. */
static int
mkstemp (char *name)
{
if (strlen (name) < L_tmpnam)
return -1;
name = tmpnam (name);
if (name == nullptr)
return -1;
return open (name);
}
#endif /* HAVE_MKSTEMP */
regards,
markus.
> -----Original Message-----
> From: Metzger, Markus T
> Sent: 14 February 2018 18:26
> To: Yao Qi <qiyaoltc@gmail.com>
> Cc: GDB Patches <gdb-patches@sourceware.org>
> Subject: RE: [PATCH v2 1/7] common: add scoped_fd
>
> Hello Yao,
>
> > > Could you try setting, say, _POSIX_C_SOURCE or try using mkostemp()
> > > instead
> > of mkstemp()?
> > >
> >
> > None of them works with my i686-w64-mingw32-g++ 4.8.2. :(
>
> Thanks for trying. I will look into this.
>
> Regards,
> Markus.
>
> > -----Original Message-----
> > From: Yao Qi [mailto:qiyaoltc@gmail.com]
> > Sent: 14 February 2018 16:23
> > To: Metzger, Markus T <markus.t.metzger@intel.com>
> > Cc: GDB Patches <gdb-patches@sourceware.org>
> > Subject: Re: [PATCH v2 1/7] common: add scoped_fd
> >
> > On Tue, Feb 13, 2018 at 5:28 PM, Metzger, Markus T
> > <markus.t.metzger@intel.com> wrote:
> > >
> > > This is supposed to be a glibc function. But it is guarded by some
> > > feature
> > macros.
> > > Quote from mkstemp(3): "
> > >
> > > mkstemp():
> > > _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500 ||
> > _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
> > > || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200112L
> > >
> > > mkostemp(): _GNU_SOURCE
> > > mkstemps(): _BSD_SOURCE || _SVID_SOURCE
> > > mkostemps(): _GNU_SOURCE
> > > "
> > >
> > > Maybe the newer compiler is setting some macros automatically that
> > > the older
> > compiler doesn't set.
> > > Could you try setting, say, _POSIX_C_SOURCE or try using mkostemp()
> > > instead
> > of mkstemp()?
> > >
> >
> > None of them works with my i686-w64-mingw32-g++ 4.8.2. :(
> >
> > > If that doesn't help, I'll try to find a Ubuntu 14.04 to reproduce the issue.
> > >
> >
> > --
> > Yao (齐尧)
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928