Ignore:
Timestamp:
Sep 21, 2017, 5:11:07 PM (8 years ago)
Author:
bird
Message:

kmk,lib: ported kmk_touch to windows (nt).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/touch.c

    r3059 r3060  
    3838# include <ctype.h>
    3939# include <io.h>
     40# include <sys/timeb.h>
    4041#else
    4142# include <unistd.h>
     
    4748#include "kbuild_version.h"
    4849#include "kmkbuiltin.h"
     50
     51#ifdef _MSC_VER
     52# include "nt/ntstat.h"
     53# undef FILE_TIMESTAMP_HI_RES
     54# define FILE_TIMESTAMP_HI_RES 1
     55#endif
     56
    4957
    5058/*********************************************************************************************************************************
     
    99107    int             cFiles;
    100108    /** The specified files.   */
    101     const char    **papszFiles;
     109    char          **papszFiles;
    102110} KMKTOUCHOPTS;
    103111typedef KMKTOUCHOPTS *PKMKTOUCHOPTS;
     112
    104113
    105114
     
    217226{
    218227    const char * const  pszTsIn = pszTs;
    219     KBOOL               fIsZulu = K_FALSE;
    220228    struct tm           ExpTime;
    221229
     
    244252        return touch_error("Malformed timestamp '%s' given to -d: expected to two digit month at position 6 followed by a dash",
    245253                           pszTsIn);
    246     ExpTime.tm_mon = TWO_CHARS_TO_INT(pszTs[0], pszTs[1]);
     254    ExpTime.tm_mon = TWO_CHARS_TO_INT(pszTs[0], pszTs[1]) - 1;
    247255    pszTs += 3;
    248256
     
    301309
    302310    /* zulu time indicator */
     311    ExpTime.tm_isdst = -1;
    303312    if (*pszTs == 'Z' || *pszTs == 'z')
    304313    {
    305         fIsZulu = K_TRUE;
     314        ExpTime.tm_isdst = 0;
    306315        pszTs++;
    307316        if (*pszTs != '\0')
     
    315324     * Convert to UTC seconds using either timegm or mktime.
    316325     */
    317     ExpTime.tm_isdst = fIsZulu ? 0 : -1;
    318326    ExpTime.tm_yday  = -1;
    319327    ExpTime.tm_wday  = -1;
    320     pDst->tv_sec  = fIsZulu ? timegm(&ExpTime) : mktime(&ExpTime);
    321     if (pDst->tv_sec != -1)
    322         return 0;
    323     return touch_error("%s failed on '%s': %s", fIsZulu ? "timegm" : "mktime", pszTs, strerror(errno));
     328    if (ExpTime.tm_isdst == 0)
     329    {
     330        pDst->tv_sec = timegm(&ExpTime);
     331        if (pDst->tv_sec == -1)
     332            return touch_error("timegm failed on '%s': %s", pszTs, strerror(errno));
     333    }
     334    else
     335    {
     336        pDst->tv_sec = mktime(&ExpTime);
     337        if (pDst->tv_sec == -1)
     338            return touch_error("mktime failed on '%s': %s", pszTs, strerror(errno));
     339    }
     340    return 0;
    324341}
    325342
     
    421438    }
    422439
    423     pExpTime->tm_mon  = TWO_CHARS_TO_INT(pszTs[cchTsNoSec - 8], pszTs[cchTsNoSec - 7]);
     440    pExpTime->tm_mon  = TWO_CHARS_TO_INT(pszTs[cchTsNoSec - 8], pszTs[cchTsNoSec - 7]) - 1;
    424441    pExpTime->tm_mday = TWO_CHARS_TO_INT(pszTs[cchTsNoSec - 6], pszTs[cchTsNoSec - 5]);
    425442    pExpTime->tm_hour = TWO_CHARS_TO_INT(pszTs[cchTsNoSec - 4], pszTs[cchTsNoSec - 3]);
     
    894911    Opts.fDereference   = K_TRUE;
    895912    Opts.cFiles         = 0;
    896     Opts.papszFiles     = (const char **)calloc(argc, sizeof(const char *));
     913    Opts.papszFiles     = (char **)calloc(argc, sizeof(char *));
    897914    if (Opts.papszFiles)
    898915    {
Note: See TracChangeset for help on using the changeset viewer.