Archive-Unzip-Burst

 view release on metacpan or  search on metacpan

unzip-6.0/macos/source/mactime.c  view on Meta::CPAN

/*
  Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.

  See the accompanying file LICENSE, version 2000-Apr-09 or later
  (the contents of which are also included in zip.h) for terms of use.
  If, for some reason, all these files are missing, the Info-ZIP license
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/* -----------------------------------------------------------------------------

The original functions (Metrowerks Codewarrior pro 3.0) gmtime, localtime,
mktime and time do not work correctly. The supplied link library mactime.c
contains replacement functions for them.

 *     Caveat: On a Mac, we only know the GMT and DST offsets for
 *     the current time, not for the time in question.
 *     Mac has no support for DST handling.
 *     DST changeover is all manually set by the user.


------------------------------------------------------------------------------*/

/*****************************************************************************/
/*  Includes                                                                 */
/*****************************************************************************/

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <OSUtils.h>

#include "mactime.h"


/*
The MacOS function GetDateTime returns  the
number of seconds elapsed since midnight, January 1, 1904.
*/
const unsigned long MacOS_2_Unix = 2082844800L;


/*****************************************************************************/
/*  Macros, typedefs                                                         */
/*****************************************************************************/


#ifndef TEST_TIME_LIB
#define my_gmtime    gmtime
#define my_localtime localtime
#define my_mktime    mktime
#define my_time      time
#endif


/*****************************************************************************/
/*  Prototypes                                                               */
/*****************************************************************************/
/* internal prototypes */
static void clear_tm(struct tm * tm);
static long GMTDelta(void);
static Boolean DaylightSaving(void);
static time_t GetTimeMac(void);
static time_t Mactime(time_t *timer);
static void   normalize(int *i,int *j,int norm);
static struct tm *time2tm(const time_t *timer);
static time_t tm2time(struct tm *tp);

/* Because serial port and SLIP conflict with ReadXPram calls,
   we cache the call here so we don't hang on calling ReadLocation()  */
static void myReadLocation(MachineLocation * loc);


/* prototypes for STD lib replacement functions */
struct tm *my_gmtime(const time_t *t);
struct tm *my_localtime(const time_t *t);
time_t my_mktime(struct tm *tp);
time_t my_time(time_t *t);


/*****************************************************************************/
/*  Functions                                                                */
/*****************************************************************************/

 /*
 *  Mac file times are based on 1904 Jan 1 00:00 local time,
 *  not 1970 Jan 1 00:00 UTC.
 *  So we have to convert the time stamps into UNIX UTC
 *  compatible values.
 */
time_t MacFtime2UnixFtime(unsigned long macftime)
{
    long UTCoffset;

    GetGMToffsetMac(macftime, &UTCoffset);
    MACOS_TO_UNIX(macftime);
    macftime -= UTCoffset;

    return macftime;
}


 /*
 *  Mac file times are based on 1904 Jan 1 00:00 local time,



( run in 1.106 second using v1.01-cache-2.11-cpan-5735350b133 )