[9633] | 1 | /*
|
---|
| 2 | * msvcrt.dll date/time functions
|
---|
| 3 | *
|
---|
| 4 | * Copyright 1996,1998 Marcus Meissner
|
---|
| 5 | * Copyright 1996 Jukka Iivonen
|
---|
| 6 | * Copyright 1997,2000 Uwe Bonnes
|
---|
| 7 | * Copyright 2000 Jon Griffiths
|
---|
| 8 | *
|
---|
| 9 | * This library is free software; you can redistribute it and/or
|
---|
| 10 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 11 | * License as published by the Free Software Foundation; either
|
---|
| 12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * This library is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 17 | * Lesser General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 20 | * License along with this library; if not, write to the Free Software
|
---|
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 22 | */
|
---|
| 23 | #ifdef __WIN32OS2__
|
---|
| 24 | #include <emxheader.h>
|
---|
[10005] | 25 | #include <unistd.h>
|
---|
| 26 | #include <time.h>
|
---|
[21916] | 27 | #include <sys/times.h>
|
---|
[9633] | 28 | #else
|
---|
| 29 | #include "config.h"
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #include <time.h>
|
---|
| 33 | #ifdef HAVE_SYS_TIMES_H
|
---|
| 34 | # include <sys/times.h>
|
---|
| 35 | #endif
|
---|
| 36 |
|
---|
| 37 | #include "msvcrt.h"
|
---|
| 38 | #include "msvcrt/sys/timeb.h"
|
---|
| 39 | #include "msvcrt/time.h"
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | #include "wine/debug.h"
|
---|
| 43 |
|
---|
| 44 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | /* INTERNAL: Return formatted current time/date */
|
---|
| 48 | char* msvcrt_get_current_time(char* out, const char* format)
|
---|
| 49 | {
|
---|
| 50 | static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
|
---|
| 51 | time_t t;
|
---|
| 52 | struct tm *_tm = NULL;
|
---|
| 53 | char *retval = NULL;
|
---|
| 54 |
|
---|
| 55 | if (time(&t) != bad_time && (_tm = localtime(&t)) &&
|
---|
| 56 | strftime(out,9,format,_tm) == 8)
|
---|
| 57 | retval = out;
|
---|
| 58 | return retval;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /**********************************************************************
|
---|
| 62 | * mktime (MSVCRT.@)
|
---|
| 63 | */
|
---|
| 64 | MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
|
---|
| 65 | {
|
---|
| 66 | MSVCRT_time_t res;
|
---|
[10005] | 67 | dprintf(("MSVCRT: mktime"));
|
---|
[9633] | 68 | struct tm tm;
|
---|
| 69 |
|
---|
| 70 | tm.tm_sec = t->tm_sec;
|
---|
| 71 | tm.tm_min = t->tm_min;
|
---|
| 72 | tm.tm_hour = t->tm_hour;
|
---|
| 73 | tm.tm_mday = t->tm_mday;
|
---|
| 74 | tm.tm_mon = t->tm_mon;
|
---|
| 75 | tm.tm_year = t->tm_year;
|
---|
| 76 | tm.tm_isdst = t->tm_isdst;
|
---|
| 77 | res = mktime(&tm);
|
---|
| 78 | if (res != -1)
|
---|
| 79 | {
|
---|
| 80 | t->tm_sec = tm.tm_sec;
|
---|
| 81 | t->tm_min = tm.tm_min;
|
---|
| 82 | t->tm_hour = tm.tm_hour;
|
---|
| 83 | t->tm_mday = tm.tm_mday;
|
---|
| 84 | t->tm_mon = tm.tm_mon;
|
---|
| 85 | t->tm_year = tm.tm_year;
|
---|
| 86 | t->tm_isdst = tm.tm_isdst;
|
---|
| 87 | }
|
---|
| 88 | return res;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /**********************************************************************
|
---|
| 92 | * _strdate (MSVCRT.@)
|
---|
| 93 | */
|
---|
[10005] | 94 | char* MSVCRT__strdate(char* date)
|
---|
[9633] | 95 | {
|
---|
[10005] | 96 | dprintf(("MSVCRT: _strdate"));
|
---|
[9633] | 97 | return msvcrt_get_current_time(date,"%m/%d/%y");
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /*********************************************************************
|
---|
| 101 | * _strtime (MSVCRT.@)
|
---|
| 102 | */
|
---|
[10005] | 103 | char* MSVCRT__strtime(char* date)
|
---|
[9633] | 104 | {
|
---|
[10005] | 105 | dprintf(("MSVCRT: _strtime"));
|
---|
[9633] | 106 | return msvcrt_get_current_time(date,"%H:%M:%S");
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[21395] | 109 | clock_t emx__times(struct tms *) __asm__("emx__times");
|
---|
| 110 |
|
---|
[9633] | 111 | /*********************************************************************
|
---|
| 112 | * clock (MSVCRT.@)
|
---|
| 113 | */
|
---|
| 114 | MSVCRT_clock_t MSVCRT_clock(void)
|
---|
| 115 | {
|
---|
| 116 | struct tms alltimes;
|
---|
| 117 | clock_t res;
|
---|
| 118 |
|
---|
[10005] | 119 | dprintf(("MSVCRT: clock"));
|
---|
| 120 |
|
---|
| 121 | emx__times(&alltimes);
|
---|
[9633] | 122 | res = alltimes.tms_utime + alltimes.tms_stime +
|
---|
| 123 | alltimes.tms_cutime + alltimes.tms_cstime;
|
---|
| 124 | /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
|
---|
| 125 | * 10 holds only for Windows/Linux_i86)
|
---|
| 126 | */
|
---|
| 127 | return 10*res;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /*********************************************************************
|
---|
| 131 | * difftime (MSVCRT.@)
|
---|
| 132 | */
|
---|
| 133 | double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
|
---|
| 134 | {
|
---|
[10005] | 135 | dprintf(("MSVCRT: difftime"));
|
---|
[9633] | 136 | return (double)(time1 - time2);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /*********************************************************************
|
---|
| 140 | * time (MSVCRT.@)
|
---|
| 141 | */
|
---|
| 142 | MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
|
---|
| 143 | {
|
---|
| 144 | MSVCRT_time_t curtime = time(NULL);
|
---|
[10005] | 145 | dprintf(("MSVCRT: time"));
|
---|
[9633] | 146 | return buf ? *buf = curtime : curtime;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /*********************************************************************
|
---|
| 150 | * _ftime (MSVCRT.@)
|
---|
| 151 | */
|
---|
| 152 | #ifdef __WIN32OS2__
|
---|
[10005] | 153 | void MSVCRT__ftime(struct _timeb *buf)
|
---|
[9633] | 154 | #else
|
---|
| 155 | void _ftime(struct _timeb *buf)
|
---|
| 156 | #endif
|
---|
| 157 | {
|
---|
[10005] | 158 | dprintf(("MSVCRT: _ftime %p",buf));
|
---|
[9633] | 159 | buf->time = MSVCRT_time(NULL);
|
---|
| 160 | buf->millitm = 0; /* FIXME */
|
---|
| 161 | buf->timezone = 0;
|
---|
| 162 | buf->dstflag = 0;
|
---|
| 163 | }
|
---|
[10005] | 164 |
|
---|
| 165 | /*********************************************************************
|
---|
| 166 | * _daylight (MSVCRT.@)
|
---|
| 167 | */
|
---|
| 168 | int MSVCRT___daylight = 1; /* FIXME: assume daylight */
|
---|
| 169 |
|
---|
| 170 | /*********************************************************************
|
---|
| 171 | * __p_daylight (MSVCRT.@)
|
---|
| 172 | */
|
---|
| 173 | void *MSVCRT___p__daylight(void)
|
---|
| 174 | {
|
---|
| 175 | return &MSVCRT___daylight;
|
---|
| 176 | }
|
---|