| 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>
|
|---|
| 25 | #include <sys/times.h>
|
|---|
| 26 | #else
|
|---|
| 27 | #include "config.h"
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #include <time.h>
|
|---|
| 31 | #ifdef HAVE_SYS_TIMES_H
|
|---|
| 32 | # include <sys/times.h>
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | #include "msvcrt.h"
|
|---|
| 36 | #include "msvcrt/sys/timeb.h"
|
|---|
| 37 | #include "msvcrt/time.h"
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | #include "wine/debug.h"
|
|---|
| 41 |
|
|---|
| 42 | WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | /* INTERNAL: Return formatted current time/date */
|
|---|
| 46 | char* msvcrt_get_current_time(char* out, const char* format)
|
|---|
| 47 | {
|
|---|
| 48 | static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
|
|---|
| 49 | time_t t;
|
|---|
| 50 | struct tm *_tm = NULL;
|
|---|
| 51 | char *retval = NULL;
|
|---|
| 52 |
|
|---|
| 53 | if (time(&t) != bad_time && (_tm = localtime(&t)) &&
|
|---|
| 54 | strftime(out,9,format,_tm) == 8)
|
|---|
| 55 | retval = out;
|
|---|
| 56 | return retval;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /**********************************************************************
|
|---|
| 60 | * mktime (MSVCRT.@)
|
|---|
| 61 | */
|
|---|
| 62 | MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
|
|---|
| 63 | {
|
|---|
| 64 | MSVCRT_time_t res;
|
|---|
| 65 | struct tm tm;
|
|---|
| 66 |
|
|---|
| 67 | tm.tm_sec = t->tm_sec;
|
|---|
| 68 | tm.tm_min = t->tm_min;
|
|---|
| 69 | tm.tm_hour = t->tm_hour;
|
|---|
| 70 | tm.tm_mday = t->tm_mday;
|
|---|
| 71 | tm.tm_mon = t->tm_mon;
|
|---|
| 72 | tm.tm_year = t->tm_year;
|
|---|
| 73 | tm.tm_isdst = t->tm_isdst;
|
|---|
| 74 | res = mktime(&tm);
|
|---|
| 75 | if (res != -1)
|
|---|
| 76 | {
|
|---|
| 77 | t->tm_sec = tm.tm_sec;
|
|---|
| 78 | t->tm_min = tm.tm_min;
|
|---|
| 79 | t->tm_hour = tm.tm_hour;
|
|---|
| 80 | t->tm_mday = tm.tm_mday;
|
|---|
| 81 | t->tm_mon = tm.tm_mon;
|
|---|
| 82 | t->tm_year = tm.tm_year;
|
|---|
| 83 | t->tm_isdst = tm.tm_isdst;
|
|---|
| 84 | }
|
|---|
| 85 | return res;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /**********************************************************************
|
|---|
| 89 | * _strdate (MSVCRT.@)
|
|---|
| 90 | */
|
|---|
| 91 | char* _strdate(char* date)
|
|---|
| 92 | {
|
|---|
| 93 | return msvcrt_get_current_time(date,"%m/%d/%y");
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /*********************************************************************
|
|---|
| 97 | * _strtime (MSVCRT.@)
|
|---|
| 98 | */
|
|---|
| 99 | char* _strtime(char* date)
|
|---|
| 100 | {
|
|---|
| 101 | return msvcrt_get_current_time(date,"%H:%M:%S");
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /*********************************************************************
|
|---|
| 105 | * clock (MSVCRT.@)
|
|---|
| 106 | */
|
|---|
| 107 | MSVCRT_clock_t MSVCRT_clock(void)
|
|---|
| 108 | {
|
|---|
| 109 | struct tms alltimes;
|
|---|
| 110 | clock_t res;
|
|---|
| 111 |
|
|---|
| 112 | times(&alltimes);
|
|---|
| 113 | res = alltimes.tms_utime + alltimes.tms_stime +
|
|---|
| 114 | alltimes.tms_cutime + alltimes.tms_cstime;
|
|---|
| 115 | /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
|
|---|
| 116 | * 10 holds only for Windows/Linux_i86)
|
|---|
| 117 | */
|
|---|
| 118 | return 10*res;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /*********************************************************************
|
|---|
| 122 | * difftime (MSVCRT.@)
|
|---|
| 123 | */
|
|---|
| 124 | double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
|
|---|
| 125 | {
|
|---|
| 126 | return (double)(time1 - time2);
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /*********************************************************************
|
|---|
| 130 | * time (MSVCRT.@)
|
|---|
| 131 | */
|
|---|
| 132 | MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
|
|---|
| 133 | {
|
|---|
| 134 | MSVCRT_time_t curtime = time(NULL);
|
|---|
| 135 | return buf ? *buf = curtime : curtime;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /*********************************************************************
|
|---|
| 139 | * _ftime (MSVCRT.@)
|
|---|
| 140 | */
|
|---|
| 141 | #ifdef __WIN32OS2__
|
|---|
| 142 | void MSVCRT_ftime(struct _timeb *buf)
|
|---|
| 143 | #else
|
|---|
| 144 | void _ftime(struct _timeb *buf)
|
|---|
| 145 | #endif
|
|---|
| 146 | {
|
|---|
| 147 | buf->time = MSVCRT_time(NULL);
|
|---|
| 148 | buf->millitm = 0; /* FIXME */
|
|---|
| 149 | buf->timezone = 0;
|
|---|
| 150 | buf->dstflag = 0;
|
|---|
| 151 | }
|
|---|