VirtualBox

Changeset 3060 in kBuild


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

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

Location:
trunk/src
Files:
1 added
9 edited
1 copied

Legend:

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

    r2901 r3060  
    3737#include <fcntl.h>
    3838#include <sys/stat.h>
     39#include <sys/timeb.h>
    3940#include "err.h"
    4041#include "mscfakes.h"
     42
     43#include "nt/ntutimes.h"
     44#undef utimes
     45#undef lutimes
    4146
    4247#define timeval windows_timeval
    4348#include <Windows.h>
    4449#undef timeval
     50
    4551
    4652/*******************************************************************************
     
    460466
    461467
    462 int utimes(const char *pszPath, const struct timeval *paTimes)
    463 {
    464     /** @todo implement me! */
    465     return 0;
    466 }
    467 
    468 
    469468/* We override the libc write function (in our modules only, unfortunately) so
    470469   we can kludge our way around a ENOSPC problem observed on build servers
     
    651650
    652651
     652int utimes(const char *pszPath, const struct timeval *paTimes)
     653{
     654    BirdTimeVal_T aTimes[2];
     655    aTimes[0].tv_sec  = paTimes[0].tv_sec;
     656    aTimes[0].tv_usec = paTimes[0].tv_usec;
     657    aTimes[1].tv_sec  = paTimes[1].tv_sec;
     658    aTimes[1].tv_usec = paTimes[1].tv_usec;
     659    return birdUtimes(pszPath, aTimes);
     660}
     661
     662
     663int lutimes(const char *pszPath, const struct timeval *paTimes)
     664{
     665    BirdTimeVal_T aTimes[2];
     666    aTimes[0].tv_sec  = paTimes[0].tv_sec;
     667    aTimes[0].tv_usec = paTimes[0].tv_usec;
     668    aTimes[1].tv_sec  = paTimes[1].tv_sec;
     669    aTimes[1].tv_usec = paTimes[1].tv_usec;
     670    return birdUtimes(pszPath, aTimes);
     671}
     672
     673
     674int gettimeofday(struct timeval *pNow, void *pvIgnored)
     675{
     676    struct __timeb64 Now;
     677    int rc = _ftime64_s(&Now);
     678    if (rc == 0)
     679    {
     680        pNow->tv_sec  = Now.time;
     681        pNow->tv_usec = Now.millitm * 1000;
     682        return 0;
     683    }
     684    errno = rc;
     685    return -1;
     686}
     687
     688
     689struct tm *localtime_r(const __time64_t *pNow, struct tm *pResult)
     690{
     691    int rc = _localtime64_s(pResult, pNow);
     692    if (rc == 0)
     693        return pResult;
     694    errno = rc;
     695    return NULL;
     696}
     697
     698
     699__time64_t timegm(struct tm *pNow)
     700{
     701    return _mkgmtime64(pNow);
     702}
     703
     704
    653705/**
    654706 * Checks if the given file descriptor is a pipe or not.
  • trunk/src/kmk/kmkbuiltin/mscfakes.h

    r2766 r3060  
    2828#ifdef _MSC_VER
    2929
     30#define timeval windows_timeval
     31
    3032/* Include the config file (kmk's) so we don't need to duplicate stuff from it here. */
    3133#include "config.h"
     
    5052# define lseek _lseeki64
    5153#endif
     54
     55#undef timeval
    5256
    5357#undef  PATH_MAX
     
    104108#endif
    105109
    106 #if !defined(timerisset) && defined(MSCFAKES_NO_WINDOWS_H)
    107110struct timeval
    108111{
    109     long tv_sec;
     112    __time64_t tv_sec;
    110113    long tv_usec;
    111114};
    112 #endif
    113115
    114116struct iovec
     
    134136#define chmod msc_chmod
    135137#define lchown(path, uid, gid) chown(path, uid, gid)
    136 #define lutimes(path, tvs) utimes(path, tvs)
    137138int link(const char *pszDst, const char *pszLink);
    138139int mkdir_msc(const char *path, mode_t mode);
     
    158159int symlink(const char *pszDst, const char *pszLink);
    159160int utimes(const char *pszPath, const struct timeval *paTimes);
     161int lutimes(const char *pszPath, const struct timeval *paTimes);
    160162ssize_t writev(int fd, const struct iovec *vector, int count);
     163
     164int gettimeofday(struct timeval *pNow, void *pvIgnored);
     165struct tm *localtime_r(const __time64_t *pNow, struct tm *pResult);
     166__time64_t timegm(struct tm *pNow);
     167#undef mktime
     168#define mktime _mktime64
    161169
    162170/* bird write ENOSPC hacks. */
  • 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    {
  • trunk/src/kmk/w32/pathstuff.c

    r2849 r3060  
    1616this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1717
    18 #include <Windows.h> /* bird */
    1918#include "make.h"
    2019#include <string.h>
  • trunk/src/lib/Makefile.kmk

    r2994 r3060  
    5353       nt/ntstat.c \
    5454       nt/ntunlink.c \
     55       nt/ntutimes.c \
    5556       nt/fts-nt.c \
    5657       nt/kFsCache.c \
  • trunk/src/lib/nt/nthlp.h

    r3009 r3060  
    8989
    9090
     91static __inline void birdNtTimeToTimeVal(__int64 iNtTime, BirdTimeVal_T *pTimeVal)
     92{
     93    iNtTime -= BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
     94    pTimeVal->tv_sec  = iNtTime / 10000000;
     95    pTimeVal->tv_usec = (iNtTime % 10000000) / 10;
     96}
     97
     98
     99static __inline __int64 birdNtTimeFromTimeVal(BirdTimeVal_T const *pTimeVal)
     100{
     101    __int64 iNtTime = pTimeVal->tv_sec * 10000000;
     102    iNtTime += pTimeVal->tv_usec * 10;
     103    iNtTime += BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
     104    return iNtTime;
     105}
     106
     107
    91108#endif
    92109
  • trunk/src/lib/nt/nttypes.h

    r2702 r3060  
    55
    66/*
    7  * Copyright (c) 2005-2013 knut st. osmundsen <[email protected]>
     7 * Copyright (c) 2005-2017 knut st. osmundsen <[email protected]>
    88 *
    99 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3434#include <sys/types.h>
    3535
     36typedef struct BirdTimeVal
     37{
     38    __int64       tv_sec;
     39    __int32       tv_usec;
     40    __int32       tv_padding0;
     41} BirdTimeVal_T;
     42
    3643typedef struct BirdTimeSpec
    3744{
     
    4754#endif
    4855
    49 
  • trunk/src/lib/nt/ntunlink.c

    r3009 r3060  
    55
    66/*
    7  * Copyright (c) 2005-2013 knut st. osmundsen <[email protected]>
     7 * Copyright (c) 2005-2017 knut st. osmundsen <[email protected]>
    88 *
    99 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3333*   Header Files                                                               *
    3434*******************************************************************************/
    35 #include <stdio.h>
    36 #include <errno.h>
    37 #include <malloc.h>
     35#include "ntunlink.h"
    3836
    3937#include "ntstuff.h"
  • trunk/src/lib/nt/ntunlink.h

    r3009 r3060  
    3333
    3434#include "nttypes.h"
     35#include <wchar.h>
    3536
    3637int birdUnlink(const char *pszFile);
  • trunk/src/lib/nt/ntutimes.h

    r3049 r3060  
    11/* $Id$ */
    22/** @file
    3  * MSC + NT unlink and variations.
     3 * MSC + NT utimes and lutimes.
    44 */
    55
    66/*
    7  * Copyright (c) 2005-2013 knut st. osmundsen <[email protected]>
     7 * Copyright (c) 2005-2017 knut st. osmundsen <[email protected]>
    88 *
    99 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2929 */
    3030
    31 #ifndef ___nt_ntunlink_h
    32 #define ___nt_ntunlink_h
     31#ifndef ___nt_ntutimes_h
     32#define ___nt_ntutimes_h
    3333
    3434#include "nttypes.h"
    3535
    36 int birdUnlink(const char *pszFile);
    37 int birdUnlinkW(const wchar_t *pwszFile);
    38 int birdUnlinkEx(void *hRoot, const char *pszFile);
    39 int birdUnlinkExW(void *hRoot, const wchar_t *pwszFile);
    40 int birdUnlinkForced(const char *pszFile);
    41 int birdUnlinkForcedW(const wchar_t *pwszFile);
    42 int birdUnlinkForcedEx(void *hRoot, const char *pszFile);
    43 int birdUnlinkForcedExW(void *hRoot, const wchar_t *pszFile);
    44 int birdUnlinkForcedFast(const char *pszFile);
    45 int birdUnlinkForcedFastW(const wchar_t *pwszFile);
    46 int birdUnlinkForcedFastEx(void *hRoot, const char *pszFile);
    47 int birdUnlinkForcedFastExW(void *hRoot, const wchar_t *pwszFile);
     36int birdUtimes(const char *pszFile, BirdTimeVal_T paTimes[2]);
     37int birdLUtimes(const char *pszFile, BirdTimeVal_T paTimes[2]);
    4838
    49 #undef  unlink
    50 #define unlink(a_pszPath)     birdUnlinkForced(a_pszPath)
     39#undef  utimes
     40#define utimes(a_pszPath, a_paTimes)    birdUtimes(a_pszPath, a_paTimes)
     41#undef  lutimes
     42#define lutimes(a_pszPath, a_paTimes)   birdLUtimes(a_pszPath, a_paTimes)
    5143
    5244#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette