From: Charles Forsyth <charles.forsyth@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] off topic - a good Git reference
Date: Wed, 30 Sep 2015 08:59:40 +0100 [thread overview]
Message-ID: <CAOw7k5jB8GHF=--f0-JRKDuD6sTg95EqDJMhE29rzh-tCSoTNA@mail.gmail.com> (raw)
In-Reply-To: <CAOw7k5i8XqVe3Wk+xvEE+8T-UJ-t4NeO757L__BoLDO6aOrdqA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]
On 30 September 2015 at 08:47, Charles Forsyth <charles.forsyth@gmail.com>
wrote:
> I was being sarcastic about the portability of so much contemporary C code.
Here's a small but representative example.
#if HAVE_SYS_TIME_H
#include <sys/time.h
#elif HAVE_TIME_H
#include <time.h>
#endif
#if HAVE_SYS_CLOCK_GETTIME
time_t
time_now(void)
{
struct timespec timespec_value;
(void) clock_gettime(CLOCK_REALTIME, ×pec_value);
return timespec_value.tv_seconds;
}
#elif HAVE_SYS_GETTIMEOFDAY
time_t
time_now(void)
{
struct timeval timeval_value;
(void) gettimeofday(&timeval_value, (struct timezone *) NULL);
return timeval_value.tv_seconds;
}
#elif HAVE_SYS_TIME
time_t
time_now(void)
{
time_t seconds_since_epoch;
(void) time(&seconds_since_epoch);
return seconds_since_epoch;
}
#endif
./configure # work out which HAVE_... definitions to use
Usually there are a few more alternatives enumerated. Surprisingly often,
the microseconds or nanoseconds
value is discarded, to get the seconds. You could just use #include
<time.h> and call time(NULL) to get that, but where's the fun?
[-- Attachment #2: Type: text/html, Size: 2476 bytes --]
next prev parent reply other threads:[~2015-09-30 7:59 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-29 16:58 Skip Tavakkolian
2015-09-29 17:18 ` Tiago Natel
2015-09-29 19:42 ` Kurt H Maier
2015-09-30 3:11 ` erik quanstrom
2015-09-30 7:18 ` Charles Forsyth
2015-09-30 7:36 ` hiro
2015-09-30 7:47 ` Charles Forsyth
2015-09-30 7:59 ` Charles Forsyth [this message]
2015-10-01 17:31 ` Jeff Sickel
2015-10-01 17:38 ` Charles Forsyth
2015-10-01 17:38 ` Ryan Gonzalez
2015-10-01 17:47 ` arnold
2015-10-02 8:32 ` hiro
2015-10-02 8:57 ` Aram Hăvărneanu
2015-10-02 13:10 ` Joseph Stewart
2015-10-02 14:07 ` a.regenfuss
2015-10-02 14:10 ` Aram Hăvărneanu
2015-10-02 21:56 ` a.regenfuss
2015-10-03 1:43 ` Kurt H Maier
2015-10-03 2:30 ` erik quanstrom
2015-10-03 4:37 ` Nick Owens
2015-10-02 15:51 ` lucio
2015-10-02 21:43 ` a.regenfuss
2015-10-02 19:27 ` Steve Simon
2015-10-02 15:23 ` Steffen Nurpmeso
2015-09-30 8:15 ` lucio
2015-09-30 8:25 ` hiro
2015-09-30 7:43 ` Ori Bernstein
2015-09-30 8:22 ` lucio
2015-09-30 7:43 ` lucio
2015-09-30 10:01 ` Brantley Coile
2015-09-30 10:08 ` Steve Simon
2015-10-03 3:00 ` erik quanstrom
2015-10-01 13:54 ` Prof Brucee
2015-09-30 8:15 ` lego12239
2015-10-03 4:48 erik quanstrom
2015-10-03 5:03 ` Andrew Simmons
2015-10-03 5:19 ` Jacob Todd
2015-10-03 19:26 ` Jeff Sickel
2015-10-03 19:57 ` Jacob Todd
2015-10-05 4:24 ` Prof Brucee
2015-10-07 2:37 sl
2015-10-07 15:17 ` Álvaro Jurado
2015-10-07 16:24 ` Charles Forsyth
2015-10-07 21:23 ` Álvaro Jurado
2015-10-10 15:23 ` erik quanstrom
2015-10-12 11:37 ` Steffen Nurpmeso
2015-10-10 15:26 ` erik quanstrom
2015-10-10 18:25 ` Álvaro Jurado
2015-10-12 11:47 ` Charles Forsyth
2015-10-12 16:49 ` Álvaro Jurado
2015-10-12 17:00 ` Charles Forsyth
2015-10-12 17:54 ` Álvaro Jurado
2015-10-12 20:25 ` Giacomo Tesio
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='CAOw7k5jB8GHF=--f0-JRKDuD6sTg95EqDJMhE29rzh-tCSoTNA@mail.gmail.com' \
--to=charles.forsyth@gmail.com \
--cc=9fans@9fans.net \
/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 NNTP newsgroup(s).