2001-01-10 23:59:25 +00:00
|
|
|
/*
|
|
|
|
* msvcrt.dll drive/directory functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2020-11-27 13:17:01 +00:00
|
|
|
#include <stdlib.h>
|
2020-11-20 11:35:52 +00:00
|
|
|
#include <direct.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-09-12 22:07:02 +00:00
|
|
|
#include "winternl.h"
|
2001-01-10 23:59:25 +00:00
|
|
|
#include "msvcrt.h"
|
2002-01-22 00:57:16 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2020-12-03 18:11:02 +00:00
|
|
|
#undef _wfindfirst
|
|
|
|
#undef _wfindfirsti64
|
|
|
|
#undef _wfindnext
|
|
|
|
#undef _wfindnexti64
|
|
|
|
#undef _wfindfirst32
|
|
|
|
#undef _wfindnext32
|
|
|
|
#undef _wfindfirst64i32
|
|
|
|
#undef _wfindfirst64
|
|
|
|
#undef _wfindnext64i32
|
|
|
|
#undef _wfindnext64
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAA to finddata_t */
|
2004-03-16 19:17:11 +00:00
|
|
|
static void msvcrt_fttofd( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata_t* ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_create = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_access = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
2011-03-15 00:01:43 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAA to finddata32_t */
|
|
|
|
static void msvcrt_fttofd32( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata32_t* ft)
|
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata_t */
|
2020-12-03 18:11:02 +00:00
|
|
|
static void msvcrt_wfttofd( const WIN32_FIND_DATAW *fd, struct _wfinddata_t* ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_create = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_access = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2001-01-10 23:59:25 +00:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(ft->name, fd->cFileName);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 11:18:48 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata32_t */
|
2020-12-03 18:11:02 +00:00
|
|
|
static void msvcrt_wfttofd32(const WIN32_FIND_DATAW *fd, struct _wfinddata32_t* ft)
|
2013-04-19 11:18:48 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(ft->name, fd->cFileName);
|
2013-04-19 11:18:48 +00:00
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAA to finddatai64_t */
|
2004-03-16 19:17:11 +00:00
|
|
|
static void msvcrt_fttofdi64( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddatai64_t* ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_create = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_access = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:42:27 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAA to finddata64_t */
|
|
|
|
static void msvcrt_fttofd64( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata64_t* ft)
|
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
2011-02-26 18:49:21 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata64_t */
|
2020-12-03 18:11:02 +00:00
|
|
|
static void msvcrt_wfttofd64( const WIN32_FIND_DATAW *fd, struct _wfinddata64_t* ft)
|
2011-02-26 18:49:21 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(ft->name, fd->cFileName);
|
2011-02-26 18:49:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 19:52:22 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAA to finddata64i32_t */
|
|
|
|
static void msvcrt_fttofd64i32( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata64i32_t* ft)
|
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
2010-04-15 11:42:27 +00:00
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddatai64_t */
|
2020-12-03 18:11:02 +00:00
|
|
|
static void msvcrt_wfttofdi64( const WIN32_FIND_DATAW *fd, struct _wfinddatai64_t* ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_create = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_access = dw;
|
2004-11-30 21:38:57 +00:00
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2004-01-13 05:45:05 +00:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(ft->name, fd->cFileName);
|
2004-01-13 05:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-11-20 13:49:54 +00:00
|
|
|
/* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata64i32_t */
|
2020-12-03 18:11:02 +00:00
|
|
|
static void msvcrt_wfttofd64i32( const WIN32_FIND_DATAW *fd, struct _wfinddata64i32_t* ft)
|
2010-11-20 13:49:54 +00:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
|
|
|
ft->time_create = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
|
|
|
ft->time_access = dw;
|
|
|
|
RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(ft->name, fd->cFileName);
|
2010-11-20 13:49:54 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _chdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Change the current working directory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* newdir [I] Directory to change to
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. The current working directory is set to newdir.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SetCurrentDirectoryA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _chdir(const char * newdir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (!SetCurrentDirectoryA(newdir))
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(newdir?GetLastError():0);
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wchdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _chdir.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wchdir(const wchar_t * newdir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (!SetCurrentDirectoryW(newdir))
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(newdir?GetLastError():0);
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _chdrive (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Change the current drive.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* newdrive [I] Drive number to change to (1 = 'A', 2 = 'B', ...)
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. The current drive is set to newdrive.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SetCurrentDirectoryA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _chdrive(int newdrive)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-11-27 13:16:53 +00:00
|
|
|
WCHAR buffer[] = L"A:";
|
2004-02-09 20:45:59 +00:00
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
buffer[0] += newdrive - 1;
|
2004-02-09 20:45:59 +00:00
|
|
|
if (!SetCurrentDirectoryW( buffer ))
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
if (newdrive <= 0)
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EACCES;
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _findclose (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Close a handle returned by _findfirst().
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hand [I] Handle to close
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. All resources associated with hand are freed.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See FindClose.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findclose(intptr_t hand)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-11-20 11:35:52 +00:00
|
|
|
TRACE(":handle %Iu\n",hand);
|
2001-01-10 23:59:25 +00:00
|
|
|
if (!FindClose((HANDLE)hand))
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _findfirst (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Open a handle for iterating through a directory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* fspec [I] File specification of files to iterate.
|
|
|
|
* ft [O] Information for the first file found.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A handle suitable for passing to _findnext() and _findclose().
|
|
|
|
* ft is populated with the details of the found file.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See FindFirstFileA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _findfirst(const char * fspec, struct MSVCRT__finddata_t* ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_fttofd(&find_data,ft);
|
2002-10-25 03:12:01 +00:00
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 00:01:43 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findfirst32 (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _findfirst32(const char * fspec, struct MSVCRT__finddata32_t* ft)
|
2011-03-15 00:01:43 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_fttofd32(&find_data, ft);
|
|
|
|
TRACE(":got handle %p\n", hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2011-03-15 00:01:43 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
2020-12-03 18:11:02 +00:00
|
|
|
* _wfindfirst (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _findfirst.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _wfindfirst(const wchar_t * fspec, struct _wfinddata_t* ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_wfttofd(&find_data,ft);
|
2002-10-25 03:12:01 +00:00
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 11:18:48 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindfirst32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _findfirst32.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _wfindfirst32(const wchar_t * fspec, struct _wfinddata32_t* ft)
|
2013-04-19 11:18:48 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_wfttofd32(&find_data, ft);
|
|
|
|
TRACE(":got handle %p\n", hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2013-04-19 11:18:48 +00:00
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findfirsti64 (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* 64-bit version of _findfirst.
|
2004-01-13 05:45:05 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _findfirsti64(const char * fspec, struct MSVCRT__finddatai64_t* ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2004-01-13 05:45:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_fttofdi64(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2004-01-13 05:45:05 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 11:42:27 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findfirst64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* 64-bit version of _findfirst.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _findfirst64(const char * fspec, struct MSVCRT__finddata64_t* ft)
|
2010-04-15 11:42:27 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_fttofd64(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2010-04-15 11:42:27 +00:00
|
|
|
}
|
|
|
|
|
2011-02-26 18:49:21 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindfirst64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _findfirst64.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _wfindfirst64(const wchar_t * fspec, struct _wfinddata64_t* ft)
|
2011-02-26 18:49:21 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_wfttofd64(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2011-02-26 18:49:21 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 19:52:22 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findfirst64i32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* 64-bit/32-bit version of _findfirst.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _findfirst64i32(const char * fspec, struct MSVCRT__finddata64i32_t* ft)
|
2010-11-01 19:52:22 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_fttofd64i32(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2010-11-01 19:52:22 +00:00
|
|
|
}
|
|
|
|
|
2010-11-20 13:49:54 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindfirst64i32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _findfirst64i32.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _wfindfirst64i32(const wchar_t * fspec, struct _wfinddata64i32_t* ft)
|
2010-11-20 13:49:54 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_wfttofd64i32(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2010-11-20 13:49:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindfirsti64 (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _findfirsti64.
|
2004-01-13 05:45:05 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
intptr_t CDECL _wfindfirsti64(const wchar_t * fspec, struct _wfinddatai64_t* ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2004-01-13 05:45:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msvcrt_wfttofdi64(&find_data,ft);
|
|
|
|
TRACE(":got handle %p\n",hfind);
|
2020-11-27 13:17:05 +00:00
|
|
|
return (intptr_t)hfind;
|
2004-01-13 05:45:05 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findnext (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Find the next file from a file search handle.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hand [I] Handle to the search returned from _findfirst().
|
|
|
|
* ft [O] Information for the file found.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. ft is populated with the details of the found file.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See FindNextFileA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findnext(intptr_t hand, struct MSVCRT__finddata_t * ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
2002-10-25 03:12:01 +00:00
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_fttofd(&find_data,ft);
|
2001-01-10 23:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-15 00:06:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findnext32 (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findnext32(intptr_t hand, struct MSVCRT__finddata32_t * ft)
|
2011-03-15 00:06:17 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2011-03-15 00:06:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_fttofd32(&find_data, ft);
|
2016-11-04 16:05:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wfindnext32 (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wfindnext32(intptr_t hand, struct _wfinddata32_t * ft)
|
2016-11-04 16:05:05 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2016-11-04 16:05:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_wfttofd32(&find_data, ft);
|
2011-03-15 00:06:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
2020-12-03 18:11:02 +00:00
|
|
|
* _wfindnext (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _findnext.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wfindnext(intptr_t hand, struct _wfinddata_t * ft)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
2002-10-25 03:12:01 +00:00
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 21:16:07 +00:00
|
|
|
msvcrt_wfttofd(&find_data,ft);
|
2001-01-10 23:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findnexti64 (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* 64-bit version of _findnext.
|
2004-01-13 05:45:05 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findnexti64(intptr_t hand, struct MSVCRT__finddatai64_t * ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2004-01-13 05:45:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_fttofdi64(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-15 11:42:27 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findnext64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* 64-bit version of _findnext.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findnext64(intptr_t hand, struct MSVCRT__finddata64_t * ft)
|
2010-04-15 11:42:27 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2010-04-15 11:42:27 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_fttofd64(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-26 18:49:51 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindnext64 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _wfindnext64.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wfindnext64(intptr_t hand, struct _wfinddata64_t * ft)
|
2011-02-26 18:49:51 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2011-02-26 18:49:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_wfttofd64(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-01 19:52:22 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _findnext64i32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* 64-bit/32-bit version of _findnext.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _findnext64i32(intptr_t hand, struct MSVCRT__finddata64i32_t * ft)
|
2010-11-01 19:52:22 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2010-11-01 19:52:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_fttofd64i32(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-13 05:45:05 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindnexti64 (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _findnexti64.
|
2004-01-13 05:45:05 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wfindnexti64(intptr_t hand, struct _wfinddatai64_t * ft)
|
2004-01-13 05:45:05 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2004-01-13 05:45:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_wfttofdi64(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-20 14:15:00 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfindnext64i32 (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _findnext64i32.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wfindnext64i32(intptr_t hand, struct _wfinddata64i32_t * ft)
|
2010-11-20 14:15:00 +00:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2010-11-20 14:15:00 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msvcrt_wfttofd64i32(&find_data,ft);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _getcwd (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Get the current working directory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* buf [O] Destination for current working directory.
|
|
|
|
* size [I] Size of buf in characters
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: If buf is NULL, returns an allocated string containing the path.
|
|
|
|
* Otherwise populates buf with the path and returns it.
|
|
|
|
* Failure: NULL. errno indicates the error.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
char* CDECL _getcwd(char * buf, int size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2002-05-01 18:13:18 +00:00
|
|
|
char dir[MAX_PATH];
|
2001-01-10 23:59:25 +00:00
|
|
|
int dir_len = GetCurrentDirectoryA(MAX_PATH,dir);
|
|
|
|
|
|
|
|
if (dir_len < 1)
|
|
|
|
return NULL; /* FIXME: Real return value untested */
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
2007-07-27 10:17:58 +00:00
|
|
|
if (size <= dir_len) size = dir_len + 1;
|
2020-12-01 12:51:32 +00:00
|
|
|
if (!(buf = malloc( size ))) return NULL;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2007-07-27 10:17:58 +00:00
|
|
|
else if (dir_len >= size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
strcpy(buf,dir);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wgetcwd (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _getcwd.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
wchar_t* CDECL _wgetcwd(wchar_t * buf, int size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t dir[MAX_PATH];
|
2001-01-10 23:59:25 +00:00
|
|
|
int dir_len = GetCurrentDirectoryW(MAX_PATH,dir);
|
|
|
|
|
|
|
|
if (dir_len < 1)
|
|
|
|
return NULL; /* FIXME: Real return value untested */
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
2007-07-27 10:17:58 +00:00
|
|
|
if (size <= dir_len) size = dir_len + 1;
|
2020-12-01 12:51:32 +00:00
|
|
|
if (!(buf = malloc( size * sizeof(WCHAR) ))) return NULL;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
if (dir_len >= size)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(buf,dir);
|
2001-01-10 23:59:25 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdrive (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Get the current drive number.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: The drive letter number from 1 to 26 ("A:" to "Z:").
|
|
|
|
* Failure: 0.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _getdrive(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2004-02-09 20:45:59 +00:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
if (GetCurrentDirectoryW( MAX_PATH, buffer ) &&
|
|
|
|
buffer[0] >= 'A' && buffer[0] <= 'z' && buffer[1] == ':')
|
2020-12-03 18:10:54 +00:00
|
|
|
return towupper(buffer[0]) - 'A' + 1;
|
2004-02-09 20:45:59 +00:00
|
|
|
return 0;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdcwd (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Get the current working directory on a given disk.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* drive [I] Drive letter to get the current working directory from.
|
|
|
|
* buf [O] Destination for the current working directory.
|
|
|
|
* size [I] Length of drive in characters.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: If drive is NULL, returns an allocated string containing the path.
|
|
|
|
* Otherwise populates drive with the path and returns it.
|
|
|
|
* Failure: NULL. errno indicates the error.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
char* CDECL _getdcwd(int drive, char * buf, int size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
static char* dummy;
|
|
|
|
|
|
|
|
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
|
|
|
|
|
2020-12-03 18:11:02 +00:00
|
|
|
if (!drive || drive == _getdrive())
|
|
|
|
return _getcwd(buf,size); /* current */
|
2001-01-10 23:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
2002-05-01 18:13:18 +00:00
|
|
|
char dir[MAX_PATH];
|
2020-11-27 13:16:53 +00:00
|
|
|
char drivespec[] = "A:";
|
2001-01-10 23:59:25 +00:00
|
|
|
int dir_len;
|
|
|
|
|
|
|
|
drivespec[0] += drive - 1;
|
|
|
|
if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EACCES;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-01 18:13:18 +00:00
|
|
|
dir_len = GetFullPathNameA(drivespec,MAX_PATH,dir,&dummy);
|
2001-01-10 23:59:25 +00:00
|
|
|
if (dir_len >= size || dir_len < 1)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(":returning '%s'\n", dir);
|
|
|
|
if (!buf)
|
2020-12-01 23:54:09 +00:00
|
|
|
return _strdup(dir); /* allocate */
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
strcpy(buf,dir);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wgetdcwd (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _wgetdcwd.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
wchar_t* CDECL _wgetdcwd(int drive, wchar_t * buf, int size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
static wchar_t* dummy;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
|
|
|
|
|
2020-12-03 18:11:02 +00:00
|
|
|
if (!drive || drive == _getdrive())
|
|
|
|
return _wgetcwd(buf,size); /* current */
|
2001-01-10 23:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t dir[MAX_PATH];
|
2020-11-27 13:16:53 +00:00
|
|
|
wchar_t drivespec[4] = L"A:\\";
|
2001-01-10 23:59:25 +00:00
|
|
|
int dir_len;
|
|
|
|
|
|
|
|
drivespec[0] += drive - 1;
|
|
|
|
if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EACCES;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-01 18:13:18 +00:00
|
|
|
dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
|
2001-01-10 23:59:25 +00:00
|
|
|
if (dir_len >= size || dir_len < 1)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
|
2001-05-11 20:03:40 +00:00
|
|
|
TRACE(":returning %s\n", debugstr_w(dir));
|
2001-01-10 23:59:25 +00:00
|
|
|
if (!buf)
|
2020-12-03 18:10:54 +00:00
|
|
|
return _wcsdup(dir); /* allocate */
|
|
|
|
wcscpy(buf,dir);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdiskfree (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Get information about the free space on a drive.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* disk [I] Drive number to get information about (1 = 'A', 2 = 'B', ...)
|
|
|
|
* info [O] Destination for the resulting information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. info is updated with the free space information.
|
|
|
|
* Failure: An error code from GetLastError().
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See GetLastError().
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
unsigned int CDECL _getdiskfree(unsigned int disk, struct _diskfree_t * d)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2020-11-27 13:16:53 +00:00
|
|
|
WCHAR drivespec[] = L"@:\\";
|
2001-01-10 23:59:25 +00:00
|
|
|
DWORD ret[4];
|
|
|
|
unsigned int err;
|
|
|
|
|
|
|
|
if (disk > 26)
|
|
|
|
return ERROR_INVALID_PARAMETER; /* MSVCRT doesn't set errno here */
|
|
|
|
|
|
|
|
drivespec[0] += disk; /* make a drive letter */
|
|
|
|
|
2004-02-09 20:45:59 +00:00
|
|
|
if (GetDiskFreeSpaceW(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2008-01-12 16:05:11 +00:00
|
|
|
d->sectors_per_cluster = ret[0];
|
|
|
|
d->bytes_per_sector = ret[1];
|
|
|
|
d->avail_clusters = ret[2];
|
|
|
|
d->total_clusters = ret[3];
|
2001-01-10 23:59:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
err = GetLastError();
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(err);
|
2001-01-10 23:59:25 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mkdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Create a directory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* newdir [I] Name of directory to create.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. The directory indicated by newdir is created.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See CreateDirectoryA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _mkdir(const char * newdir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (CreateDirectoryA(newdir,NULL))
|
|
|
|
return 0;
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wmkdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _mkdir.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wmkdir(const wchar_t* newdir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (CreateDirectoryW(newdir,NULL))
|
|
|
|
return 0;
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _rmdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Delete a directory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* dir [I] Name of directory to delete.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: 0. The directory indicated by newdir is deleted.
|
|
|
|
* Failure: -1. errno indicates the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See RemoveDirectoryA.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _rmdir(const char * dir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (RemoveDirectoryA(dir))
|
|
|
|
return 0;
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wrmdir (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _rmdir.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wrmdir(const wchar_t * dir)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
if (RemoveDirectoryW(dir))
|
|
|
|
return 0;
|
2004-06-25 01:19:15 +00:00
|
|
|
msvcrt_set_errno(GetLastError());
|
2001-01-10 23:59:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-29 14:59:35 +00:00
|
|
|
/******************************************************************
|
|
|
|
* _splitpath_s (MSVCRT.@)
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _splitpath_s(const char* inpath,
|
2020-11-27 13:17:05 +00:00
|
|
|
char* drive, size_t sz_drive,
|
|
|
|
char* dir, size_t sz_dir,
|
|
|
|
char* fname, size_t sz_fname,
|
|
|
|
char* ext, size_t sz_ext)
|
2010-08-29 14:59:35 +00:00
|
|
|
{
|
|
|
|
const char *p, *end;
|
|
|
|
|
|
|
|
if (!inpath || (!drive && sz_drive) ||
|
|
|
|
(drive && !sz_drive) ||
|
|
|
|
(!dir && sz_dir) ||
|
|
|
|
(dir && !sz_dir) ||
|
|
|
|
(!fname && sz_fname) ||
|
|
|
|
(fname && !sz_fname) ||
|
|
|
|
(!ext && sz_ext) ||
|
|
|
|
(ext && !sz_ext))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EINVAL;
|
2020-11-30 13:37:27 +00:00
|
|
|
return EINVAL;
|
2010-08-29 14:59:35 +00:00
|
|
|
}
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2003-10-15 02:34:51 +00:00
|
|
|
if (inpath[0] && inpath[1] == ':')
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2010-08-29 14:59:35 +00:00
|
|
|
if (drive)
|
2003-10-15 02:34:51 +00:00
|
|
|
{
|
2010-08-29 14:59:35 +00:00
|
|
|
if (sz_drive <= 2) goto do_error;
|
|
|
|
drive[0] = inpath[0];
|
|
|
|
drive[1] = inpath[1];
|
|
|
|
drive[2] = 0;
|
2003-10-15 02:34:51 +00:00
|
|
|
}
|
|
|
|
inpath += 2;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2010-08-29 14:59:35 +00:00
|
|
|
else if (drive) drive[0] = '\0';
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2003-10-15 02:34:51 +00:00
|
|
|
/* look for end of directory part */
|
|
|
|
end = NULL;
|
2014-04-13 15:08:33 +00:00
|
|
|
for (p = inpath; *p; p++)
|
|
|
|
{
|
|
|
|
if (_ismbblead((unsigned char)*p))
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*p == '/' || *p == '\\') end = p + 1;
|
|
|
|
}
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2003-10-15 02:34:51 +00:00
|
|
|
if (end) /* got a directory */
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2003-10-15 02:34:51 +00:00
|
|
|
if (dir)
|
|
|
|
{
|
2010-08-29 14:59:35 +00:00
|
|
|
if (sz_dir <= end - inpath) goto do_error;
|
|
|
|
memcpy( dir, inpath, (end - inpath) );
|
2003-10-15 02:34:51 +00:00
|
|
|
dir[end - inpath] = 0;
|
|
|
|
}
|
|
|
|
inpath = end;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2003-10-15 02:34:51 +00:00
|
|
|
else if (dir) dir[0] = 0;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2003-10-21 23:51:06 +00:00
|
|
|
/* look for extension: what's after the last dot */
|
|
|
|
end = NULL;
|
|
|
|
for (p = inpath; *p; p++) if (*p == '.') end = p;
|
|
|
|
|
|
|
|
if (!end) end = p; /* there's no extension */
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2003-10-15 02:34:51 +00:00
|
|
|
if (fname)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2010-08-29 14:59:35 +00:00
|
|
|
if (sz_fname <= end - inpath) goto do_error;
|
|
|
|
memcpy( fname, inpath, (end - inpath) );
|
2003-10-15 02:34:51 +00:00
|
|
|
fname[end - inpath] = 0;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2010-08-29 14:59:35 +00:00
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
if (sz_ext <= strlen(end)) goto do_error;
|
|
|
|
strcpy( ext, end );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
do_error:
|
|
|
|
if (drive) drive[0] = '\0';
|
|
|
|
if (dir) dir[0] = '\0';
|
|
|
|
if (fname) fname[0]= '\0';
|
|
|
|
if (ext) ext[0]= '\0';
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ERANGE;
|
2010-08-29 14:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _splitpath (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
void CDECL _splitpath(const char *inpath, char *drv, char *dir,
|
2010-08-29 14:59:35 +00:00
|
|
|
char *fname, char *ext)
|
|
|
|
{
|
2020-12-03 18:11:02 +00:00
|
|
|
_splitpath_s(inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
|
2020-11-27 13:17:01 +00:00
|
|
|
fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2008-10-04 11:37:55 +00:00
|
|
|
/******************************************************************
|
|
|
|
* _wsplitpath_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Secure version of _wsplitpath
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wsplitpath_s(const wchar_t* inpath,
|
2020-11-27 13:17:05 +00:00
|
|
|
wchar_t* drive, size_t sz_drive,
|
|
|
|
wchar_t* dir, size_t sz_dir,
|
|
|
|
wchar_t* fname, size_t sz_fname,
|
|
|
|
wchar_t* ext, size_t sz_ext)
|
2008-10-04 11:37:55 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
const wchar_t *p, *end;
|
2008-10-04 11:37:55 +00:00
|
|
|
|
2010-08-29 14:59:35 +00:00
|
|
|
if (!inpath || (!drive && sz_drive) ||
|
|
|
|
(drive && !sz_drive) ||
|
|
|
|
(!dir && sz_dir) ||
|
|
|
|
(dir && !sz_dir) ||
|
|
|
|
(!fname && sz_fname) ||
|
|
|
|
(fname && !sz_fname) ||
|
|
|
|
(!ext && sz_ext) ||
|
|
|
|
(ext && !sz_ext))
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EINVAL;
|
2020-11-30 13:37:27 +00:00
|
|
|
return EINVAL;
|
2010-08-29 14:59:35 +00:00
|
|
|
}
|
2008-10-04 11:37:55 +00:00
|
|
|
|
|
|
|
if (inpath[0] && inpath[1] == ':')
|
|
|
|
{
|
|
|
|
if (drive)
|
|
|
|
{
|
|
|
|
if (sz_drive <= 2) goto do_error;
|
|
|
|
drive[0] = inpath[0];
|
|
|
|
drive[1] = inpath[1];
|
|
|
|
drive[2] = 0;
|
|
|
|
}
|
|
|
|
inpath += 2;
|
|
|
|
}
|
|
|
|
else if (drive) drive[0] = '\0';
|
|
|
|
|
|
|
|
/* look for end of directory part */
|
|
|
|
end = NULL;
|
|
|
|
for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
|
|
|
|
|
|
|
|
if (end) /* got a directory */
|
|
|
|
{
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
if (sz_dir <= end - inpath) goto do_error;
|
2020-11-27 13:16:49 +00:00
|
|
|
memcpy( dir, inpath, (end - inpath) * sizeof(wchar_t) );
|
2008-10-04 11:37:55 +00:00
|
|
|
dir[end - inpath] = 0;
|
|
|
|
}
|
|
|
|
inpath = end;
|
|
|
|
}
|
|
|
|
else if (dir) dir[0] = 0;
|
|
|
|
|
|
|
|
/* look for extension: what's after the last dot */
|
|
|
|
end = NULL;
|
|
|
|
for (p = inpath; *p; p++) if (*p == '.') end = p;
|
|
|
|
|
|
|
|
if (!end) end = p; /* there's no extension */
|
|
|
|
|
|
|
|
if (fname)
|
|
|
|
{
|
|
|
|
if (sz_fname <= end - inpath) goto do_error;
|
2020-11-27 13:16:49 +00:00
|
|
|
memcpy( fname, inpath, (end - inpath) * sizeof(wchar_t) );
|
2008-10-04 11:37:55 +00:00
|
|
|
fname[end - inpath] = 0;
|
|
|
|
}
|
|
|
|
if (ext)
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
if (sz_ext <= wcslen(end)) goto do_error;
|
|
|
|
wcscpy( ext, end );
|
2008-10-04 11:37:55 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
do_error:
|
|
|
|
if (drive) drive[0] = '\0';
|
|
|
|
if (dir) dir[0] = '\0';
|
|
|
|
if (fname) fname[0]= '\0';
|
|
|
|
if (ext) ext[0]= '\0';
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ERANGE;
|
2008-10-04 11:37:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 14:59:35 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wsplitpath (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Unicode version of _splitpath.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
void CDECL _wsplitpath(const wchar_t *inpath, wchar_t *drv, wchar_t *dir,
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t *fname, wchar_t *ext)
|
2010-08-29 14:59:35 +00:00
|
|
|
{
|
2020-12-03 18:11:02 +00:00
|
|
|
_wsplitpath_s(inpath, drv, drv ? _MAX_DRIVE : 0, dir, dir ? _MAX_DIR : 0,
|
2020-11-27 13:17:01 +00:00
|
|
|
fname, fname ? _MAX_FNAME : 0, ext, ext ? _MAX_EXT : 0);
|
2010-08-29 14:59:35 +00:00
|
|
|
}
|
|
|
|
|
2003-05-12 03:31:16 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wfullpath (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _fullpath.
|
2003-05-12 03:31:16 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
wchar_t * CDECL _wfullpath(wchar_t * absPath, const wchar_t* relPath, size_t size)
|
2003-05-12 03:31:16 +00:00
|
|
|
{
|
2006-01-06 20:45:26 +00:00
|
|
|
DWORD rc;
|
|
|
|
WCHAR* buffer;
|
|
|
|
WCHAR* lastpart;
|
|
|
|
BOOL alloced = FALSE;
|
2003-05-12 03:31:16 +00:00
|
|
|
|
|
|
|
if (!relPath || !*relPath)
|
2020-12-03 18:11:02 +00:00
|
|
|
return _wgetcwd(absPath, size);
|
2003-05-12 03:31:16 +00:00
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
if (absPath == NULL)
|
|
|
|
{
|
2020-12-01 12:51:32 +00:00
|
|
|
buffer = malloc(MAX_PATH * sizeof(WCHAR));
|
2006-01-06 20:45:26 +00:00
|
|
|
size = MAX_PATH;
|
|
|
|
alloced = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
buffer = absPath;
|
|
|
|
|
2003-05-12 03:31:16 +00:00
|
|
|
if (size < 4)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2003-05-12 03:31:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-01-18 10:40:15 +00:00
|
|
|
TRACE(":resolving relative path %s\n",debugstr_w(relPath));
|
2003-05-12 03:31:16 +00:00
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
rc = GetFullPathNameW(relPath,size,buffer,&lastpart);
|
2003-05-12 03:31:16 +00:00
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
if (rc > 0 && rc <= size )
|
|
|
|
return buffer;
|
2001-01-10 23:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
2006-01-06 20:45:26 +00:00
|
|
|
if (alloced)
|
2020-12-01 12:51:32 +00:00
|
|
|
free(buffer);
|
2006-01-06 20:45:26 +00:00
|
|
|
return NULL;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fullpath (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Create an absolute path from a relative path.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* absPath [O] Destination for absolute path
|
|
|
|
* relPath [I] Relative path to convert to absolute
|
|
|
|
* size [I] Length of absPath in characters.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: If absPath is NULL, returns an allocated string containing the path.
|
|
|
|
* Otherwise populates absPath with the path and returns it.
|
|
|
|
* Failure: NULL. errno indicates the error.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
char * CDECL _fullpath(char * absPath, const char* relPath, size_t size)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2006-01-06 20:45:26 +00:00
|
|
|
DWORD rc;
|
|
|
|
char* lastpart;
|
|
|
|
char* buffer;
|
|
|
|
BOOL alloced = FALSE;
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
if (!relPath || !*relPath)
|
2020-12-03 18:11:02 +00:00
|
|
|
return _getcwd(absPath, size);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
if (absPath == NULL)
|
|
|
|
{
|
2020-12-01 12:51:32 +00:00
|
|
|
buffer = malloc(MAX_PATH);
|
2006-01-06 20:45:26 +00:00
|
|
|
size = MAX_PATH;
|
|
|
|
alloced = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
buffer = absPath;
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
if (size < 4)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2001-01-10 23:59:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(":resolving relative path '%s'\n",relPath);
|
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
rc = GetFullPathNameA(relPath,size,buffer,&lastpart);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2006-01-06 20:45:26 +00:00
|
|
|
if (rc > 0 && rc <= size)
|
|
|
|
return buffer;
|
2001-01-10 23:59:25 +00:00
|
|
|
else
|
|
|
|
{
|
2006-01-06 20:45:26 +00:00
|
|
|
if (alloced)
|
2020-12-01 12:51:32 +00:00
|
|
|
free(buffer);
|
2006-01-06 20:45:26 +00:00
|
|
|
return NULL;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _makepath (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Create a pathname.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* path [O] Destination for created pathname
|
|
|
|
* drive [I] Drive letter (e.g. "A:")
|
|
|
|
* directory [I] Directory
|
|
|
|
* filename [I] Name of the file, excluding extension
|
|
|
|
* extension [I] File extension (e.g. ".TXT")
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing. If path is not large enough to hold the resulting pathname,
|
|
|
|
* random process memory will be overwritten.
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
VOID CDECL _makepath(char * path, const char * drive,
|
2006-06-13 09:21:19 +00:00
|
|
|
const char *directory, const char * filename,
|
|
|
|
const char * extension)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2007-08-06 13:38:49 +00:00
|
|
|
char *p = path;
|
2006-01-17 15:20:37 +00:00
|
|
|
|
|
|
|
TRACE("(%s %s %s %s)\n", debugstr_a(drive), debugstr_a(directory),
|
2003-02-19 03:43:08 +00:00
|
|
|
debugstr_a(filename), debugstr_a(extension) );
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
2007-08-06 13:38:49 +00:00
|
|
|
*p++ = drive[0];
|
|
|
|
*p++ = ':';
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
2008-07-03 19:30:18 +00:00
|
|
|
unsigned int len = strlen(directory);
|
|
|
|
memmove(p, directory, len);
|
|
|
|
p += len;
|
|
|
|
if (p[-1] != '/' && p[-1] != '\\')
|
|
|
|
*p++ = '\\';
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
2008-07-03 19:30:18 +00:00
|
|
|
unsigned int len = strlen(filename);
|
|
|
|
memmove(p, filename, len);
|
|
|
|
p += len;
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2008-07-03 19:30:18 +00:00
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
|
|
|
if (extension[0] != '.')
|
|
|
|
*p++ = '.';
|
|
|
|
strcpy(p, extension);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*p = '\0';
|
2001-04-10 23:25:25 +00:00
|
|
|
TRACE("returning %s\n",path);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2002-01-29 18:00:44 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wmakepath (MSVCRT.@)
|
2004-02-09 20:45:59 +00:00
|
|
|
*
|
|
|
|
* Unicode version of _wmakepath.
|
2002-01-29 18:00:44 +00:00
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
VOID CDECL _wmakepath(wchar_t *path, const wchar_t *drive, const wchar_t *directory,
|
2020-11-27 13:16:49 +00:00
|
|
|
const wchar_t *filename, const wchar_t *extension)
|
2002-01-29 18:00:44 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t *p = path;
|
2008-07-03 19:30:18 +00:00
|
|
|
|
2002-01-29 18:00:44 +00:00
|
|
|
TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory),
|
2004-02-09 20:45:59 +00:00
|
|
|
debugstr_w(filename), debugstr_w(extension));
|
2002-01-29 18:00:44 +00:00
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
2008-07-03 19:30:18 +00:00
|
|
|
*p++ = drive[0];
|
|
|
|
*p++ = ':';
|
2002-01-29 18:00:44 +00:00
|
|
|
}
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
unsigned int len = wcslen(directory);
|
2020-11-27 13:16:49 +00:00
|
|
|
memmove(p, directory, len * sizeof(wchar_t));
|
2008-07-03 19:30:18 +00:00
|
|
|
p += len;
|
|
|
|
if (p[-1] != '/' && p[-1] != '\\')
|
|
|
|
*p++ = '\\';
|
2002-01-29 18:00:44 +00:00
|
|
|
}
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
unsigned int len = wcslen(filename);
|
2020-11-27 13:16:49 +00:00
|
|
|
memmove(p, filename, len * sizeof(wchar_t));
|
2008-07-03 19:30:18 +00:00
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
|
|
|
if (extension[0] != '.')
|
|
|
|
*p++ = '.';
|
2020-12-03 18:10:54 +00:00
|
|
|
wcscpy(p, extension);
|
2002-01-29 18:00:44 +00:00
|
|
|
}
|
2008-07-03 19:30:18 +00:00
|
|
|
else
|
|
|
|
*p = '\0';
|
2002-01-29 18:00:44 +00:00
|
|
|
|
|
|
|
TRACE("returning %s\n", debugstr_w(path));
|
|
|
|
}
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2010-06-25 08:53:41 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _makepath_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Safe version of _makepath.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _makepath_s(char *path, size_t size, const char *drive,
|
2010-06-25 08:53:41 +00:00
|
|
|
const char *directory, const char *filename,
|
|
|
|
const char *extension)
|
|
|
|
{
|
|
|
|
char *p = path;
|
|
|
|
|
|
|
|
if (!path || !size)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EINVAL;
|
2020-11-30 13:37:27 +00:00
|
|
|
return EINVAL;
|
2010-06-25 08:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
|
|
|
if (size <= 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
*p++ = drive[0];
|
|
|
|
*p++ = ':';
|
|
|
|
size -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
|
|
|
unsigned int len = strlen(directory);
|
|
|
|
unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
|
|
|
|
unsigned int copylen = min(size - 1, len);
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
memmove(p, directory, copylen);
|
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += copylen;
|
|
|
|
size -= copylen;
|
|
|
|
|
|
|
|
if (needs_separator)
|
|
|
|
{
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
*p++ = '\\';
|
|
|
|
size -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
|
|
|
unsigned int len = strlen(filename);
|
|
|
|
unsigned int copylen = min(size - 1, len);
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
memmove(p, filename, copylen);
|
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += len;
|
|
|
|
size -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
|
|
|
unsigned int len = strlen(extension);
|
|
|
|
unsigned int needs_period = extension[0] != '.';
|
|
|
|
unsigned int copylen;
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
if (needs_period)
|
|
|
|
{
|
|
|
|
*p++ = '.';
|
|
|
|
size -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
copylen = min(size - 1, len);
|
|
|
|
memcpy(p, extension, copylen);
|
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += copylen;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
range:
|
|
|
|
path[0] = '\0';
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ERANGE;
|
2010-06-25 08:53:41 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 08:53:54 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wmakepath_s (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Safe version of _wmakepath.
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wmakepath_s(wchar_t *path, size_t size, const wchar_t *drive,
|
2020-11-27 13:16:49 +00:00
|
|
|
const wchar_t *directory, const wchar_t *filename,
|
|
|
|
const wchar_t *extension)
|
2010-06-25 08:53:54 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t *p = path;
|
2010-06-25 08:53:54 +00:00
|
|
|
|
|
|
|
if (!path || !size)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = EINVAL;
|
2020-11-30 13:37:27 +00:00
|
|
|
return EINVAL;
|
2010-06-25 08:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
|
|
|
if (size <= 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
*p++ = drive[0];
|
|
|
|
*p++ = ':';
|
|
|
|
size -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
unsigned int len = wcslen(directory);
|
2010-06-25 08:53:54 +00:00
|
|
|
unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
|
|
|
|
unsigned int copylen = min(size - 1, len);
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
2020-11-27 13:16:49 +00:00
|
|
|
memmove(p, directory, copylen * sizeof(wchar_t));
|
2010-06-25 08:53:54 +00:00
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += copylen;
|
|
|
|
size -= copylen;
|
|
|
|
|
|
|
|
if (needs_separator)
|
|
|
|
{
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
*p++ = '\\';
|
|
|
|
size -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
unsigned int len = wcslen(filename);
|
2010-06-25 08:53:54 +00:00
|
|
|
unsigned int copylen = min(size - 1, len);
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
2020-11-27 13:16:49 +00:00
|
|
|
memmove(p, filename, copylen * sizeof(wchar_t));
|
2010-06-25 08:53:54 +00:00
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += len;
|
|
|
|
size -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
2020-12-03 18:10:54 +00:00
|
|
|
unsigned int len = wcslen(extension);
|
2010-06-25 08:53:54 +00:00
|
|
|
unsigned int needs_period = extension[0] != '.';
|
|
|
|
unsigned int copylen;
|
|
|
|
|
|
|
|
if (size < 2)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
if (needs_period)
|
|
|
|
{
|
|
|
|
*p++ = '.';
|
|
|
|
size -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
copylen = min(size - 1, len);
|
2020-11-27 13:16:49 +00:00
|
|
|
memcpy(p, extension, copylen * sizeof(wchar_t));
|
2010-06-25 08:53:54 +00:00
|
|
|
|
|
|
|
if (size <= len)
|
|
|
|
goto range;
|
|
|
|
|
|
|
|
p += copylen;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
range:
|
|
|
|
path[0] = '\0';
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ERANGE;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ERANGE;
|
2010-06-25 08:53:54 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 21:03:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _searchenv_s (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _searchenv_s(const char* file, const char* env, char *buf, size_t count)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2018-02-19 14:32:29 +00:00
|
|
|
char *envVal, *penv, *end;
|
|
|
|
char path[MAX_PATH];
|
2020-11-27 13:17:05 +00:00
|
|
|
size_t path_len, fname_len;
|
2010-11-02 21:03:17 +00:00
|
|
|
|
2020-11-30 13:37:27 +00:00
|
|
|
if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(buf != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(count > 0)) return EINVAL;
|
2010-11-02 21:03:17 +00:00
|
|
|
|
2018-02-19 14:32:29 +00:00
|
|
|
if (count > MAX_PATH)
|
|
|
|
FIXME("count > MAX_PATH not supported\n");
|
|
|
|
|
|
|
|
fname_len = strlen(file);
|
2010-11-02 21:03:17 +00:00
|
|
|
*buf = '\0';
|
|
|
|
|
|
|
|
/* Try CWD first */
|
|
|
|
if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
if (GetFullPathNameA( file, count, buf, NULL )) return 0;
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search given environment variable */
|
2020-12-01 23:53:33 +00:00
|
|
|
envVal = getenv(env);
|
2010-11-02 21:03:17 +00:00
|
|
|
if (!envVal)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ENOENT;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
penv = envVal;
|
|
|
|
TRACE(":searching for %s in paths %s\n", file, envVal);
|
|
|
|
|
2018-02-19 14:32:29 +00:00
|
|
|
for(; *penv; penv = (*end ? end + 1 : end))
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2018-02-19 14:32:29 +00:00
|
|
|
end = penv;
|
2020-01-29 12:42:11 +00:00
|
|
|
path_len = 0;
|
|
|
|
while(*end && *end != ';' && path_len < MAX_PATH)
|
|
|
|
{
|
|
|
|
if (*end == '"')
|
|
|
|
{
|
|
|
|
end++;
|
|
|
|
while(*end && *end != '"' && path_len < MAX_PATH)
|
|
|
|
{
|
|
|
|
path[path_len++] = *end;
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
if (*end == '"') end++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
path[path_len++] = *end;
|
|
|
|
end++;
|
|
|
|
}
|
2018-02-19 14:32:29 +00:00
|
|
|
if (!path_len || path_len >= MAX_PATH)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (path[path_len - 1] != '/' && path[path_len - 1] != '\\')
|
|
|
|
path[path_len++] = '\\';
|
|
|
|
if (path_len + fname_len >= MAX_PATH)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memcpy(path + path_len, file, fname_len + 1);
|
|
|
|
TRACE("Checking for file %s\n", path);
|
|
|
|
if (GetFileAttributesA( path ) != INVALID_FILE_ATTRIBUTES)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2018-02-19 14:32:29 +00:00
|
|
|
if (path_len + fname_len + 1 > count)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2020-11-30 13:37:27 +00:00
|
|
|
MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE);
|
|
|
|
return ERANGE;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
2018-02-19 14:32:29 +00:00
|
|
|
memcpy(buf, path, path_len + fname_len + 1);
|
2010-11-02 21:03:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-19 14:32:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ENOENT;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 12:42:15 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _searchenv (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
void CDECL _searchenv(const char* file, const char* env, char *buf)
|
2020-01-29 12:42:15 +00:00
|
|
|
{
|
2020-12-03 18:11:02 +00:00
|
|
|
_searchenv_s(file, env, buf, MAX_PATH);
|
2020-01-29 12:42:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 21:03:17 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _wsearchenv_s (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
int CDECL _wsearchenv_s(const wchar_t* file, const wchar_t* env,
|
2020-11-27 13:17:05 +00:00
|
|
|
wchar_t *buf, size_t count)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2020-11-27 13:16:49 +00:00
|
|
|
wchar_t *envVal, *penv, *end;
|
|
|
|
wchar_t path[MAX_PATH];
|
2020-11-27 13:17:05 +00:00
|
|
|
size_t path_len, fname_len;
|
2010-11-02 21:03:17 +00:00
|
|
|
|
2020-11-30 13:37:27 +00:00
|
|
|
if (!MSVCRT_CHECK_PMT(file != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(buf != NULL)) return EINVAL;
|
|
|
|
if (!MSVCRT_CHECK_PMT(count > 0)) return EINVAL;
|
2012-07-26 09:05:32 +00:00
|
|
|
|
2018-02-19 14:32:29 +00:00
|
|
|
if (count > MAX_PATH)
|
|
|
|
FIXME("count > MAX_PATH not supported\n");
|
|
|
|
|
2020-12-03 18:10:54 +00:00
|
|
|
fname_len = wcslen(file);
|
2010-11-02 21:03:17 +00:00
|
|
|
*buf = '\0';
|
|
|
|
|
|
|
|
/* Try CWD first */
|
|
|
|
if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
if (GetFullPathNameW( file, count, buf, NULL )) return 0;
|
|
|
|
msvcrt_set_errno(GetLastError());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search given environment variable */
|
2020-12-01 23:53:33 +00:00
|
|
|
envVal = _wgetenv(env);
|
2010-11-02 21:03:17 +00:00
|
|
|
if (!envVal)
|
|
|
|
{
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ENOENT;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
penv = envVal;
|
|
|
|
TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal));
|
|
|
|
|
2018-02-19 14:32:29 +00:00
|
|
|
for(; *penv; penv = (*end ? end + 1 : end))
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2018-02-19 14:32:29 +00:00
|
|
|
end = penv;
|
2020-01-29 12:42:19 +00:00
|
|
|
path_len = 0;
|
|
|
|
while(*end && *end != ';' && path_len < MAX_PATH)
|
|
|
|
{
|
|
|
|
if (*end == '"')
|
|
|
|
{
|
|
|
|
end++;
|
|
|
|
while(*end && *end != '"' && path_len < MAX_PATH)
|
|
|
|
{
|
|
|
|
path[path_len++] = *end;
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
if (*end == '"') end++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
path[path_len++] = *end;
|
|
|
|
end++;
|
|
|
|
}
|
2018-02-19 14:32:29 +00:00
|
|
|
if (!path_len || path_len >= MAX_PATH)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (path[path_len - 1] != '/' && path[path_len - 1] != '\\')
|
|
|
|
path[path_len++] = '\\';
|
|
|
|
if (path_len + fname_len >= MAX_PATH)
|
|
|
|
continue;
|
|
|
|
|
2020-11-27 13:16:49 +00:00
|
|
|
memcpy(path + path_len, file, (fname_len + 1) * sizeof(wchar_t));
|
2018-02-19 14:32:29 +00:00
|
|
|
TRACE("Checking for file %s\n", debugstr_w(path));
|
|
|
|
if (GetFileAttributesW( path ) != INVALID_FILE_ATTRIBUTES)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2018-02-19 14:32:29 +00:00
|
|
|
if (path_len + fname_len + 1 > count)
|
2010-11-02 21:03:17 +00:00
|
|
|
{
|
2020-11-30 13:37:27 +00:00
|
|
|
MSVCRT_INVALID_PMT("buf[count] is too small", ERANGE);
|
|
|
|
return ERANGE;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
2020-11-27 13:16:49 +00:00
|
|
|
memcpy(buf, path, (path_len + fname_len + 1) * sizeof(wchar_t));
|
2010-11-02 21:03:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-19 14:32:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 12:51:23 +00:00
|
|
|
*_errno() = ENOENT;
|
2020-11-30 13:37:27 +00:00
|
|
|
return ENOENT;
|
2010-11-02 21:03:17 +00:00
|
|
|
}
|
2020-01-29 12:42:23 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wsearchenv (MSVCRT.@)
|
|
|
|
*/
|
2020-12-03 18:11:02 +00:00
|
|
|
void CDECL _wsearchenv(const wchar_t* file, const wchar_t* env, wchar_t *buf)
|
2020-01-29 12:42:23 +00:00
|
|
|
{
|
2020-12-03 18:11:02 +00:00
|
|
|
_wsearchenv_s(file, env, buf, MAX_PATH);
|
2020-01-29 12:42:23 +00:00
|
|
|
}
|