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