Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 kernel functions |
| 3 | * |
| 4 | * Copyright 1995 Martin von Loewis and Cameron Heide |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | 136fae5 | 2002-03-11 05:08:38 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 23 | #include <string.h> |
| 24 | #include <unistd.h> |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 26 | #include <sys/time.h> |
| 27 | #include <sys/times.h> |
| 28 | #include "file.h" |
Patrik Stridvall | bf8943c | 2000-10-02 03:39:34 +0000 | [diff] [blame] | 29 | #include "ntddk.h" |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 30 | #include "winerror.h" |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 31 | #include "winnls.h" |
James Hatheway | a9f8997 | 2001-04-09 18:45:49 +0000 | [diff] [blame] | 32 | #include "wine/unicode.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 33 | #include "wine/debug.h" |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 35 | WINE_DEFAULT_DEBUG_CHANNEL(win32); |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 36 | |
| 37 | /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */ |
| 38 | #define SETTIME_MAX_ADJUST 120 |
| 39 | |
James Hatheway | a9f8997 | 2001-04-09 18:45:49 +0000 | [diff] [blame] | 40 | |
| 41 | /* This structure is used to store strings that represent all of the time zones |
| 42 | in the world. (This is used to help GetTimeZoneInformation) |
| 43 | */ |
| 44 | struct tagTZ_INFO |
| 45 | { |
| 46 | const char *psTZFromUnix; |
| 47 | WCHAR psTZWindows[32]; |
| 48 | int bias; |
| 49 | int dst; |
| 50 | }; |
| 51 | |
| 52 | static const struct tagTZ_INFO TZ_INFO[] = |
| 53 | { |
| 54 | {"MHT", |
| 55 | {'D','a','t','e','l','i','n','e',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 56 | -720, 0}, |
| 57 | {"SST", |
| 58 | {'S','a','m','o','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 59 | 660, 0}, |
| 60 | {"HST", |
| 61 | {'H','a','w','a','i','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 62 | 600, 0}, |
| 63 | {"AKDT", |
| 64 | {'A','l','a','s','k','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 65 | 480, 1}, |
| 66 | {"PDT", |
| 67 | {'P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 68 | 420, 1}, |
| 69 | {"MST", |
| 70 | {'U','S',' ','M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 71 | 420, 0}, |
| 72 | {"MDT", |
| 73 | {'M','o','u','n','t','a','i','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 74 | 360, 1}, |
| 75 | {"CST", |
| 76 | {'C','e','n','t','r','a','l',' ','A','m','e','r','i','c','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 77 | 360, 0}, |
| 78 | {"CDT", |
| 79 | {'C','e','n','t','r','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 80 | 300, 1}, |
| 81 | {"COT", |
| 82 | {'S','A',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 83 | 300, 0}, |
| 84 | {"EDT", |
| 85 | {'E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 86 | 240, 1}, |
| 87 | {"EST", |
| 88 | {'U','S',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 89 | 300, 0}, |
| 90 | {"ADT", |
| 91 | {'A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 92 | 180, 1}, |
| 93 | {"VET", |
| 94 | {'S','A',' ','W','e','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 95 | 240, 0}, |
| 96 | {"CLT", |
| 97 | {'P','a','c','i','f','i','c',' ','S','A',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 98 | 240, 0}, |
| 99 | {"NDT", |
| 100 | {'N','e','w','f','o','u','n','d','l','a','n','d',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 101 | 150, 1}, |
| 102 | {"BRT", |
| 103 | {'E','.',' ','S','o','u','t','h',' ','A','m','e','r','i','c','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 104 | 180, 0}, |
| 105 | {"ART", |
| 106 | {'S','A',' ','E','a','s','t','e','r','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 107 | 180, 0}, |
| 108 | {"WGST", |
| 109 | {'G','r','e','e','n','l','a','n','d',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 110 | 120, 1}, |
| 111 | {"GST", |
| 112 | {'M','i','d','-','A','t','l','a','n','t','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 113 | 120, 0}, |
| 114 | {"AZOST", |
| 115 | {'A','z','o','r','e','s',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 116 | 0, 1}, |
| 117 | {"CVT", |
| 118 | {'C','a','p','e',' ','V','e','r','d','e',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 119 | 60, 0}, |
| 120 | {"WET", |
| 121 | {'G','r','e','e','n','w','i','c','h',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 122 | 0, 0}, |
| 123 | {"BST", |
| 124 | {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 125 | -60, 1}, |
| 126 | {"GMT", |
| 127 | {'G','M','T',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 128 | 0, 0}, |
| 129 | {"CEST", |
| 130 | {'C','e','n','t','r','a','l',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 131 | -120, 1}, |
| 132 | {"WAT", |
| 133 | {'W','.',' ','C','e','n','t','r','a','l',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 134 | -60, 0}, |
| 135 | {"EEST", |
| 136 | {'E','.',' ','E','u','r','o','p','e',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 137 | -180, 1}, |
| 138 | {"EET", |
| 139 | {'E','g','y','p','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 140 | -120, 0}, |
| 141 | {"CAT", |
| 142 | {'S','o','u','t','h',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 143 | -120, 0}, |
| 144 | {"IST", |
| 145 | {'I','s','r','a','e','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 146 | -120, 0}, |
| 147 | {"ADT", |
| 148 | {'A','r','a','b','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 149 | -240, 1}, |
| 150 | {"AST", |
| 151 | {'A','r','a','b',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 152 | -180, 0}, |
| 153 | {"MSD", |
| 154 | {'R','u','s','s','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 155 | -240, 1}, |
| 156 | {"EAT", |
| 157 | {'E','.',' ','A','f','r','i','c','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 158 | -180, 0}, |
| 159 | {"IRST", |
| 160 | {'I','r','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 161 | -270, 1}, |
| 162 | {"GST", |
| 163 | {'A','r','a','b','i','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 164 | -240, 0}, |
| 165 | {"AZST", |
| 166 | {'C','a','u','c','a','s','u','s',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 167 | -300, 1}, |
| 168 | {"AFT", |
| 169 | {'A','f','g','h','a','n','i','s','t','a','n',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 170 | -270, 0}, |
| 171 | {"YEKST", |
| 172 | {'E','k','a','t','e','r','i','n','b','u','r','g',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 173 | -360, 1}, |
| 174 | {"PKT", |
| 175 | {'W','e','s','t',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 176 | -300, 0}, |
| 177 | {"IST", |
| 178 | {'I','n','d','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 179 | -330, 0}, |
| 180 | {"NPT", |
| 181 | {'N','e','p','a','l',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 182 | -345, 0}, |
| 183 | {"ALMST", |
| 184 | {'N','.',' ','C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 185 | -420, 1}, |
| 186 | {"BDT", |
| 187 | {'C','e','n','t','r','a','l',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 188 | -360, 0}, |
| 189 | {"LKT", |
| 190 | {'S','r','i',' ','L','a','n','k','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 191 | -360, 0}, |
| 192 | {"MMT", |
| 193 | {'M','y','a','n','m','a','r',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 194 | -390, 0}, |
| 195 | {"ICT", |
| 196 | {'S','E',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 197 | -420, 0}, |
| 198 | {"KRAST", |
| 199 | {'N','o','r','t','h',' ','A','s','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 200 | -480, 1}, |
| 201 | {"CST", |
| 202 | {'C','h','i','n','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 203 | -480, 0}, |
| 204 | {"IRKST", |
| 205 | {'N','o','r','t','h',' ','A','s','i','a',' ','E','a','s','t',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 206 | -540, 1}, |
| 207 | {"SGT", |
| 208 | {'M','a','l','a','y',' ','P','e','n','i','n','s','u','l','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 209 | -480, 0}, |
| 210 | {"WST", |
| 211 | {'W','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 212 | -480, 0}, |
| 213 | {"JST", |
| 214 | {'T','o','k','y','o',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 215 | -540, 0}, |
| 216 | {"KST", |
| 217 | {'K','o','r','e','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 218 | -540, 0}, |
| 219 | {"YAKST", |
| 220 | {'Y','a','k','u','t','s','k',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 221 | -600, 1}, |
| 222 | {"CST", |
| 223 | {'C','e','n','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 224 | -570, 0}, |
| 225 | {"EST", |
| 226 | {'E','.',' ','A','u','s','t','r','a','l','i','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 227 | -600, 0}, |
| 228 | {"GST", |
| 229 | {'W','e','s','t',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 230 | -600, 0}, |
| 231 | {"VLAST", |
| 232 | {'V','l','a','d','i','v','o','s','t','o','k',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 233 | -660, 1}, |
| 234 | {"MAGST", |
| 235 | {'C','e','n','t','r','a','l',' ','P','a','c','i','f','i','c',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 236 | -720, 1}, |
| 237 | {"NZST", |
| 238 | {'N','e','w',' ','Z','e','a','l','a','n','d',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 239 | -720, 0}, |
| 240 | {"FJT", |
| 241 | {'F','i','j','i',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 242 | -720, 0}, |
| 243 | {"TOT", |
| 244 | {'T','o','n','g','a',' ','S','t','a','n','d','a','r','d',' ','T','i','m','e','\0'}, |
| 245 | -780, 0} |
| 246 | }; |
| 247 | |
| 248 | /* TIME_GetTZAsStr: helper function that returns the given timezone as a string. |
| 249 | This could be done with a hash table instead of merely iterating through |
| 250 | a table, however with the small amount of entries (60 or so) I didn't think |
| 251 | it was worth it. */ |
| 252 | static const WCHAR* TIME_GetTZAsStr (time_t utc, int bias, int dst) |
| 253 | { |
| 254 | char psTZName[7]; |
| 255 | struct tm *ptm = localtime(&utc); |
| 256 | int i; |
| 257 | |
| 258 | if (!strftime (psTZName, 7, "%Z", ptm)) |
| 259 | return (NULL); |
| 260 | |
| 261 | for (i=0; i<(sizeof(TZ_INFO) / sizeof(struct tagTZ_INFO)); i++) |
| 262 | { |
| 263 | if ( strcmp(TZ_INFO[i].psTZFromUnix, psTZName) == 0 && |
| 264 | TZ_INFO[i].bias == bias && |
| 265 | TZ_INFO[i].dst == dst |
| 266 | ) |
| 267 | return TZ_INFO[i].psTZWindows; |
| 268 | } |
| 269 | |
| 270 | return (NULL); |
| 271 | } |
| 272 | |
| 273 | |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 274 | /* TIME_GetBias: helper function calculates delta local time from UTC */ |
| 275 | static int TIME_GetBias( time_t utc, int *pdaylight) |
| 276 | { |
| 277 | struct tm *ptm = localtime(&utc); |
| 278 | *pdaylight = ptm->tm_isdst; /* daylight for local timezone */ |
| 279 | ptm = gmtime(&utc); |
| 280 | ptm->tm_isdst = *pdaylight; /* use local daylight, not that of Greenwich */ |
| 281 | return (int)(utc-mktime(ptm)); |
| 282 | } |
| 283 | |
| 284 | |
| 285 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 286 | * SetLocalTime (KERNEL32.@) |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 287 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 288 | * Sets the local time using current time zone and daylight |
| 289 | * savings settings. |
| 290 | * |
| 291 | * RETURNS |
| 292 | * |
| 293 | * True if the time was set, false if the time was invalid or the |
| 294 | * necessary permissions were not held. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 295 | */ |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 296 | BOOL WINAPI SetLocalTime( |
| 297 | const SYSTEMTIME *systime) /* [in] The desired local time. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 298 | { |
| 299 | struct timeval tv; |
| 300 | struct tm t; |
| 301 | time_t sec; |
| 302 | time_t oldsec=time(NULL); |
| 303 | int err; |
| 304 | |
| 305 | /* get the number of seconds */ |
| 306 | t.tm_sec = systime->wSecond; |
| 307 | t.tm_min = systime->wMinute; |
| 308 | t.tm_hour = systime->wHour; |
| 309 | t.tm_mday = systime->wDay; |
| 310 | t.tm_mon = systime->wMonth - 1; |
| 311 | t.tm_year = systime->wYear - 1900; |
| 312 | t.tm_isdst = -1; |
| 313 | sec = mktime (&t); |
| 314 | |
| 315 | /* set the new time */ |
| 316 | tv.tv_sec = sec; |
| 317 | tv.tv_usec = systime->wMilliseconds * 1000; |
| 318 | |
| 319 | /* error and sanity check*/ |
| 320 | if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ |
| 321 | err = 1; |
| 322 | SetLastError(ERROR_INVALID_PARAMETER); |
| 323 | } else { |
Patrik Stridvall | 136fae5 | 2002-03-11 05:08:38 +0000 | [diff] [blame] | 324 | #ifdef HAVE_SETTIMEOFDAY |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 325 | err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ |
| 326 | if(err == 0) |
| 327 | return TRUE; |
| 328 | SetLastError(ERROR_PRIVILEGE_NOT_HELD); |
Patrik Stridvall | 136fae5 | 2002-03-11 05:08:38 +0000 | [diff] [blame] | 329 | #else |
| 330 | err = 1; |
| 331 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 332 | #endif |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 333 | } |
| 334 | ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", |
| 335 | systime->wYear, systime->wMonth, systime->wDay, systime->wHour, |
| 336 | systime->wMinute, systime->wSecond, |
| 337 | sec-oldsec, err == -1 ? "No Permission" : |
| 338 | sec==(time_t)-1 ? "" : "is too large." ); |
| 339 | return FALSE; |
| 340 | } |
| 341 | |
| 342 | |
| 343 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 344 | * GetSystemTimeAdjustment (KERNEL32.@) |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 345 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 346 | * Indicates the period between clock interrupt and the amount the clock |
| 347 | * is adjusted each interrupt so as to keep it insync with an external source. |
| 348 | * |
| 349 | * RETURNS |
| 350 | * |
| 351 | * Always returns true. |
| 352 | * |
| 353 | * BUGS |
| 354 | * |
| 355 | * Only the special case of disabled time adjustments is supported. |
| 356 | * (also the signature is wrong it should have a return type of BOOL) |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 357 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 358 | DWORD WINAPI GetSystemTimeAdjustment( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 359 | LPDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */ |
| 360 | LPDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */ |
| 361 | LPBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 362 | { |
| 363 | *lpTimeAdjustment = 0; |
| 364 | *lpTimeIncrement = 0; |
| 365 | *lpTimeAdjustmentDisabled = TRUE; |
| 366 | return TRUE; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 371 | * SetSystemTime (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 372 | * |
| 373 | * Sets the system time (utc). |
| 374 | * |
| 375 | * RETURNS |
| 376 | * |
| 377 | * True if the time was set, false if the time was invalid or the |
| 378 | * necessary permissions were not held. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 379 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 380 | BOOL WINAPI SetSystemTime( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 381 | const SYSTEMTIME *systime) /* [in] The desired system time. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 382 | { |
| 383 | struct timeval tv; |
| 384 | struct timezone tz; |
| 385 | struct tm t; |
| 386 | time_t sec, oldsec; |
| 387 | int dst, bias; |
| 388 | int err; |
| 389 | |
| 390 | /* call gettimeofday to get the current timezone */ |
| 391 | gettimeofday(&tv, &tz); |
| 392 | oldsec=tv.tv_sec; |
| 393 | /* get delta local time from utc */ |
| 394 | bias=TIME_GetBias(oldsec,&dst); |
| 395 | |
| 396 | /* get the number of seconds */ |
| 397 | t.tm_sec = systime->wSecond; |
| 398 | t.tm_min = systime->wMinute; |
| 399 | t.tm_hour = systime->wHour; |
| 400 | t.tm_mday = systime->wDay; |
| 401 | t.tm_mon = systime->wMonth - 1; |
| 402 | t.tm_year = systime->wYear - 1900; |
| 403 | t.tm_isdst = dst; |
| 404 | sec = mktime (&t); |
| 405 | /* correct for timezone and daylight */ |
| 406 | sec += bias; |
| 407 | |
| 408 | /* set the new time */ |
| 409 | tv.tv_sec = sec; |
| 410 | tv.tv_usec = systime->wMilliseconds * 1000; |
| 411 | |
| 412 | /* error and sanity check*/ |
| 413 | if( sec == (time_t)-1 || abs((int)(sec-oldsec)) > SETTIME_MAX_ADJUST ){ |
| 414 | err = 1; |
| 415 | SetLastError(ERROR_INVALID_PARAMETER); |
| 416 | } else { |
Patrik Stridvall | 136fae5 | 2002-03-11 05:08:38 +0000 | [diff] [blame] | 417 | #ifdef HAVE_SETTIMEOFDAY |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 418 | err=settimeofday(&tv, NULL); /* 0 is OK, -1 is error */ |
| 419 | if(err == 0) |
| 420 | return TRUE; |
| 421 | SetLastError(ERROR_PRIVILEGE_NOT_HELD); |
Patrik Stridvall | 136fae5 | 2002-03-11 05:08:38 +0000 | [diff] [blame] | 422 | #else |
| 423 | err = 1; |
| 424 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 425 | #endif |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 426 | } |
| 427 | ERR("Cannot set time to %d/%d/%d %d:%d:%d Time adjustment %ld %s\n", |
| 428 | systime->wYear, systime->wMonth, systime->wDay, systime->wHour, |
| 429 | systime->wMinute, systime->wSecond, |
| 430 | sec-oldsec, err == -1 ? "No Permission" : |
| 431 | sec==(time_t)-1 ? "" : "is too large." ); |
| 432 | return FALSE; |
| 433 | } |
| 434 | |
| 435 | |
| 436 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 437 | * GetTimeZoneInformation (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 438 | * |
| 439 | * Fills in the a time zone information structure with values based on |
| 440 | * the current local time. |
| 441 | * |
| 442 | * RETURNS |
| 443 | * |
| 444 | * The daylight savings time standard or TIME_ZONE_ID_INVALID if the call failed. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 445 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 446 | DWORD WINAPI GetTimeZoneInformation( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 447 | LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 448 | { |
| 449 | time_t gmt; |
| 450 | int bias, daylight; |
James Hatheway | a9f8997 | 2001-04-09 18:45:49 +0000 | [diff] [blame] | 451 | const WCHAR *psTZ; |
| 452 | |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 453 | |
| 454 | memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION)); |
| 455 | |
| 456 | gmt = time(NULL); |
| 457 | bias=TIME_GetBias(gmt,&daylight); |
| 458 | |
| 459 | tzinfo->Bias = -bias / 60; |
| 460 | tzinfo->StandardBias = 0; |
| 461 | tzinfo->DaylightBias = -60; |
James Hatheway | a9f8997 | 2001-04-09 18:45:49 +0000 | [diff] [blame] | 462 | psTZ = TIME_GetTZAsStr (gmt, (-bias/60), daylight); |
| 463 | if (psTZ) strcpyW( tzinfo->StandardName, psTZ ); |
Rein Klazes | 8fa528a | 2000-10-31 01:01:12 +0000 | [diff] [blame] | 464 | return TIME_ZONE_ID_STANDARD; |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
| 468 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 469 | * SetTimeZoneInformation (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 470 | * |
| 471 | * Set the local time zone with values based on the time zone structure. |
| 472 | * |
| 473 | * RETURNS |
| 474 | * |
| 475 | * True on successful setting of the time zone. |
| 476 | * |
| 477 | * BUGS |
| 478 | * |
| 479 | * Use the obsolete unix timezone structure and tz_dsttime member. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 480 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 481 | BOOL WINAPI SetTimeZoneInformation( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 482 | const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 483 | { |
| 484 | struct timezone tz; |
| 485 | |
| 486 | tz.tz_minuteswest = tzinfo->Bias; |
| 487 | #ifdef DST_NONE |
| 488 | tz.tz_dsttime = DST_NONE; |
| 489 | #else |
| 490 | tz.tz_dsttime = 0; |
| 491 | #endif |
| 492 | return !settimeofday(NULL, &tz); |
| 493 | } |
| 494 | |
| 495 | |
| 496 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 497 | * SystemTimeToTzSpecificLocalTime (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 498 | * |
| 499 | * Converts the system time (utc) to the local time in the specified time zone. |
| 500 | * |
| 501 | * RETURNS |
| 502 | * |
| 503 | * Returns true when the local time was calculated. |
| 504 | * |
| 505 | * BUGS |
| 506 | * |
| 507 | * Does not handle daylight savings time adjustments correctly. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 508 | */ |
| 509 | BOOL WINAPI SystemTimeToTzSpecificLocalTime( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 510 | LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */ |
| 511 | LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */ |
| 512 | LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 513 | { |
| 514 | FIXME(":stub\n"); |
| 515 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 516 | return FALSE; |
| 517 | } |
| 518 | |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 519 | |
| 520 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 521 | * GetSystemTimeAsFileTime (KERNEL32.@) |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 522 | * |
| 523 | * Fills in a file time structure with the current time in UTC format. |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 524 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 525 | VOID WINAPI GetSystemTimeAsFileTime( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 526 | LPFILETIME time) /* [out] The file time struct to be filled with the system time. */ |
Alexandre Julliard | d76f9f9 | 2000-10-01 01:40:42 +0000 | [diff] [blame] | 527 | { |
| 528 | NtQuerySystemTime( (LARGE_INTEGER *)time ); |
| 529 | } |
| 530 | |
| 531 | |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 532 | /********************************************************************* |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 533 | * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998) |
| 534 | * |
| 535 | * Used by GetProcessTimes to convert clock_t into FILETIME. |
| 536 | * |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 537 | * Differences to UnixTimeToFileTime: |
| 538 | * 1) Divided by CLK_TCK |
| 539 | * 2) Time is relative. There is no 'starting date', so there is |
| 540 | * no need in offset correction, like in UnixTimeToFileTime |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 541 | */ |
| 542 | static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime) |
| 543 | { |
Alexandre Julliard | 27952ef | 2000-10-13 20:26:03 +0000 | [diff] [blame] | 544 | LONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 ); |
| 545 | ((LARGE_INTEGER *)filetime)->QuadPart = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL ); |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /********************************************************************* |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 549 | * GetProcessTimes (KERNEL32.@) |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 550 | * |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 551 | * Returns the user and kernel execution times of a process, |
| 552 | * along with the creation and exit times if known. |
| 553 | * |
| 554 | * olorin@fandra.org: |
| 555 | * Would be nice to subtract the cpu time, used by Wine at startup. |
| 556 | * Also, there is a need to separate times used by different applications. |
| 557 | * |
| 558 | * RETURNS |
| 559 | * |
| 560 | * Always returns true. |
| 561 | * |
| 562 | * BUGS |
| 563 | * |
| 564 | * lpCreationTime, lpExitTime are NOT INITIALIZED. |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 565 | */ |
Andrew Johnston | 03131aa | 2000-12-19 23:33:03 +0000 | [diff] [blame] | 566 | BOOL WINAPI GetProcessTimes( |
Patrik Stridvall | bca4a8d | 2001-02-12 03:49:57 +0000 | [diff] [blame] | 567 | HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */ |
| 568 | LPFILETIME lpCreationTime, /* [out] The creation time of the process. */ |
| 569 | LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */ |
| 570 | LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */ |
| 571 | LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */ |
Alexandre Julliard | afb49ea | 2000-09-29 20:48:04 +0000 | [diff] [blame] | 572 | { |
| 573 | struct tms tms; |
| 574 | |
| 575 | times(&tms); |
| 576 | TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime); |
| 577 | TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime); |
| 578 | return TRUE; |
| 579 | } |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 580 | |
| 581 | /********************************************************************* |
Patrik Stridvall | c01c193 | 2001-06-19 03:36:23 +0000 | [diff] [blame] | 582 | * GetCalendarInfoA (KERNEL32.@) |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 583 | * |
| 584 | */ |
| 585 | int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, |
| 586 | LPSTR lpCalData, int cchData, LPDWORD lpValue) |
| 587 | { |
| 588 | FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): stub\n", |
| 589 | Locale, Calendar, CalType, lpCalData, cchData, lpValue); |
Marcus Meissner | 8934496 | 2001-09-10 23:08:39 +0000 | [diff] [blame] | 590 | /* dont have the #define values for those */ |
| 591 | |
| 592 | FIXME("\t"); |
| 593 | /* |
| 594 | if (CalType & CAL_NOUSEROVERRIDE) |
| 595 | MESSAGE("CAL_NOUSEROVERRIDE|"); |
| 596 | if (CalType & CAL_RETURN_NUMBER) |
| 597 | MESSAGE("CAL_RETURN_NUMBER|"); |
| 598 | if (CalType & CAL_USE_CP_ACP) |
| 599 | MESSAGE("CAL_USE_CP_ACP|"); |
| 600 | */ |
| 601 | |
| 602 | /*switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {*/ |
| 603 | switch (CalType & 0xffff) { |
| 604 | #define X(x) case x: MESSAGE(#x"\n");break; |
| 605 | X(CAL_ICALINTVALUE) |
| 606 | X(CAL_SCALNAME) |
| 607 | X(CAL_IYEAROFFSETRANGE) |
| 608 | X(CAL_SERASTRING) |
| 609 | X(CAL_SSHORTDATE) |
| 610 | X(CAL_SLONGDATE) |
| 611 | X(CAL_SDAYNAME1) |
| 612 | X(CAL_SDAYNAME2) |
| 613 | X(CAL_SDAYNAME3) |
| 614 | X(CAL_SDAYNAME4) |
| 615 | X(CAL_SDAYNAME5) |
| 616 | X(CAL_SDAYNAME6) |
| 617 | X(CAL_SDAYNAME7) |
| 618 | X(CAL_SABBREVDAYNAME1) |
| 619 | X(CAL_SABBREVDAYNAME2) |
| 620 | X(CAL_SABBREVDAYNAME3) |
| 621 | X(CAL_SABBREVDAYNAME4) |
| 622 | X(CAL_SABBREVDAYNAME5) |
| 623 | X(CAL_SABBREVDAYNAME6) |
| 624 | X(CAL_SABBREVDAYNAME7) |
| 625 | X(CAL_SMONTHNAME1) |
| 626 | X(CAL_SMONTHNAME2) |
| 627 | X(CAL_SMONTHNAME3) |
| 628 | X(CAL_SMONTHNAME4) |
| 629 | X(CAL_SMONTHNAME5) |
| 630 | X(CAL_SMONTHNAME6) |
| 631 | X(CAL_SMONTHNAME7) |
| 632 | X(CAL_SMONTHNAME8) |
| 633 | X(CAL_SMONTHNAME9) |
| 634 | X(CAL_SMONTHNAME10) |
| 635 | X(CAL_SMONTHNAME11) |
| 636 | X(CAL_SMONTHNAME12) |
| 637 | X(CAL_SMONTHNAME13) |
| 638 | X(CAL_SABBREVMONTHNAME1) |
| 639 | X(CAL_SABBREVMONTHNAME2) |
| 640 | X(CAL_SABBREVMONTHNAME3) |
| 641 | X(CAL_SABBREVMONTHNAME4) |
| 642 | X(CAL_SABBREVMONTHNAME5) |
| 643 | X(CAL_SABBREVMONTHNAME6) |
| 644 | X(CAL_SABBREVMONTHNAME7) |
| 645 | X(CAL_SABBREVMONTHNAME8) |
| 646 | X(CAL_SABBREVMONTHNAME9) |
| 647 | X(CAL_SABBREVMONTHNAME10) |
| 648 | X(CAL_SABBREVMONTHNAME11) |
| 649 | X(CAL_SABBREVMONTHNAME12) |
| 650 | X(CAL_SABBREVMONTHNAME13) |
| 651 | X(CAL_SYEARMONTH) |
| 652 | #undef X |
| 653 | default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff); |
| 654 | return E_FAIL; |
| 655 | } |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | /********************************************************************* |
Patrik Stridvall | c01c193 | 2001-06-19 03:36:23 +0000 | [diff] [blame] | 660 | * GetCalendarInfoW (KERNEL32.@) |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 661 | * |
| 662 | */ |
| 663 | int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, |
| 664 | LPWSTR lpCalData, int cchData, LPDWORD lpValue) |
| 665 | { |
| 666 | FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): stub\n", |
| 667 | Locale, Calendar, CalType, lpCalData, cchData, lpValue); |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | /********************************************************************* |
Patrik Stridvall | c01c193 | 2001-06-19 03:36:23 +0000 | [diff] [blame] | 672 | * SetCalendarInfoA (KERNEL32.@) |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 673 | * |
| 674 | */ |
| 675 | int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData) |
| 676 | { |
| 677 | FIXME("(%08lx,%08lx,%08lx,%s): stub\n", |
| 678 | Locale, Calendar, CalType, debugstr_a(lpCalData)); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | /********************************************************************* |
Patrik Stridvall | c01c193 | 2001-06-19 03:36:23 +0000 | [diff] [blame] | 683 | * SetCalendarInfoW (KERNEL32.@) |
Eric Pouech | a862f68 | 2001-02-26 22:33:29 +0000 | [diff] [blame] | 684 | * |
| 685 | */ |
| 686 | int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData) |
| 687 | { |
| 688 | FIXME("(%08lx,%08lx,%08lx,%s): stub\n", |
| 689 | Locale, Calendar, CalType, debugstr_w(lpCalData)); |
| 690 | return 0; |
| 691 | } |
| 692 | |