diff options
| author | 2013-02-18 01:41:59 +0100 | |
|---|---|---|
| committer | 2013-02-18 01:41:59 +0100 | |
| commit | f1ec18b6fce73f7346cf4265211721a30787b1ce (patch) | |
| tree | 09ec6c9f83e0794c9406321c1e34635f01bced8a | |
| parent | fe8198c6ec12d20cbdfdad13d3cc077dee48a6e6 (diff) | |
| download | csoap-f1ec18b6fce73f7346cf4265211721a30787b1ce.tar.gz csoap-f1ec18b6fce73f7346cf4265211721a30787b1ce.tar.bz2 | |
Fix compilation of strtok_r and localtime_r replacements for WIN32 builds
| -rw-r--r-- | nanohttp/nanohttp-common.c | 105 | 
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 | 
