* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#include "msvcrt.h"
-#include "msvcrt/stdlib.h"
-#include "msvcrt/string.h"
-
-DEFAULT_DEBUG_CHANNEL(msvcrt);
-
-/* INTERNAL: MSVCRT_malloc() based strndup */
-char* msvcrt_strndup(const char* buf, unsigned int size)
-{
- char* ret;
- unsigned int len = strlen(buf), max_len;
-
- max_len = size <= len? size : len + 1;
+#define _ISOC99_SOURCE
+#include "config.h"
- ret = MSVCRT_malloc(max_len);
- if (ret)
- {
- memcpy(ret,buf,max_len);
- ret[max_len] = 0;
- }
- return ret;
-}
+#include <stdlib.h>
+#include "msvcrt.h"
+#include "wine/debug.h"
-/*********************************************************************
- * _strdec (MSVCRT.@)
- */
-char* _strdec(const char* str1, const char* str2)
-{
- /* Hmm. While the docs suggest that the following should work... */
- /* return (str2<=str1?0:str2-1); */
- /* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
- str1 = str1; /* remove warning */
- return (char *)str2-1;
-}
+WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/*********************************************************************
* _mbsdup (MSVCRT.@)
* _strdup (MSVCRT.@)
*/
-char* _strdup(const char* str)
-{
- char * ret = MSVCRT_malloc(strlen(str)+1);
- if (ret) strcpy( ret, str );
- return ret;
-}
-
-/*********************************************************************
- * _strinc (MSVCRT.@)
- */
-char* _strinc(const char* str)
+char* CDECL _strdup(const char* str)
{
- return (char*)str+1;
-}
-
-/*********************************************************************
- * _strnextc (MSVCRT.@)
- */
-unsigned int _strnextc(const char* str)
-{
- return (unsigned int)*str;
-}
-
-/*********************************************************************
- * _strninc (MSVCRT.@)
- *
- * Return a pointer to the 'n'th character in a string
- */
-char* _strninc(char* str, unsigned int n)
-{
- return str + n;
+ if(str)
+ {
+ char * ret = MSVCRT_malloc(strlen(str)+1);
+ if (ret) strcpy( ret, str );
+ return ret;
+ }
+ else return 0;
}
/*********************************************************************
* _strnset (MSVCRT.@)
*/
-char* _strnset(char* str, int value, unsigned int len)
+char* CDECL _strnset(char* str, int value, MSVCRT_size_t len)
{
if (len > 0 && str)
while (*str && len--)
/*********************************************************************
* _strrev (MSVCRT.@)
*/
-char* _strrev(char* str)
+char* CDECL _strrev(char* str)
{
char * p1;
char * p2;
/*********************************************************************
* _strset (MSVCRT.@)
*/
-char* _strset(char* str, int value)
+char* CDECL _strset(char* str, int value)
{
char *ptr = str;
while (*ptr)
}
/*********************************************************************
- * _strncnt (MSVCRT.@)
+ * strtok (MSVCRT.@)
*/
-unsigned int _strncnt(char* str, unsigned int max)
+char * CDECL MSVCRT_strtok( char *str, const char *delim )
{
- unsigned int len = strlen(str);
- return (len > max? max : len);
+ thread_data_t *data = msvcrt_get_thread_data();
+ char *ret;
+
+ if (!str)
+ if (!(str = data->strtok_next)) return NULL;
+
+ while (*str && strchr( delim, *str )) str++;
+ if (!*str) return NULL;
+ ret = str++;
+ while (*str && !strchr( delim, *str )) str++;
+ if (*str) *str++ = 0;
+ data->strtok_next = str;
+ return ret;
}
-/*********************************************************************
- * _strspnp (MSVCRT.@)
- */
-char* _strspnp(char* str1, char* str2)
-{
- str1 += strspn(str1,str2);
- return *str1? str1 : 0;
-}
/*********************************************************************
* _swab (MSVCRT.@)
*/
-void _swab(char* src, char* dst, int len)
+void CDECL MSVCRT__swab(char* src, char* dst, int len)
{
if (len > 1)
{
len = (unsigned)len >> 1;
while (len--) {
- *dst++ = src[1];
- *dst++ = *src++;
- src++;
+ char s0 = src[0];
+ char s1 = src[1];
+ *dst++ = s1;
+ *dst++ = s0;
+ src = src + 2;
}
}
}
+
+/*********************************************************************
+ * atof (MSVCRT.@)
+ */
+double CDECL MSVCRT_atof( const char *str )
+{
+ return atof( str );
+}
+
+/*********************************************************************
+ * strtod (MSVCRT.@)
+ */
+double CDECL MSVCRT_strtod( const char *str, char **end )
+{
+ return strtod( str, end );
+}
+
+/*********************************************************************
+ * strcoll (MSVCRT.@)
+ */
+int CDECL MSVCRT_strcoll( const char* str1, const char* str2 )
+{
+ /* FIXME: handle Windows locale */
+ return strcoll( str1, str2 );
+}
+
+/*********************************************************************
+ * strcpy_s (MSVCRT.@)
+ */
+int CDECL MSVCRT_strcpy_s( char* dst, MSVCRT_size_t elem, const char* src )
+{
+ MSVCRT_size_t i;
+ if(!elem) return MSVCRT_EINVAL;
+ if(!dst) return MSVCRT_EINVAL;
+ if(!src)
+ {
+ dst[0] = '\0';
+ return MSVCRT_EINVAL;
+ }
+
+ for(i = 0; i < elem; i++)
+ {
+ if((dst[i] = src[i]) == '\0') return 0;
+ }
+ dst[0] = '\0';
+ return MSVCRT_ERANGE;
+}
+
+/*********************************************************************
+ * strcat_s (MSVCRT.@)
+ */
+int CDECL MSVCRT_strcat_s( char* dst, MSVCRT_size_t elem, const char* src )
+{
+ MSVCRT_size_t i, j;
+ if(!dst) return MSVCRT_EINVAL;
+ if(elem == 0) return MSVCRT_EINVAL;
+ if(!src)
+ {
+ dst[0] = '\0';
+ return MSVCRT_EINVAL;
+ }
+
+ for(i = 0; i < elem; i++)
+ {
+ if(dst[i] == '\0')
+ {
+ for(j = 0; (j + i) < elem; j++)
+ {
+ if((dst[j + i] = src[j]) == '\0') return 0;
+ }
+ }
+ }
+ /* Set the first element to 0, not the first element after the skipped part */
+ dst[0] = '\0';
+ return MSVCRT_ERANGE;
+}
+
+/*********************************************************************
+ * strxfrm (MSVCRT.@)
+ */
+MSVCRT_size_t CDECL MSVCRT_strxfrm( char *dest, const char *src, MSVCRT_size_t len )
+{
+ /* FIXME: handle Windows locale */
+ return strxfrm( dest, src, len );
+}
+
+/*********************************************************************
+ * _stricoll (MSVCRT.@)
+ */
+int CDECL MSVCRT__stricoll( const char* str1, const char* str2 )
+{
+ /* FIXME: handle collates */
+ TRACE("str1 %s str2 %s\n", debugstr_a(str1), debugstr_a(str2));
+ return lstrcmpiA( str1, str2 );
+}
+
+/********************************************************************
+ * _atoldbl (MSVCRT.@)
+ */
+int CDECL MSVCRT__atoldbl(MSVCRT__LDOUBLE *value, const char *str)
+{
+ /* FIXME needs error checking for huge/small values */
+#ifdef HAVE_STRTOLD
+ TRACE("str %s value %p\n",str,value);
+ value->x = strtold(str,0);
+#else
+ FIXME("stub, str %s value %p\n",str,value);
+#endif
+ return 0;
+}
+
+/********************************************************************
+ * __STRINGTOLD (MSVCRT.@)
+ */
+int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str, int flags )
+{
+#ifdef HAVE_STRTOLD
+ FIXME("%p %p %s %x partial stub\n", value, endptr, str, flags );
+ value->x = strtold(str,endptr);
+#else
+ FIXME("%p %p %s %x stub\n", value, endptr, str, flags );
+#endif
+ return 0;
+}