Fixes #738 Actual completion : added missing file

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4910 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 739044b6495479cf096d0a6ceed39feb7349dfd6
Former-commit-id: 407e05e095e546e41c3ec860c9a2d4b7a75f5fee
This commit is contained in:
pouillot 2012-08-31 18:24:08 +00:00
parent 2bd3148b5c
commit 071c2d31c6

View file

@ -0,0 +1,72 @@
/***************************************************************************
file : portability.cpp
created : August 2012
copyright : (C) 2012 Jean-Philippe Meuret
web : speed-dreams.sourceforge.net
version : $Id$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "portability.h"
// Missing strndup, define it here (for FreeBSD).
// Code provided by Thierry Thomas.
#ifndef HAVE_STRNDUP
char *strndup(const char *str, int len)
{
if (!str || len < 0)
return 0;
char* ret;
if (!(ret = (char*)malloc(len + 1)))
return 0;
memcpy(ret, str, len);
ret[len] = '\0';
return ret;
}
#endif // HAVE_STRNDUP
// Missing strtok_r, define it here (for MinGW).
// Code provided by Charlie Gordon http://bytes.com/topic/c/answers/708293-strtok-strtok_r.
#ifndef HAVE_STRTOK_R
#ifdef _MSC_VER
#undef strtok_r // Avoid warning C4273: 'strtok_s' : inconsistent dll linkage (yes, 'strtok_s', not '_r' !)
#endif
char *strtok_r(char *str, const char *delim, char **nextp)
{
char *ret;
if (!str)
str = *nextp;
str += strspn(str, delim);
if (*str == '\0')
return 0;
ret = str;
str += strcspn(str, delim);
if (*str)
*str++ = '\0';
*nextp = str;
return ret;
}
#endif // HAVE_STRTOK_R