Browse code

- _timegm added to utils

Jan Janak authored on 15/12/2005 23:17:40
Showing 2 changed files
... ...
@@ -32,6 +32,7 @@
32 32
 #include <pwd.h>
33 33
 #include <grp.h>
34 34
 #include <stdlib.h>
35
+#include <time.h>
35 36
 #include "ut.h"
36 37
 
37 38
 /* converts a username into uid:gid,
... ...
@@ -82,3 +83,38 @@ int group2gid(int* gid, char* group)
82 83
 error:
83 84
 	return -1;
84 85
 }
86
+
87
+
88
+/*
89
+ * Replacement of timegm (does not exists on all platforms
90
+ * Taken from 
91
+ * http://lists.samba.org/archive/samba-technical/2002-November/025737.html
92
+ */
93
+time_t _timegm(struct tm* t)
94
+{
95
+	time_t tl, tb;
96
+	struct tm* tg;
97
+	
98
+	tl = mktime(t);
99
+	if (tl == -1) {
100
+		t->tm_hour--;
101
+		tl = mktime (t);
102
+		if (tl == -1) {
103
+			return -1; /* can't deal with output from strptime */
104
+		}
105
+		tl += 3600;
106
+	}
107
+	
108
+	tg = gmtime(&tl);
109
+	tg->tm_isdst = 0;
110
+	tb = mktime(tg);
111
+	if (tb == -1) {
112
+		tg->tm_hour--;
113
+		tb = mktime (tg);
114
+		if (tb == -1) {
115
+			return -1; /* can't deal with output from gmtime */
116
+		}
117
+		tb += 3600;
118
+	}
119
+	return (tl - (tb - tl));
120
+}
... ...
@@ -50,6 +50,7 @@
50 50
 #include <sys/types.h>
51 51
 #include <sys/time.h>
52 52
 #include <limits.h>
53
+#include <time.h>
53 54
 #include <unistd.h>
54 55
 #include <ctype.h>
55 56
 
... ...
@@ -427,4 +428,11 @@ int user2uid(int* uid, int* gid, char* user);
427 428
  * returns -1 on error, 0 on success */
428 429
 int group2gid(int* gid, char* group);
429 430
 
431
+/*
432
+ * Replacement of timegm (does not exists on all platforms
433
+ * Taken from 
434
+ * http://lists.samba.org/archive/samba-technical/2002-November/025737.html
435
+ */
436
+time_t _timegm(struct tm* t);
437
+
430 438
 #endif