public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Patrick Chkoreff <pc@fexl.com>
To: cygwin@cygwin.com
Subject: Re: setrlimit always fails
Date: Mon, 15 Feb 2021 14:54:26 -0500	[thread overview]
Message-ID: <b55c516e-4b20-2dbb-3785-a7006dd049eb@fexl.com> (raw)
In-Reply-To: <20210215091419.GJ4251@calimero.vinschen.de>

Corinna Vinschen wrote on 2/15/21 4:14 AM:

> That looks wrong.  The __USE_<standard> flags are internal flags from
> GLibc and not supposed to be used by application code.  Check the Linux
> man page for strptime, the usage of _XOPEN_SOURCE or another flag
> including _XOPEN_SOURCE (e. g. _GNU_SOURCE) is required.  So this:
> 
>   #define _XOPEN_SOURCE
>   #include <time.h>

One would think so, but I tried it on two different Linux machines and
it failed with:

error: ‘strptime’ undeclared

To fix that, I must define _USE_XOPEN.

I have stripped down my requirements as far as possible.  I created a
file "test_stuff.c" as follows, with the most minimal preambles that
actually work on each platform (Cygwin or Linux):

~~
#ifdef __CYGWIN__

#define _XOPEN_SOURCE
#include <stdint.h>
#include <sys/time.h>
#include <time.h>

#else

#include <stdint.h>
#include <sys/time.h>
#define __USE_XOPEN
#include <time.h>

#endif

void stuff(void)
    {
    uint64_t n;
    time_t t;
    struct timeval tv;
    (void)n;
    (void)t;
    (void)tv;
    (void)time;
    (void)gettimeofday;
    (void)timegm;
    (void)timelocal;
    (void)gmtime;
    (void)localtime;
    (void)strftime;
    (void)strptime;
    }

~~


That compiles successfully on both Cygwin and Linux, using the simple
command "gcc -c test_stuff.c".

Note that in the case of Linux, the define __USE_XOPEN is absolutely
essential, and define _XOPEN_SOURCE makes no difference.  This is an
experimental fact on the two Linux machines I tested.

Note also that on Cygwin, I must define _XOPEN_SOURCE before including
stdint.h.  There are all kinds of weird interactions and different
ordering requirements between the Linux and Cygwin code.  So let's look
at some options, and show how they work on both Linux and Cygwin.

OPTION 1:

#define _XOPEN_SOURCE
#include <stdint.h>
#include <sys/time.h>
#include <time.h>

Result on Cygwin: SUCCESS

Result on Linux:
error: ‘timegm’ undeclared
error: ‘timelocal’ undeclared


OPTION 2:

#include <stdint.h>
#include <sys/time.h>
#define _XOPEN_SOURCE
#include <time.h>

Result on Cygwin:
error: 'strptime' undeclared

Result on Linux:
error: 'strptime' undeclared


OPTION 3:

#include <stdint.h>
#include <sys/time.h>
#define __USE_XOPEN
#define _XOPEN_SOURCE
#include <time.h>

Result on Cygwin:
error: 'strptime' undeclared

Result on Linux:  SUCCESS


Consequently I see nothing simpler than the test_stuff.c code at the top
of this email.  By all means correct me if I am wrong.  Propose a
preamble on this list, and I'll jam it into my test code and see if it
compiles on both Cygwin and Linux.  I can literally compile the exact
same code file on both Cygwin and Linux, due to how I've got sharing set up.


-- Patrick

  reply	other threads:[~2021-02-15 19:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 15:23 Patrick Chkoreff
2021-02-12  2:06 ` Ken Brown
2021-02-12  7:26   ` Brian Inglis
2021-02-12  9:12     ` Corinna Vinschen
2021-02-12 18:56       ` Brian Inglis
2021-02-12 20:38         ` Brian Inglis
2021-02-12 15:11   ` Patrick Chkoreff
2021-02-15  9:14     ` Corinna Vinschen
2021-02-15 19:54       ` Patrick Chkoreff [this message]
2021-02-15 20:48         ` Corinna Vinschen
2021-02-16 14:53           ` Patrick Chkoreff
2021-02-16 15:22             ` Marco Atzeri
2021-02-16 18:33               ` Brian Inglis
2021-02-12  9:11 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b55c516e-4b20-2dbb-3785-a7006dd049eb@fexl.com \
    --to=pc@fexl.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).