l10n: Update translation catalogues
[libisds.git] / test / simline / win32.c
blob8abe78b40c630dc18b29e9a302d681f35567dac5
1 #include "../../config.h"
2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
3 #include "../test-tools.h"
4 #include <stdio.h>
5 #include <string.h>
6 #include "http.h"
7 #include "win32.h"
9 static void yday2mday(struct tm *time) {
10 static int mtab[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
11 int i, year = 1900 + time->tm_year;
13 mtab[1] = (!(year % 4) && ((year % 100) || !(year %400))) ? 29 : 28;
14 time->tm_mday = time->tm_yday + 1;
16 for (i = 0; i < 12; i++) {
17 if (time->tm_mday > mtab[i]) {
18 time->tm_mday -= mtab[i];
19 } else {
20 break;
24 time->tm_mon = i;
27 /* Convert UTF-8 @string representation of ISO 8601 date to @time.
28 * XXX: Not all ISO formats are supported */
29 http_error _server_datestring2tm(const char *string, struct tm *time) {
30 char *ptr;
31 int len, tmp;
32 if (!string || !time) return HTTP_ERROR_SERVER;
34 memset(time, 0, sizeof(*time));
36 if (sscanf(string, "%d-%d-%d%n",
37 &time->tm_year, &time->tm_mon, &time->tm_mday, &tmp) >= 3
38 && tmp == strlen(string)) {
39 time->tm_mon--;
40 time->tm_year -= 1900;
41 return HTTP_ERROR_SUCCESS;
44 memset(time, 0, sizeof(*time));
46 if (sscanf(string, "%d-%d%n",
47 &time->tm_year, &time->tm_yday, &tmp) >= 2
48 && tmp == strlen(string)) {
49 time->tm_yday--;
50 time->tm_year -= 1900;
51 yday2mday(time);
52 return HTTP_ERROR_SUCCESS;
55 memset(time, 0, sizeof(*time));
56 len = strlen(string);
58 if (len < 4) {
59 return HTTP_ERROR_SERVER;
62 ptr = strdup(string);
64 if (sscanf(ptr + len - 2, "%d%n", &time->tm_mday, &tmp) < 1 || tmp < 2) {
65 free(ptr);
66 return HTTP_ERROR_SERVER;
69 ptr[len - 2] = '\0';
71 if (sscanf(ptr + len - 4, "%d%n", &time->tm_mon, &tmp) < 1 || tmp < 2) {
72 free(ptr);
73 return HTTP_ERROR_SERVER;
76 ptr[len - 4] = '\0';
78 if (sscanf(ptr, "%d%n", &time->tm_year, &tmp) < 1 || tmp < len - 4) {
79 free(ptr);
80 return HTTP_ERROR_SERVER;
83 free(ptr);
84 time->tm_mon--;
85 time->tm_year -= 1900;
86 return HTTP_ERROR_SUCCESS;