summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nanohttp/nanohttp-common.c105
1 files changed, 56 insertions, 49 deletions
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 18b206b..7ec3d17 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -60,6 +60,61 @@
#ifdef WIN32
#include <time.h>
+#include <ws2tcpip.h>
+#endif
+
+#ifdef WIN32
+
+#ifndef strtok_r
+/* strtok_r() */
+char *
+strtok_r(char *s, const char *delim, char **save_ptr)
+{
+ char *token;
+
+ if (s == NULL)
+ s = *save_ptr;
+
+ /* Scan leading delimiters. */
+ s += strspn(s, delim);
+ if (*s == '\0')
+ return NULL;
+
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk(token, delim);
+ if (s == NULL)
+ /* This token finishes the string. */
+ *save_ptr = strchr(token, '\0');
+ else
+ {
+ /* Terminate the token and make *SAVE_PTR point past it. */
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+ return token;
+}
+#endif
+
+/* New mingw pthread package seems to define localtime_r as a macro */
+#ifdef localtime_r
+#undef localtime_r
+#endif
+
+/* localtime_r() */
+struct tm *
+localtime_r(const time_t * timep, struct tm* p_tm)
+{
+ static struct tm *tmp;
+ tmp = localtime(timep);
+ if (tmp)
+ {
+ memcpy(p_tm, tmp, sizeof(struct tm));
+ tmp = p_tm;
+ }
+ return tmp;
+}
+
#endif
hpair_t *
@@ -108,7 +163,7 @@ hpairnode_parse(const char *str, const char *delim, hpair_t * next)
pair->value = "";
pair->next = next;
- key = strtok_r((char *) str, delim, &value);
+ key = (char*)strtok_r((char *) str, delim, &value);
if (key != NULL)
{
@@ -484,51 +539,3 @@ attachments_free(struct attachments_t *message)
return;
}
-
-
-#ifdef WIN32
-
-/* strtok_r() */
-char *
-strtok_r(char *s, const char *delim, char **save_ptr)
-{
- char *token;
-
- if (s == NULL)
- s = *save_ptr;
-
- /* Scan leading delimiters. */
- s += strspn(s, delim);
- if (*s == '\0')
- return NULL;
-
- /* Find the end of the token. */
- token = s;
- s = strpbrk(token, delim);
- if (s == NULL)
- /* This token finishes the string. */
- *save_ptr = strchr(token, '\0');
- else
- {
- /* Terminate the token and make *SAVE_PTR point past it. */
- *s = '\0';
- *save_ptr = s + 1;
- }
- return token;
-}
-
-/* localtime_r() */
-struct tm *
-localtime_r(const time_t * const timep, struct tm *p_tm)
-{
- static struct tm *tmp;
- tmp = localtime(timep);
- if (tmp)
- {
- memcpy(p_tm, tmp, sizeof(struct tm));
- tmp = p_tm;
- }
- return tmp;
-}
-
-#endif