mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 22:50:43 +00:00
106 lines
2.9 KiB
C
106 lines
2.9 KiB
C
/*
|
|
* String functions
|
|
*
|
|
* Copyright 1993 Yngvi Sigurjonsson
|
|
* Copyright 1996 Alexandre Julliard
|
|
*
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
|
|
#include "ntstatus.h"
|
|
#include "windef.h"
|
|
#include "winbase.h"
|
|
#include "wine/winbase16.h"
|
|
#include "wine/exception.h"
|
|
#include "wine/unicode.h"
|
|
#include "winerror.h"
|
|
#include "winnls.h"
|
|
#include "excpt.h"
|
|
#include "wine/debug.h"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(string);
|
|
|
|
/***********************************************************************
|
|
* lstrcpyn (KERNEL32.@)
|
|
* lstrcpynA (KERNEL32.@)
|
|
*
|
|
* Note: this function differs from the UNIX strncpy, it _always_ writes
|
|
* a terminating \0.
|
|
*
|
|
* Note: n is an INT but Windows treats it as unsigned, and will happily
|
|
* copy a gazillion chars if n is negative.
|
|
*/
|
|
LPSTR WINAPI lstrcpynA( LPSTR dst, LPCSTR src, INT n )
|
|
{
|
|
LPSTR p = dst;
|
|
UINT count = n;
|
|
|
|
TRACE("(%p, %s, %i)\n", dst, debugstr_a(src), n);
|
|
|
|
/* In real windows the whole function is protected by an exception handler
|
|
* that returns ERROR_INVALID_PARAMETER on faulty parameters
|
|
* We currently just check for NULL.
|
|
*/
|
|
if (!dst || !src) {
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
return 0;
|
|
}
|
|
while ((count > 1) && *src)
|
|
{
|
|
count--;
|
|
*p++ = *src++;
|
|
}
|
|
if (count) *p = 0;
|
|
return dst;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* lstrcpynW (KERNEL32.@)
|
|
*
|
|
* Note: this function differs from the UNIX strncpy, it _always_ writes
|
|
* a terminating \0
|
|
*
|
|
* Note: n is an INT but Windows treats it as unsigned, and will happily
|
|
* copy a gazillion chars if n is negative.
|
|
*/
|
|
LPWSTR WINAPI lstrcpynW( LPWSTR dst, LPCWSTR src, INT n )
|
|
{
|
|
LPWSTR p = dst;
|
|
UINT count = n;
|
|
|
|
TRACE("(%p, %s, %i)\n", dst, debugstr_w(src), n);
|
|
|
|
/* In real windows the whole function is protected by an exception handler
|
|
* that returns ERROR_INVALID_PARAMETER on faulty parameters
|
|
* We currently just check for NULL.
|
|
*/
|
|
if (!dst || !src) {
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
return 0;
|
|
}
|
|
while ((count > 1) && *src)
|
|
{
|
|
count--;
|
|
*p++ = *src++;
|
|
}
|
|
if (count) *p = 0;
|
|
return dst;
|
|
}
|