git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Trying to use AUTHOR_DATE

From
JCJuliusz Chroboczek <juliusz.chroboczek@pps.jussieu.fr>
Date
Apr 30, 2005, 21:59 UTC
Message-ID
<7ism18exin.fsf@lanthane.pps.jussieu.fr>
In-Reply-To
<Pine.LNX.4.58.0504301322130.2296@ppc970.osdl.org>
Hi,

Here's the code I'm using in darcs-git (copied from Polipo, another project of mine). You're welcome to use it in any way you see fit.

sprintf_a is defined as strdup of sprintf.
                                        Juliusz
#if defined __GLIBC__
#define HAVE_TM_GMTOFF
#define HAVE_SETENV
#ifndef __UCLIBC__
#define HAVE_TIMEGM
#endif
#endif

#if defined(__linux__) && (__GNU_LIBRARY__ == 1) /* Linux libc 5 */ #define HAVE_TIMEGM #define HAVE_SETENV #endif

#ifdef BSD #define HAVE_TM_GMTOFF #define HAVE_SETENV #endif

#ifdef __CYGWIN__ #define HAVE_SETENV #endif

#if _POSIX_VERSION >= 200112L #define HAVE_SETENV #endif

#define HAVE_TZSET
/* Like mktime(3), but UTC rather than local time */
#if defined(HAVE_TIMEGM)
time_t
mktime_gmt(struct tm *tm)
{
    return timegm(tm);
}
#elif defined(HAVE_TM_GMTOFF)
time_t
mktime_gmt(struct tm *tm)
{
    time_t t;
    struct tm *ltm;
    t = mktime(tm);
    if(t < 0)
        return -1;
    ltm = localtime(&t);
    if(ltm == NULL)
        return -1;
    return t + ltm->tm_gmtoff;
}
#elif defined(HAVE_TZSET)
#ifdef HAVE_SETENV
/* Taken from the Linux timegm(3) man page. */
time_t
mktime_gmt(struct tm *tm)
{
    time_t t;
    char *tz;
    tz = getenv("TZ");
    setenv("TZ", "", 1);
    tzset();
    t = mktime(tm);
    if(tz)
        setenv("TZ", tz, 1);
    else
        unsetenv("TZ");
    tzset();
    return t;
}
#else
time_t
mktime_gmt(struct tm *tm)
{
    time_t t;
    char *tz;
    static char *old_tz = NULL;
    tz = getenv("TZ");
    putenv("TZ=");
    tzset();
    t = mktime(tm);
    if(old_tz)
        free(old_tz);
    if(tz)
        old_tz = sprintf_a("TZ=%s", tz);
    else
        old_tz = strdup("TZ");  /* XXX - non-portable? */
    if(old_tz)
        putenv(old_tz);
    tzset();
    return t;
}
#endif
#else
#error no mktime_gmt implementation on this platform
#endif
Previous: Linus TorvaldsNext: Edgar Toernig
Message 10 of 31 in “RE: Trying to use AUTHOR_DATE”
  1. Luck, TonyApr 30, 2005
  2. H. Peter AnvinApr 30, 2005
  3. Linus TorvaldsApr 30, 2005
  4. Linus TorvaldsApr 30, 2005
  5. Russ AllberyApr 30, 2005
  6. David WoodhouseApr 30, 2005
  7. Edgar ToernigApr 30, 2005
  8. Russ AllberyApr 30, 2005
  9. Linus TorvaldsApr 30, 2005
  10. Juliusz ChroboczekApr 30, 2005
  11. Edgar ToernigApr 30, 2005
  12. Linus TorvaldsApr 30, 2005
  13. Linus TorvaldsMay 1, 2005
  14. Randy.DunlapMay 1, 2005
  15. Edgar ToernigMay 1, 2005
  16. Junio C HamanoApr 30, 2005
  17. Edgar ToernigApr 30, 2005
  18. David WoodhouseApr 30, 2005
  19. Kay SieversApr 30, 2005
  20. David WoodhouseApr 30, 2005
  21. Edgar ToernigApr 30, 2005
  22. David WoodhouseApr 30, 2005
  23. Edgar ToernigApr 30, 2005
  24. Krzysztof HalasaMay 2, 2005
  25. H. Peter AnvinMay 2, 2005
  26. Krzysztof HalasaMay 2, 2005
  27. H. Peter AnvinMay 2, 2005
  28. Krzysztof HalasaMay 3, 2005
  29. H. Peter AnvinMay 3, 2005
  30. H. Peter AnvinApr 30, 2005
  31. Edgar ToernigApr 30, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.