* localtime.c: Changed whole file to become C++ clean. Rename to

localtime.cc.
        * localtime.cc (tzload): Preserve errno.
This commit is contained in:
Corinna Vinschen 2001-07-25 21:58:21 +00:00
parent a7670c1e82
commit 09ff05f7f9
2 changed files with 62 additions and 140 deletions

View File

@ -1,3 +1,9 @@
Wed 25 Jul 2001 23:46:00 Corinna Vinschen <corinna@vinschen.de>
* localtime.c: Changed whole file to become C++ clean. Rename to
localtime.cc.
* localtime.cc (tzload): Preserve errno.
Fri 20 Jul 2001 11:15:50 PM EDT Christopher Faylor <cgf@cygnus.com> Fri 20 Jul 2001 11:15:50 PM EDT Christopher Faylor <cgf@cygnus.com>
* cygheap.cc (cygheap_fixup_in_child): Attempt Win95 workaround. * cygheap.cc (cygheap_fixup_in_child): Attempt Win95 workaround.

View File

@ -6,6 +6,7 @@
/* CYGNUS LOCAL */ /* CYGNUS LOCAL */
#include "winsup.h" #include "winsup.h"
#include "cygerrno.h"
#include <windows.h> #include <windows.h>
#define lint #define lint
@ -97,7 +98,6 @@ static char privatehid[] = "@(#)private.h 7.48";
#include "sys/types.h" /* for time_t */ #include "sys/types.h" /* for time_t */
#include "stdio.h" #include "stdio.h"
#include "errno.h"
#include "limits.h" /* for CHAR_BIT */ #include "limits.h" /* for CHAR_BIT */
#include "time.h" #include "time.h"
#include "stdlib.h" #include "stdlib.h"
@ -195,28 +195,6 @@ extern int unlink P((const char * filename));
#define remove unlink #define remove unlink
#endif /* !defined remove */ #endif /* !defined remove */
/*
** Some ancient errno.h implementations don't declare errno.
** But some newer errno.h implementations define it as a macro.
** Fix the former without affecting the latter.
*/
#ifndef errno
extern int errno;
#endif /* !defined errno */
/*
** Private function declarations.
*/
char * icalloc P((int nelem, int elsize));
char * icatalloc P((char * old, const char * new));
char * icpyalloc P((const char * string));
char * imalloc P((int n));
void * irealloc P((void * pointer, int size));
void icfree P((char * pointer));
void ifree P((char * pointer));
char * scheck P((const char *string, const char *format));
/* /*
** Finally, some convenience items. ** Finally, some convenience items.
*/ */
@ -671,8 +649,7 @@ time_t altzone = 0;
#endif /* defined ALTZONE */ #endif /* defined ALTZONE */
static long static long
detzcode(codep) detzcode(const char *codep)
const char * const codep;
{ {
register long result; register long result;
register int i; register int i;
@ -736,13 +713,12 @@ settzname P((void))
#include "tz_posixrules.h" #include "tz_posixrules.h"
static int static int
tzload(name, sp) tzload(const char *name, struct state *sp)
register const char * name;
register struct state * const sp;
{ {
register const char * p; register const char * p;
register int i; register int i;
register int fid; register int fid;
save_errno save;
if (name == NULL && (name = TZDEFAULT) == NULL) if (name == NULL && (name = TZDEFAULT) == NULL)
return -1; return -1;
@ -916,8 +892,7 @@ static const int year_lengths[2] = {
*/ */
static const char * static const char *
getzname(strp) getzname(const char *strp)
register const char * strp;
{ {
register char c; register char c;
@ -935,11 +910,7 @@ register const char * strp;
*/ */
static const char * static const char *
getnum(strp, nump, min, max) getnum(const char *strp, int *nump, const int min, const int max)
register const char * strp;
int * const nump;
const int min;
const int max;
{ {
register char c; register char c;
register int num; register int num;
@ -968,9 +939,7 @@ const int max;
*/ */
static const char * static const char *
getsecs(strp, secsp) getsecs(const char *strp, long *secsp)
register const char * strp;
long * const secsp;
{ {
int num; int num;
@ -1010,9 +979,7 @@ long * const secsp;
*/ */
static const char * static const char *
getoffset(strp, offsetp) getoffset(const char *strp, long *offsetp)
register const char * strp;
long * const offsetp;
{ {
register int neg = 0; register int neg = 0;
@ -1037,9 +1004,7 @@ long * const offsetp;
*/ */
static const char * static const char *
getrule(strp, rulep) getrule(const char *strp, struct rule *rulep)
const char * strp;
register struct rule * const rulep;
{ {
if (*strp == 'J') { if (*strp == 'J') {
/* /*
@ -1091,11 +1056,8 @@ register struct rule * const rulep;
*/ */
static time_t static time_t
transtime(janfirst, year, rulep, offset) transtime(const time_t janfirst, const int year, const struct rule *rulep,
const time_t janfirst; long offset)
const int year;
register const struct rule * const rulep;
const long offset;
{ {
register int leapyear; register int leapyear;
register time_t value; register time_t value;
@ -1186,10 +1148,7 @@ const long offset;
*/ */
static int static int
tzparse(name, sp, lastditch) tzparse(const char *name, struct state *sp, const int lastditch)
const char * name;
register struct state * const sp;
const int lastditch;
{ {
const char * stdname; const char * stdname;
const char * dstname; const char * dstname;
@ -1399,8 +1358,7 @@ const int lastditch;
} }
static void static void
gmtload(sp) gmtload(struct state *sp)
struct state * const sp;
{ {
if (tzload(gmt, sp) != 0) if (tzload(gmt, sp) != 0)
(void) tzparse(gmt, sp, TRUE); (void) tzparse(gmt, sp, TRUE);
@ -1506,7 +1464,7 @@ tzsetwall P((void))
settzname(); settzname();
} }
void extern "C" void
tzset P((void)) tzset P((void))
{ {
const char * name = getenv("TZ"); const char * name = getenv("TZ");
@ -1559,7 +1517,7 @@ tzset P((void))
/*ARGSUSED*/ /*ARGSUSED*/
static void static void
localsub (const time_t * const timep, localsub (const time_t * const timep,
const long offset __attribute__ ((unused)), const long offset,
struct tm * const tmp) struct tm * const tmp)
{ {
register struct state * sp; register struct state * sp;
@ -1602,9 +1560,8 @@ localsub (const time_t * const timep,
#endif /* defined TM_ZONE */ #endif /* defined TM_ZONE */
} }
struct tm * extern "C" struct tm *
localtime(timep) localtime(const time_t *timep)
const time_t * const timep;
{ {
tzset(); tzset();
localsub(timep, 0L, &tm); localsub(timep, 0L, &tm);
@ -1614,10 +1571,8 @@ const time_t * const timep;
/* /*
* Re-entrant version of localtime * Re-entrant version of localtime
*/ */
struct tm * extern "C" struct tm *
localtime_r(timep, tm) localtime_r(const time_t *timep, struct tm *tm)
const time_t * const timep;
struct tm * tm;
{ {
localsub(timep, 0L, tm); localsub(timep, 0L, tm);
return tm; return tm;
@ -1628,10 +1583,7 @@ struct tm * tm;
*/ */
static void static void
gmtsub(timep, offset, tmp) gmtsub(const time_t *timep, const long offset, struct tm *tmp)
const time_t * const timep;
const long offset;
struct tm * const tmp;
{ {
if (!gmt_is_set) { if (!gmt_is_set) {
gmt_is_set = TRUE; gmt_is_set = TRUE;
@ -1663,9 +1615,8 @@ struct tm * const tmp;
#endif /* defined TM_ZONE */ #endif /* defined TM_ZONE */
} }
struct tm * extern "C" struct tm *
gmtime(timep) gmtime(const time_t *timep)
const time_t * const timep;
{ {
gmtsub(timep, 0L, &tm); gmtsub(timep, 0L, &tm);
return &tm; return &tm;
@ -1674,10 +1625,8 @@ const time_t * const timep;
/* /*
* Re-entrant version of gmtime * Re-entrant version of gmtime
*/ */
struct tm * extern "C" struct tm *
gmtime_r(timep, tm) gmtime_r(const time_t *timep, struct tm *tm)
const time_t * const timep;
struct tm * tm;
{ {
gmtsub(timep, 0L, tm); gmtsub(timep, 0L, tm);
return tm; return tm;
@ -1685,10 +1634,8 @@ struct tm * tm;
#ifdef STD_INSPIRED #ifdef STD_INSPIRED
struct tm * extern "C" struct tm *
offtime(timep, offset) offtime(const time_t *timep, const long offset)
const time_t * const timep;
const long offset;
{ {
gmtsub(timep, offset, &tm); gmtsub(timep, offset, &tm);
return &tm; return &tm;
@ -1697,11 +1644,8 @@ const long offset;
#endif /* defined STD_INSPIRED */ #endif /* defined STD_INSPIRED */
static void static void
timesub(timep, offset, sp, tmp) timesub(const time_t *timep, const long offset, const struct state *sp,
const time_t * const timep; struct tm *tmp)
const long offset;
register const struct state * const sp;
register struct tm * const tmp;
{ {
register const struct lsinfo * lp; register const struct lsinfo * lp;
register long days; register long days;
@ -1797,9 +1741,8 @@ register struct tm * const tmp;
#endif /* defined TM_GMTOFF */ #endif /* defined TM_GMTOFF */
} }
char * extern "C" char *
ctime(timep) ctime(const time_t *timep)
const time_t * const timep;
{ {
/* /*
** Section 4.12.3.2 of X3.159-1989 requires that ** Section 4.12.3.2 of X3.159-1989 requires that
@ -1810,10 +1753,8 @@ const time_t * const timep;
return asctime(localtime(timep)); return asctime(localtime(timep));
} }
char * extern "C" char *
ctime_r(timep, buf) ctime_r(const time_t *timep, char *buf)
const time_t * const timep;
char * buf;
{ {
struct tm tm; struct tm tm;
@ -1839,9 +1780,7 @@ char * buf;
*/ */
static int static int
increment_overflow(number, delta) increment_overflow(int *number, int delta)
int * number;
int delta;
{ {
int number0; int number0;
@ -1851,10 +1790,7 @@ int delta;
} }
static int static int
normalize_overflow(tensptr, unitsptr, base) normalize_overflow(int *tensptr, int *unitsptr, const int base)
int * const tensptr;
int * const unitsptr;
const int base;
{ {
register int tensdelta; register int tensdelta;
@ -1866,9 +1802,7 @@ const int base;
} }
static int static int
tmcomp(atmp, btmp) tmcomp(register const struct tm *atmp, register const struct tm *btmp)
register const struct tm * const atmp;
register const struct tm * const btmp;
{ {
register int result; register int result;
@ -1882,12 +1816,8 @@ register const struct tm * const btmp;
} }
static time_t static time_t
time2sub(tmp, funcp, offset, okayp, do_norm_secs) time2sub(struct tm *tmp, void (*funcp) P((const time_t*, long, struct tm*)),
struct tm * const tmp; const long offset, int *okayp, const int do_norm_secs)
void (* const funcp) P((const time_t*, long, struct tm*));
const long offset;
int * const okayp;
const int do_norm_secs;
{ {
register const struct state * sp; register const struct state * sp;
register int dir; register int dir;
@ -2034,11 +1964,8 @@ label:
} }
static time_t static time_t
time2(tmp, funcp, offset, okayp) time2(struct tm *tmp, void (*funcp) P((const time_t*, long, struct tm*)),
struct tm * const tmp; const long offset, int *okayp)
void (* const funcp) P((const time_t*, long, struct tm*));
const long offset;
int * const okayp;
{ {
time_t t; time_t t;
@ -2052,10 +1979,8 @@ int * const okayp;
} }
static time_t static time_t
time1(tmp, funcp, offset) time1(struct tm *tmp, void (*funcp) P((const time_t *, long, struct tm *)),
struct tm * const tmp; const long offset)
void (* const funcp) P((const time_t *, long, struct tm *));
const long offset;
{ {
register time_t t; register time_t t;
register const struct state * sp; register const struct state * sp;
@ -2113,9 +2038,8 @@ const long offset;
return WRONG; return WRONG;
} }
time_t extern "C" time_t
mktime(tmp) mktime(struct tm *tmp)
struct tm * const tmp;
{ {
tzset(); tzset();
return time1(tmp, localsub, 0L); return time1(tmp, localsub, 0L);
@ -2123,26 +2047,22 @@ struct tm * const tmp;
#ifdef STD_INSPIRED #ifdef STD_INSPIRED
time_t extern "C" time_t
timelocal(tmp) timelocal(struct tm *tmp)
struct tm * const tmp;
{ {
tmp->tm_isdst = -1; /* in case it wasn't initialized */ tmp->tm_isdst = -1; /* in case it wasn't initialized */
return mktime(tmp); return mktime(tmp);
} }
time_t extern "C" time_t
timegm(tmp) timegm(struct tm *tmp)
struct tm * const tmp;
{ {
tmp->tm_isdst = 0; tmp->tm_isdst = 0;
return time1(tmp, gmtsub, 0L); return time1(tmp, gmtsub, 0L);
} }
time_t extern "C" time_t
timeoff(tmp, offset) timeoff(struct tm *tmp, const long offset)
struct tm * const tmp;
const long offset;
{ {
tmp->tm_isdst = 0; tmp->tm_isdst = 0;
return time1(tmp, gmtsub, offset); return time1(tmp, gmtsub, offset);
@ -2157,9 +2077,8 @@ const long offset;
** previous versions of the CMUCS runtime library. ** previous versions of the CMUCS runtime library.
*/ */
long extern "C" long
gtime(tmp) gtime(struct tm *tmp)
struct tm * const tmp;
{ {
const time_t t = mktime(tmp); const time_t t = mktime(tmp);
@ -2185,8 +2104,7 @@ struct tm * const tmp;
*/ */
static long static long
leapcorr(timep) leapcorr(time_t *timep)
time_t * timep;
{ {
register struct state * sp; register struct state * sp;
register struct lsinfo * lp; register struct lsinfo * lp;
@ -2202,17 +2120,15 @@ time_t * timep;
return 0; return 0;
} }
time_t extern "C" time_t
time2posix(t) time2posix(time_t t)
time_t t;
{ {
tzset(); tzset();
return t - leapcorr(&t); return t - leapcorr(&t);
} }
time_t extern "C" time_t
posix2time(t) posix2time(time_t t)
time_t t;
{ {
time_t x; time_t x;
time_t y; time_t y;