1 // compatibility routines, non reentrant ....
3 #include <string.h>
4 #include <time.h>
6 struct tm* localtime_r(const time_t* t, struct tm* r) {
7 struct tm * temp;
8 temp = localtime(t);
9 memcpy(r,temp,sizeof(struct tm));
10 return(r);
11 }
13 struct tm* gmtime_r(const time_t* t, struct tm* r) {
14 struct tm * temp;
15 temp = gmtime(t);
16 memcpy(r,temp,sizeof(struct tm));
17 return r;
18 }
20 char* ctime_r (const time_t* t, char* buf) {
21 char * temp;
22 temp = asctime(localtime(t));
23 strcpy(buf,temp);
24 return(buf);
25 }
27 /*
28 s
29 Points to the string from which to extract tokens.
31 delim
32 Points to a null-terminated set of delimiter characters.
34 save_ptr
35 Is a value-return parameter used by strtok_r() to record its progress through s1.
36 */
39 char * strtok_r (char *s, const char *delim, char **save_ptr) {
40 char *token;
42 if (s == NULL) s = *save_ptr;
44 /* Scan leading delimiters. */
45 s += strspn(s, delim);
46 if (*s == '\0')
47 {
48 *save_ptr = s;
49 return NULL;
50 }
52 /* Find the end of the token. */
53 token = s;
54 s = strpbrk (token, delim);
55 if (s == NULL) {
56 /* This token finishes the string. */
57 *save_ptr = token;
58 while (**save_ptr != '\0') (*save_ptr)++;
59 } else
60 {
61 /* Terminate the token and make *SAVE_PTR point past it. */
62 *s = '\0';
63 *save_ptr = s + 1;
64 }
65 return token;
66 }