2001-01-11 00:59:25 +01: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-10 00:29:33 +01: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
|
|
|
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-11 00:59:25 +01:00
|
|
|
#include <time.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "msvcrt.h"
|
2002-09-17 20:32:53 +02:00
|
|
|
#include "msvcrt/errno.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "msvcrt/direct.h"
|
|
|
|
#include "msvcrt/dos.h"
|
|
|
|
#include "msvcrt/io.h"
|
|
|
|
#include "msvcrt/stdlib.h"
|
|
|
|
#include "msvcrt/string.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* INTERNAL: Translate finddata_t to PWIN32_FIND_DATAA */
|
2001-04-11 01:25:25 +02:00
|
|
|
static void msvcrt_fttofd(LPWIN32_FIND_DATAA fd, struct _finddata_t* ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_create = dw;
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_access = dw;
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
|
|
|
strcpy(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: Translate wfinddata_t to PWIN32_FIND_DATAA */
|
2001-04-11 01:25:25 +02:00
|
|
|
static void msvcrt_wfttofd(LPWIN32_FIND_DATAW fd, struct _wfinddata_t* ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
|
|
|
|
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
|
|
|
|
ft->attrib = 0;
|
|
|
|
else
|
|
|
|
ft->attrib = fd->dwFileAttributes;
|
|
|
|
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftCreationTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_create = dw;
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_access = dw;
|
2002-09-13 00:28:01 +02:00
|
|
|
RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
|
2001-01-11 00:59:25 +01:00
|
|
|
ft->time_write = dw;
|
|
|
|
ft->size = fd->nFileSizeLow;
|
|
|
|
strcpyW(ft->name, fd->cFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _chdir (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _chdir(const char * newdir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (!SetCurrentDirectoryA(newdir))
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(newdir?GetLastError():0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wchdir (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
int _wchdir(const MSVCRT_wchar_t * newdir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (!SetCurrentDirectoryW(newdir))
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(newdir?GetLastError():0);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _chdrive (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _chdrive(int newdrive)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char buffer[3] = "A:";
|
|
|
|
buffer[0] += newdrive - 1;
|
|
|
|
if (!SetCurrentDirectoryA( buffer ))
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
if (newdrive <= 0)
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EACCES;
|
2001-01-11 00:59:25 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _findclose (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
int _findclose(long hand)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE(":handle %ld\n",hand);
|
|
|
|
if (!FindClose((HANDLE)hand))
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _findfirst (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
long _findfirst(const char * fspec, struct _finddata_t* ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileA(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_fttofd(&find_data,ft);
|
2002-10-25 05:12:01 +02:00
|
|
|
TRACE(":got handle %p\n",hfind);
|
|
|
|
return (long)hfind;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wfindfirst (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
long _wfindfirst(const MSVCRT_wchar_t * fspec, struct _wfinddata_t* ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
HANDLE hfind;
|
|
|
|
|
|
|
|
hfind = FindFirstFileW(fspec, &find_data);
|
|
|
|
if (hfind == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_wfttofd(&find_data,ft);
|
2002-10-25 05:12:01 +02:00
|
|
|
TRACE(":got handle %p\n",hfind);
|
|
|
|
return (long)hfind;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _findnext (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
int _findnext(long hand, struct _finddata_t * ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAA find_data;
|
|
|
|
|
2002-10-25 05:12:01 +02:00
|
|
|
if (!FindNextFileA((HANDLE)hand, &find_data))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ENOENT;
|
2001-01-11 00:59:25 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_fttofd(&find_data,ft);
|
2001-01-11 00:59:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wfindnext (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
int _wfindnext(long hand, struct _wfinddata_t * ft)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW find_data;
|
|
|
|
|
2002-10-25 05:12:01 +02:00
|
|
|
if (!FindNextFileW((HANDLE)hand, &find_data))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ENOENT;
|
2001-01-11 00:59:25 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_wfttofd(&find_data,ft);
|
2001-01-11 00:59:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getcwd (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _getcwd(char * buf, int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-05-01 20:13:18 +02:00
|
|
|
char dir[MAX_PATH];
|
2001-01-11 00:59:25 +01:00
|
|
|
int dir_len = GetCurrentDirectoryA(MAX_PATH,dir);
|
|
|
|
|
|
|
|
if (dir_len < 1)
|
|
|
|
return NULL; /* FIXME: Real return value untested */
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
if (size < 0)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _strdup(dir);
|
|
|
|
return msvcrt_strndup(dir,size);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
if (dir_len >= size)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
strcpy(buf,dir);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wgetcwd (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* _wgetcwd(MSVCRT_wchar_t * buf, int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t dir[MAX_PATH];
|
2001-01-11 00:59:25 +01:00
|
|
|
int dir_len = GetCurrentDirectoryW(MAX_PATH,dir);
|
|
|
|
|
|
|
|
if (dir_len < 1)
|
|
|
|
return NULL; /* FIXME: Real return value untested */
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
if (size < 0)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _wcsdup(dir);
|
|
|
|
return msvcrt_wstrndup(dir,size);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
if (dir_len >= size)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
strcpyW(buf,dir);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdrive (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _getdrive(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
if (!GetCurrentDirectoryA( sizeof(buffer), buffer )) return 0;
|
|
|
|
if (buffer[1] != ':') return 0;
|
|
|
|
return toupper(buffer[0]) - 'A' + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdcwd (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char* _getdcwd(int drive, char * buf, int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
static char* dummy;
|
|
|
|
|
|
|
|
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
if (!drive || drive == _getdrive())
|
|
|
|
return _getcwd(buf,size); /* current */
|
2001-01-11 00:59:25 +01:00
|
|
|
else
|
|
|
|
{
|
2002-05-01 20:13:18 +02:00
|
|
|
char dir[MAX_PATH];
|
2001-01-11 00:59:25 +01:00
|
|
|
char drivespec[4] = {'A', ':', '\\', 0};
|
|
|
|
int dir_len;
|
|
|
|
|
|
|
|
drivespec[0] += drive - 1;
|
|
|
|
if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EACCES;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-01 20:13:18 +02:00
|
|
|
dir_len = GetFullPathNameA(drivespec,MAX_PATH,dir,&dummy);
|
2001-01-11 00:59:25 +01:00
|
|
|
if (dir_len >= size || dir_len < 1)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(":returning '%s'\n", dir);
|
|
|
|
if (!buf)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _strdup(dir); /* allocate */
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
strcpy(buf,dir);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wgetdcwd (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t* _wgetdcwd(int drive, MSVCRT_wchar_t * buf, int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
static MSVCRT_wchar_t* dummy;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
|
|
|
|
|
2001-04-10 23:16:07 +02:00
|
|
|
if (!drive || drive == _getdrive())
|
|
|
|
return _wgetcwd(buf,size); /* current */
|
2001-01-11 00:59:25 +01:00
|
|
|
else
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t dir[MAX_PATH];
|
|
|
|
MSVCRT_wchar_t drivespec[4] = {'A', ':', '\\', 0};
|
2001-01-11 00:59:25 +01:00
|
|
|
int dir_len;
|
|
|
|
|
|
|
|
drivespec[0] += drive - 1;
|
|
|
|
if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_EACCES;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-05-01 20:13:18 +02:00
|
|
|
dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
|
2001-01-11 00:59:25 +01:00
|
|
|
if (dir_len >= size || dir_len < 1)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL; /* buf too small */
|
|
|
|
}
|
|
|
|
|
2001-05-11 22:03:40 +02:00
|
|
|
TRACE(":returning %s\n", debugstr_w(dir));
|
2001-01-11 00:59:25 +01:00
|
|
|
if (!buf)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _wcsdup(dir); /* allocate */
|
2001-01-11 00:59:25 +01:00
|
|
|
strcpyW(buf,dir);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getdiskfree (MSVCRT.@)
|
|
|
|
*/
|
2001-04-11 01:25:25 +02:00
|
|
|
unsigned int _getdiskfree(unsigned int disk, struct _diskfree_t* d)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char drivespec[4] = {'@', ':', '\\', 0};
|
|
|
|
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 */
|
|
|
|
|
|
|
|
if (GetDiskFreeSpaceA(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
|
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
d->sectors_per_cluster = (unsigned)ret[0];
|
|
|
|
d->bytes_per_sector = (unsigned)ret[1];
|
|
|
|
d->avail_clusters = (unsigned)ret[2];
|
|
|
|
d->total_clusters = (unsigned)ret[3];
|
2001-01-11 00:59:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
err = GetLastError();
|
|
|
|
MSVCRT__set_errno(err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _mkdir (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _mkdir(const char * newdir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (CreateDirectoryA(newdir,NULL))
|
|
|
|
return 0;
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wmkdir (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
int _wmkdir(const MSVCRT_wchar_t* newdir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (CreateDirectoryW(newdir,NULL))
|
|
|
|
return 0;
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _rmdir (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
int _rmdir(const char * dir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (RemoveDirectoryA(dir))
|
|
|
|
return 0;
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wrmdir (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
int _wrmdir(const MSVCRT_wchar_t * dir)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (RemoveDirectoryW(dir))
|
|
|
|
return 0;
|
|
|
|
MSVCRT__set_errno(GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-22 03:21:54 +01:00
|
|
|
* _wsplitpath (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
void _wsplitpath(const MSVCRT_wchar_t *inpath, MSVCRT_wchar_t *drv, MSVCRT_wchar_t *dir,
|
|
|
|
MSVCRT_wchar_t *fname, MSVCRT_wchar_t *ext )
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Modified PD code from 'snippets' collection. */
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t ch, *ptr, *p;
|
|
|
|
MSVCRT_wchar_t pathbuff[MAX_PATH],*path=pathbuff;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
/* FIXME: Should be an strncpyW or something */
|
|
|
|
strcpyW(pathbuff, inpath);
|
2003-03-27 19:35:12 +01:00
|
|
|
TRACE(":splitting path %s\n",debugstr_w(path));
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* convert slashes to backslashes for searching */
|
2002-12-19 05:21:30 +01:00
|
|
|
for (ptr = (MSVCRT_wchar_t*)path; *ptr; ++ptr)
|
|
|
|
if (*ptr == '/')
|
|
|
|
*ptr = '\\';
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* look for drive spec */
|
2002-12-19 05:21:30 +01:00
|
|
|
if ((ptr = strchrW(path, ':')) != 0)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
++ptr;
|
|
|
|
if (drv)
|
|
|
|
{
|
2001-04-11 01:25:25 +02:00
|
|
|
strncpyW(drv, path, ptr - path);
|
2002-12-19 05:21:30 +01:00
|
|
|
drv[ptr - path] = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
path = ptr;
|
|
|
|
}
|
|
|
|
else if (drv)
|
2002-12-19 05:21:30 +01:00
|
|
|
*drv = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* find rightmost backslash or leftmost colon */
|
2002-12-19 05:21:30 +01:00
|
|
|
if ((ptr = strrchrW(path, '\\')) == NULL)
|
|
|
|
ptr = (strchrW(path, ':'));
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
ptr = (MSVCRT_wchar_t *)path; /* no path */
|
2001-01-11 00:59:25 +01:00
|
|
|
if (dir)
|
2002-12-19 05:21:30 +01:00
|
|
|
*dir = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++ptr; /* skip the delimiter */
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
ch = *ptr;
|
2002-12-19 05:21:30 +01:00
|
|
|
*ptr = 0;
|
2001-04-11 01:25:25 +02:00
|
|
|
strcpyW(dir, path);
|
2001-01-11 00:59:25 +01:00
|
|
|
*ptr = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-19 05:21:30 +01:00
|
|
|
if ((p = strrchrW(ptr, '.')) == NULL)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
if (fname)
|
2001-04-11 01:25:25 +02:00
|
|
|
strcpyW(fname, ptr);
|
2001-01-11 00:59:25 +01:00
|
|
|
if (ext)
|
2002-12-19 05:21:30 +01:00
|
|
|
*ext = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
*p = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
if (fname)
|
2001-04-11 01:25:25 +02:00
|
|
|
strcpyW(fname, ptr);
|
2002-12-19 05:21:30 +01:00
|
|
|
*p = '.';
|
2001-01-11 00:59:25 +01:00
|
|
|
if (ext)
|
2001-04-11 01:25:25 +02:00
|
|
|
strcpyW(ext, p);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix pathological case - Win returns ':' as part of the
|
|
|
|
* directory when no drive letter is given.
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
if (drv && drv[0] == ':')
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
*drv = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
if (dir)
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
pathbuff[0] = ':';
|
|
|
|
pathbuff[1] = 0;
|
2001-04-11 01:25:25 +02:00
|
|
|
strcatW(pathbuff,dir);
|
|
|
|
strcpyW(dir, pathbuff);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-12 05:31:16 +02:00
|
|
|
/* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
|
|
|
|
static void wmsvcrt_fln_fix(MSVCRT_wchar_t *path)
|
|
|
|
{
|
|
|
|
int dir_flag = 0, root_flag = 0;
|
|
|
|
MSVCRT_wchar_t *r, *p, *q, *s;
|
|
|
|
MSVCRT_wchar_t szbsdot[] = { '\\', '.', 0 };
|
|
|
|
|
|
|
|
/* Skip drive */
|
|
|
|
if (NULL == (r = strrchrW(path, ':')))
|
|
|
|
r = path;
|
|
|
|
else
|
|
|
|
++r;
|
|
|
|
|
|
|
|
/* Ignore leading slashes */
|
|
|
|
while ('\\' == *r)
|
|
|
|
if ('\\' == r[1])
|
|
|
|
strcpyW(r, &r[1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root_flag = 1;
|
|
|
|
++r;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = r; /* Change "\\" to "\" */
|
|
|
|
while (NULL != (p = strchrW(p, '\\')))
|
|
|
|
if ('\\' == p[1])
|
|
|
|
strcpyW(p, &p[1]);
|
|
|
|
else
|
|
|
|
++p;
|
|
|
|
|
|
|
|
while ('.' == *r) /* Scrunch leading ".\" */
|
|
|
|
{
|
|
|
|
if ('.' == r[1])
|
|
|
|
{
|
|
|
|
/* Ignore leading ".." */
|
|
|
|
for (p = (r += 2); *p && (*p != '\\'); ++p)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (p = r + 1 ;*p && (*p != '\\'); ++p)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
strcpyW(r, p + ((*p) ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
while ('\\' == path[strlenW(path)-1]) /* Strip last '\\' */
|
|
|
|
{
|
|
|
|
dir_flag = 1;
|
|
|
|
path[strlenW(path)-1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
s = r;
|
|
|
|
|
|
|
|
/* Look for "\." in path */
|
|
|
|
|
|
|
|
while (NULL != (p = strstrW(s, szbsdot)))
|
|
|
|
{
|
|
|
|
if ('.' == p[2])
|
|
|
|
{
|
|
|
|
/* Execute this section if ".." found */
|
|
|
|
q = p - 1;
|
|
|
|
while (q > r) /* Backup one level */
|
|
|
|
{
|
|
|
|
if (*q == '\\')
|
|
|
|
break;
|
|
|
|
--q;
|
|
|
|
}
|
|
|
|
if (q > r)
|
|
|
|
{
|
|
|
|
strcpyW(q, p + 3);
|
|
|
|
s = q;
|
|
|
|
}
|
|
|
|
else if ('.' != *q)
|
|
|
|
{
|
|
|
|
strcpyW(q + ((*q == '\\') ? 1 : 0),
|
|
|
|
p + 3 + ((*(p + 3)) ? 1 : 0));
|
|
|
|
s = q;
|
|
|
|
}
|
|
|
|
else s = ++p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Execute this section if "." found */
|
|
|
|
q = p + 2;
|
|
|
|
for ( ;*q && (*q != '\\'); ++q)
|
|
|
|
;
|
|
|
|
strcpyW (p, q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root_flag) /* Embedded ".." could have bubbled up to root */
|
|
|
|
{
|
|
|
|
for (p = r; *p && ('.' == *p || '\\' == *p); ++p)
|
|
|
|
;
|
|
|
|
if (r != p)
|
|
|
|
strcpyW(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir_flag)
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t szbs[] = { '\\', 0 };
|
|
|
|
|
|
|
|
strcatW(path, szbs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _wfullpath (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_wchar_t *_wfullpath(MSVCRT_wchar_t * absPath, const MSVCRT_wchar_t* relPath, unsigned int size)
|
|
|
|
{
|
|
|
|
MSVCRT_wchar_t drive[5],dir[MAX_PATH],file[MAX_PATH],ext[MAX_PATH];
|
|
|
|
MSVCRT_wchar_t res[MAX_PATH];
|
|
|
|
size_t len;
|
|
|
|
MSVCRT_wchar_t szbs[] = { '\\', 0 };
|
|
|
|
|
|
|
|
|
|
|
|
res[0] = '\0';
|
|
|
|
|
|
|
|
if (!relPath || !*relPath)
|
|
|
|
return _wgetcwd(absPath, size);
|
|
|
|
|
|
|
|
if (size < 4)
|
|
|
|
{
|
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(":resolving relative path '%s'\n",debugstr_w(relPath));
|
|
|
|
|
|
|
|
_wsplitpath(relPath, drive, dir, file, ext);
|
|
|
|
|
|
|
|
/* Get Directory and drive into 'res' */
|
|
|
|
if (!dir[0] || (dir[0] != '/' && dir[0] != '\\'))
|
|
|
|
{
|
|
|
|
/* Relative or no directory given */
|
|
|
|
_wgetdcwd(drive[0] ? toupper(drive[0]) - 'A' + 1 : 0, res, MAX_PATH);
|
|
|
|
strcatW(res,szbs);
|
|
|
|
if (dir[0])
|
|
|
|
strcatW(res,dir);
|
|
|
|
if (drive[0])
|
|
|
|
res[0] = drive[0]; /* If given a drive, preserve the letter case */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpyW(res,drive);
|
|
|
|
strcatW(res,dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcatW(res,szbs);
|
|
|
|
strcatW(res, file);
|
|
|
|
strcatW(res, ext);
|
|
|
|
wmsvcrt_fln_fix(res);
|
|
|
|
|
|
|
|
len = strlenW(res);
|
|
|
|
if (len >= MAX_PATH || len >= (size_t)size)
|
|
|
|
return NULL; /* FIXME: errno? */
|
|
|
|
|
|
|
|
if (!absPath)
|
|
|
|
return _wcsdup(res);
|
|
|
|
strcpyW(absPath,res);
|
|
|
|
return absPath;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
|
2001-04-10 23:16:07 +02:00
|
|
|
static void msvcrt_fln_fix(char *path)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
int dir_flag = 0, root_flag = 0;
|
|
|
|
char *r, *p, *q, *s;
|
|
|
|
|
|
|
|
/* Skip drive */
|
|
|
|
if (NULL == (r = strrchr(path, ':')))
|
|
|
|
r = path;
|
|
|
|
else
|
|
|
|
++r;
|
|
|
|
|
|
|
|
/* Ignore leading slashes */
|
|
|
|
while ('\\' == *r)
|
|
|
|
if ('\\' == r[1])
|
|
|
|
strcpy(r, &r[1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root_flag = 1;
|
|
|
|
++r;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = r; /* Change "\\" to "\" */
|
|
|
|
while (NULL != (p = strchr(p, '\\')))
|
|
|
|
if ('\\' == p[1])
|
|
|
|
strcpy(p, &p[1]);
|
|
|
|
else
|
|
|
|
++p;
|
|
|
|
|
|
|
|
while ('.' == *r) /* Scrunch leading ".\" */
|
|
|
|
{
|
|
|
|
if ('.' == r[1])
|
|
|
|
{
|
|
|
|
/* Ignore leading ".." */
|
|
|
|
for (p = (r += 2); *p && (*p != '\\'); ++p)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (p = r + 1 ;*p && (*p != '\\'); ++p)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
strcpy(r, p + ((*p) ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
while ('\\' == path[strlen(path)-1]) /* Strip last '\\' */
|
|
|
|
{
|
|
|
|
dir_flag = 1;
|
|
|
|
path[strlen(path)-1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
s = r;
|
|
|
|
|
|
|
|
/* Look for "\." in path */
|
|
|
|
|
|
|
|
while (NULL != (p = strstr(s, "\\.")))
|
|
|
|
{
|
|
|
|
if ('.' == p[2])
|
|
|
|
{
|
|
|
|
/* Execute this section if ".." found */
|
|
|
|
q = p - 1;
|
|
|
|
while (q > r) /* Backup one level */
|
|
|
|
{
|
|
|
|
if (*q == '\\')
|
|
|
|
break;
|
|
|
|
--q;
|
|
|
|
}
|
|
|
|
if (q > r)
|
|
|
|
{
|
|
|
|
strcpy(q, p + 3);
|
|
|
|
s = q;
|
|
|
|
}
|
|
|
|
else if ('.' != *q)
|
|
|
|
{
|
|
|
|
strcpy(q + ((*q == '\\') ? 1 : 0),
|
|
|
|
p + 3 + ((*(p + 3)) ? 1 : 0));
|
|
|
|
s = q;
|
|
|
|
}
|
|
|
|
else s = ++p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Execute this section if "." found */
|
|
|
|
q = p + 2;
|
|
|
|
for ( ;*q && (*q != '\\'); ++q)
|
|
|
|
;
|
|
|
|
strcpy (p, q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root_flag) /* Embedded ".." could have bubbled up to root */
|
|
|
|
{
|
|
|
|
for (p = r; *p && ('.' == *p || '\\' == *p); ++p)
|
|
|
|
;
|
|
|
|
if (r != p)
|
|
|
|
strcpy(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir_flag)
|
|
|
|
strcat(path, "\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _fullpath (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
char *_fullpath(char * absPath, const char* relPath, unsigned int size)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char drive[5],dir[MAX_PATH],file[MAX_PATH],ext[MAX_PATH];
|
|
|
|
char res[MAX_PATH];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
res[0] = '\0';
|
|
|
|
|
|
|
|
if (!relPath || !*relPath)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _getcwd(absPath, size);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if (size < 4)
|
|
|
|
{
|
2002-07-19 05:24:50 +02:00
|
|
|
*MSVCRT__errno() = MSVCRT_ERANGE;
|
2001-01-11 00:59:25 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(":resolving relative path '%s'\n",relPath);
|
|
|
|
|
2001-01-22 03:21:54 +01:00
|
|
|
_splitpath(relPath, drive, dir, file, ext);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* Get Directory and drive into 'res' */
|
|
|
|
if (!dir[0] || (dir[0] != '/' && dir[0] != '\\'))
|
|
|
|
{
|
|
|
|
/* Relative or no directory given */
|
2001-04-10 23:16:07 +02:00
|
|
|
_getdcwd(drive[0] ? toupper(drive[0]) - 'A' + 1 : 0, res, MAX_PATH);
|
2001-01-11 00:59:25 +01:00
|
|
|
strcat(res,"\\");
|
|
|
|
if (dir[0])
|
|
|
|
strcat(res,dir);
|
|
|
|
if (drive[0])
|
|
|
|
res[0] = drive[0]; /* If given a drive, preserve the letter case */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(res,drive);
|
|
|
|
strcat(res,dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(res,"\\");
|
|
|
|
strcat(res, file);
|
|
|
|
strcat(res, ext);
|
2001-04-10 23:16:07 +02:00
|
|
|
msvcrt_fln_fix(res);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
len = strlen(res);
|
|
|
|
if (len >= MAX_PATH || len >= (size_t)size)
|
|
|
|
return NULL; /* FIXME: errno? */
|
|
|
|
|
|
|
|
if (!absPath)
|
2001-04-10 23:16:07 +02:00
|
|
|
return _strdup(res);
|
2001-01-11 00:59:25 +01:00
|
|
|
strcpy(absPath,res);
|
|
|
|
return absPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _makepath (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
VOID _makepath(char * path, const char * drive,
|
2001-01-11 00:59:25 +01:00
|
|
|
const char *directory, const char * filename,
|
|
|
|
const char * extension )
|
|
|
|
{
|
|
|
|
char ch;
|
2003-02-19 04:43:08 +01:00
|
|
|
char tmpPath[MAX_PATH];
|
|
|
|
TRACE("got %s %s %s %s\n", debugstr_a(drive), debugstr_a(directory),
|
|
|
|
debugstr_a(filename), debugstr_a(extension) );
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
return;
|
|
|
|
|
2003-02-19 04:43:08 +01:00
|
|
|
tmpPath[0] = '\0';
|
2001-01-11 00:59:25 +01:00
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
2003-02-19 04:43:08 +01:00
|
|
|
tmpPath[0] = drive[0];
|
|
|
|
tmpPath[1] = ':';
|
|
|
|
tmpPath[2] = 0;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
2003-02-19 04:43:08 +01:00
|
|
|
strcat(tmpPath, directory);
|
|
|
|
ch = tmpPath[strlen(tmpPath)-1];
|
2001-01-11 00:59:25 +01:00
|
|
|
if (ch != '/' && ch != '\\')
|
2003-02-19 04:43:08 +01:00
|
|
|
strcat(tmpPath,"\\");
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
2003-02-19 04:43:08 +01:00
|
|
|
strcat(tmpPath, filename);
|
2001-01-11 00:59:25 +01:00
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
|
|
|
if ( extension[0] != '.' )
|
2003-02-19 04:43:08 +01:00
|
|
|
strcat(tmpPath,".");
|
|
|
|
strcat(tmpPath,extension);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-19 04:43:08 +01:00
|
|
|
strcpy( path, tmpPath );
|
|
|
|
|
2001-04-11 01:25:25 +02:00
|
|
|
TRACE("returning %s\n",path);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2002-01-29 19:00:44 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _wmakepath (MSVCRT.@)
|
|
|
|
*/
|
2002-12-19 05:21:30 +01:00
|
|
|
VOID _wmakepath(MSVCRT_wchar_t *path, const MSVCRT_wchar_t *drive, const MSVCRT_wchar_t *directory,
|
|
|
|
const MSVCRT_wchar_t *filename, const MSVCRT_wchar_t *extension)
|
2002-01-29 19:00:44 +01:00
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
MSVCRT_wchar_t ch;
|
2002-01-29 19:00:44 +01:00
|
|
|
TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory),
|
|
|
|
debugstr_w(filename), debugstr_w(extension));
|
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
return;
|
|
|
|
|
|
|
|
path[0] = 0;
|
|
|
|
if (drive && drive[0])
|
|
|
|
{
|
|
|
|
path[0] = drive[0];
|
|
|
|
path[1] = ':';
|
|
|
|
path[2] = 0;
|
|
|
|
}
|
|
|
|
if (directory && directory[0])
|
|
|
|
{
|
|
|
|
strcatW(path, directory);
|
|
|
|
ch = path[strlenW(path) - 1];
|
|
|
|
if (ch != '/' && ch != '\\')
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
static const MSVCRT_wchar_t backslashW[] = {'\\',0};
|
2002-01-29 19:00:44 +01:00
|
|
|
strcatW(path, backslashW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (filename && filename[0])
|
|
|
|
{
|
|
|
|
strcatW(path, filename);
|
|
|
|
if (extension && extension[0])
|
|
|
|
{
|
|
|
|
if ( extension[0] != '.' )
|
|
|
|
{
|
2002-12-19 05:21:30 +01:00
|
|
|
static const MSVCRT_wchar_t dotW[] = {'.',0};
|
2002-01-29 19:00:44 +01:00
|
|
|
strcatW(path, dotW);
|
|
|
|
}
|
|
|
|
strcatW(path, extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("returning %s\n", debugstr_w(path));
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _searchenv (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:16:07 +02:00
|
|
|
void _searchenv(const char* file, const char* env, char *buf)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char*envVal, *penv;
|
|
|
|
char curPath[MAX_PATH];
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
|
|
|
/* Try CWD first */
|
|
|
|
if (GetFileAttributesA( file ) != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
GetFullPathNameA( file, MAX_PATH, buf, NULL );
|
|
|
|
/* Sigh. This error is *always* set, regardless of success */
|
|
|
|
MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search given environment variable */
|
|
|
|
envVal = MSVCRT_getenv(env);
|
|
|
|
if (!envVal)
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
penv = envVal;
|
|
|
|
TRACE(":searching for %s in paths %s\n", file, envVal);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2001-01-22 03:21:54 +01:00
|
|
|
char *end = penv;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
while(*end && *end != ';') end++; /* Find end of next path */
|
|
|
|
if (penv == end || !*penv)
|
|
|
|
{
|
|
|
|
MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strncpy(curPath, penv, end - penv);
|
|
|
|
if (curPath[end - penv] != '/' || curPath[end - penv] != '\\')
|
|
|
|
{
|
|
|
|
curPath[end - penv] = '\\';
|
|
|
|
curPath[end - penv + 1] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
curPath[end - penv] = '\0';
|
|
|
|
|
|
|
|
strcat(curPath, file);
|
|
|
|
TRACE("Checking for file %s\n", curPath);
|
|
|
|
if (GetFileAttributesA( curPath ) != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
strcpy(buf, curPath);
|
|
|
|
MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
|
|
|
|
return; /* Found */
|
|
|
|
}
|
|
|
|
penv = *end ? end + 1 : end;
|
|
|
|
} while(1);
|
|
|
|
}
|