Sweden-Number/dlls/kernelbase/path.c

68 lines
1.9 KiB
C

/*
* Copyright 2018 Nikolay Sivov
*
* 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 <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "pathcch.h"
#include "strsafe.h"
#include "wine/debug.h"
#include "wine/unicode.h"
WINE_DEFAULT_DEBUG_CHANNEL(path);
HRESULT WINAPI PathCchAddBackslash(WCHAR *path, SIZE_T size)
{
return PathCchAddBackslashEx(path, size, NULL, NULL);
}
HRESULT WINAPI PathCchAddBackslashEx(WCHAR *path, SIZE_T size, WCHAR **endptr, SIZE_T *remaining)
{
BOOL needs_termination;
SIZE_T length;
TRACE("%s, %lu, %p, %p\n", debugstr_w(path), size, endptr, remaining);
length = strlenW(path);
needs_termination = size && length && path[length - 1] != '\\';
if (length >= (needs_termination ? size - 1 : size))
{
if (endptr) *endptr = NULL;
if (remaining) *remaining = 0;
return STRSAFE_E_INSUFFICIENT_BUFFER;
}
if (!needs_termination)
{
if (endptr) *endptr = path + length;
if (remaining) *remaining = size - length;
return S_FALSE;
}
path[length++] = '\\';
path[length] = 0;
if (endptr) *endptr = path + length;
if (remaining) *remaining = size - length;
return S_OK;
}