add workarounds for mingw runtime version differences

gave directory routines a good cleanup (based on wine)
more tcharizing of routines

svn path=/trunk/; revision=13615
This commit is contained in:
Gunnar Dalsnes 2005-02-17 11:38:16 +00:00
parent 2374843a9d
commit f7a525a34b
48 changed files with 204 additions and 219 deletions

View file

@ -2,14 +2,15 @@
#include <ctype.h>
#include <direct.h>
#include <internal/file.h>
#include <tchar.h>
/*
* @implemented
*/
int _chdir(const char* _path)
int _tchdir(const _TCHAR* _path)
{
if (!SetCurrentDirectoryA((char*)_path)) {
_dosmaperr(GetLastError());
if (!SetCurrentDirectory(_path)) {
_dosmaperr(_path?GetLastError():0);
return -1;
}
return 0;

View file

@ -6,29 +6,36 @@
#include <internal/file.h>
int cur_drive = 0;
/*
* @implemented
*
* _chdrive (MSVCRT.@)
*
* 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.
*/
int _chdrive(int drive)
int _chdrive(int newdrive)
{
char d[3];
WCHAR buffer[] = L"A:";
if (!( drive >= 1 && drive <= 26)) {
__set_errno(EINVAL);
return -1;
}
if (cur_drive != drive) {
cur_drive = drive;
d[0] = toupper(cur_drive + '@');
d[1] = ':';
d[2] = 0;
if (!SetCurrentDirectoryA(d)) {
buffer[0] += newdrive - 1;
if (!SetCurrentDirectoryW( buffer ))
{
_dosmaperr(GetLastError());
return -1;
if (newdrive <= 0)
{
__set_errno(EACCES);
}
return -1;
}
return 0;
}

View file

@ -3,29 +3,33 @@
#include <stdlib.h>
#include <errno.h>
#include <internal/file.h>
#include <tchar.h>
/*
* @implemented
*/
char *_getcwd(char* buffer, int maxlen)
_TCHAR* _tgetcwd(_TCHAR* buf, int size)
{
char *cwd;
int len;
_TCHAR dir[MAX_PATH];
DWORD dir_len = GetCurrentDirectory(MAX_PATH,dir);
if (buffer == NULL) {
if ( (cwd = malloc(MAX_PATH)) == NULL ) {
__set_errno(ENOMEM);
return NULL;
}
len = MAX_PATH;
} else {
cwd = buffer;
len = maxlen;
}
if (GetCurrentDirectoryA(len, cwd) == 0) {
if (dir_len == 0)
{
_dosmaperr(GetLastError());
return NULL;
return NULL; /* FIXME: Real return value untested */
}
return cwd;
if (!buf)
{
return _tcsdup(dir);
}
if (dir_len >= size)
{
__set_errno(ERANGE);
return NULL; /* buf too small */
}
_tcscpy(buf,dir);
return buf;
}

View file

@ -1,27 +1,64 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#include <internal/debug.h>
#include <tchar.h>
#include <errno.h>
/*
* @implemented
*
* _getdcwd (MSVCRT.@)
*
* 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.
*/
char* _getdcwd(int nDrive, char* caBuffer, int nBufLen)
_TCHAR* _tgetdcwd(int drive, _TCHAR * buf, int size)
{
int i =0;
int dr = _getdrive();
static _TCHAR* dummy;
if (nDrive < 1 || nDrive > 26)
return NULL;
if (dr != nDrive) {
if ( _chdrive(nDrive) != 0 )
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
if (!drive || drive == _getdrive())
return _tgetcwd(buf,size); /* current */
else
{
_TCHAR dir[MAX_PATH];
_TCHAR drivespec[] = _T("A:");
int dir_len;
drivespec[0] += drive - 1;
if (GetDriveType(drivespec) < DRIVE_REMOVABLE)
{
__set_errno(EACCES);
return NULL;
}
i = GetCurrentDirectoryA(nBufLen, caBuffer);
if (i == nBufLen)
return NULL;
if (dr != nDrive) {
if ( _chdrive(dr) != 0 )
return NULL;
/* GetFullPathName for X: means "get working directory on drive X",
* just like passing X: to SetCurrentDirectory means "switch to working
* directory on drive X". -Gunnar */
dir_len = GetFullPathName(drivespec,MAX_PATH,dir,&dummy);
if (dir_len >= size || dir_len < 1)
{
__set_errno(ERANGE);
return NULL; /* buf too small */
}
return caBuffer;
TRACE(":returning '%s'\n", dir);
if (!buf)
return _tcsdup(dir); /* allocate */
_tcscpy(buf,dir);
}
return buf;
}

View file

@ -3,28 +3,33 @@
#include <direct.h>
extern int cur_drive;
/*
* @implemented
*
* _getdrive (MSVCRT.@)
*
* Get the current drive number.
*
* PARAMS
* None.
*
* RETURNS
* Success: The drive letter number from 1 to 26 ("A:" to "Z:").
* Failure: 0.
*/
int _getdrive(void)
{
WCHAR buffer[MAX_PATH];
if (GetCurrentDirectoryW( MAX_PATH, buffer ) &&
buffer[0] >= 'A' && buffer[0] <= 'z' && buffer[1] == ':')
return towupper(buffer[0]) - 'A' + 1;
return 0;
}
/*
* @implemented
*/
int _getdrive(void)
{
char Buffer[MAX_PATH];
if (cur_drive == 0) {
GetCurrentDirectoryA(MAX_PATH, Buffer);
cur_drive = toupper(Buffer[0] - '@');
}
return cur_drive;
}
/*
* @unimplemented
*/
unsigned long _getdrives(void)
{
//fixme get logical drives
//return GetLogicalDrives();
return 5; // drive A and C
return GetLogicalDrives();
}

View file

@ -1,14 +1,14 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#include <tchar.h>
/*
* @implemented
*/
int _mkdir(const char* _path)
int _tmkdir(const _TCHAR* _path)
{
if (!CreateDirectoryA(_path, NULL)) {
if (!CreateDirectory(_path, NULL)) {
_dosmaperr(GetLastError());
return -1;
}

View file

@ -1,14 +1,14 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#include <tchar.h>
/*
* @implemented
*/
int _rmdir(const char* _path)
int _trmdir(const _TCHAR* _path)
{
if (!RemoveDirectoryA(_path)) {
if (!RemoveDirectory(_path)) {
_dosmaperr(GetLastError());
return -1;
}

View file

@ -1,16 +1,5 @@
#include "precomp.h"
#include <ctype.h>
#include <direct.h>
#include <internal/file.h>
#define UNICODE
#define _UNICODE
#include "chdir.c"
/*
* @implemented
*/
int _wchdir (const wchar_t *_path)
{
if (!SetCurrentDirectoryW((wchar_t *)_path)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,28 +1,5 @@
#include "precomp.h"
#include <direct.h>
#include <stdlib.h>
#include <errno.h>
#include <internal/file.h>
#define UNICODE
#define _UNICODE
#include "getcwd.c"
/*
* @implemented
*/
wchar_t* _wgetcwd(wchar_t* buffer, int maxlen)
{
wchar_t *cwd;
int len;
if (buffer == NULL) {
if ( (cwd = malloc(MAX_PATH * sizeof(wchar_t))) == NULL ) {
__set_errno(ENOMEM);
return NULL;
}
len = MAX_PATH;
} else {
cwd = buffer;
len = maxlen;
}
if (GetCurrentDirectoryW(len, cwd) == 0)
return NULL;
return cwd;
}

View file

@ -1,32 +1,5 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#define UNICODE
#define _UNICODE
#include "getdcwd.c"
/*
* @implemented
*/
wchar_t* _wgetdcwd(int nDrive, wchar_t* caBuffer, int nBufLen)
{
int i =0;
int dr = _getdrive();
if (nDrive < 1 || nDrive > 26)
return NULL;
if (dr != nDrive) {
if ( _chdrive(nDrive) != 0 )
return NULL;
}
i = GetCurrentDirectoryW(nBufLen, caBuffer);
if (i == nBufLen)
return NULL;
if (dr != nDrive) {
if ( _chdrive(dr) != 0 )
return NULL;
}
return caBuffer;
}

View file

@ -1,16 +1,4 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#define UNICODE
#define _UNICODE
/*
* @implemented
*/
int _wmkdir(const wchar_t* _path)
{
if (!CreateDirectoryW(_path, NULL)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}
#include "mkdir.c"

View file

@ -1,16 +1,4 @@
#include "precomp.h"
#include <direct.h>
#include <internal/file.h>
#define UNICODE
#define _UNICODE
/*
* @implemented
*/
int _wrmdir(const wchar_t* _path)
{
if (!RemoveDirectoryW(_path)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}
#include "rmdir.c"

View file

@ -14,6 +14,9 @@
#define _FPCLASS_PN 0x0100 /* positive normal */
#define _FPCLASS_PINF 0x0200 /* positive infinity */
#if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 3
#define FP_SNAN 0x0001 // signaling NaN
#define FP_QNAN 0x0002 // quiet NaN
#define FP_NINF 0x0004 // negative infinity
@ -25,6 +28,8 @@
#define FP_NNORM 0x0080 // negative normalized non-zero
#define FP_PNORM 0x0100 // positive normalized non-zero
#endif
typedef int fpclass_t;
/*

View file

@ -185,6 +185,10 @@ int _isinf(double x);
wint_t _filwbuf(FILE *f);
#if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 2
int __cdecl _filbuf (FILE*);
int __cdecl _flsbuf (int, FILE*);
#endif
#endif /* __dj_include_libc_file_h__ */

View file

@ -5,7 +5,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#ifdef _UNICODE
#define _TS S

View file

@ -6,7 +6,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#define mode_t int

View file

@ -2,7 +2,7 @@
#include <io.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -3,7 +3,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -2,7 +2,7 @@
#include <fcntl.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -8,7 +8,7 @@
/*
* @implemented
*/
#ifdef _UNICODE
#if defined(_UNICODE) || !(__MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 3)
long
#else
int
@ -60,7 +60,7 @@ _tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result)
* @implemented
*/
int _tfindnext(
#ifdef _UNICODE
#if defined(_UNICODE) || !(__MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 3)
long handle,
#else
int handle,
@ -176,7 +176,13 @@ int _tfindnexti64(long handle, struct _tfinddatai64_t *result)
/*
* @implemented
*/
int _findclose(int handle)
int _findclose(
#if __MINGW32_MAJOR_VERSION < 3 || __MINGW32_MINOR_VERSION < 3
int handle
#else
long handle
#endif
)
{
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)

View file

@ -2,7 +2,7 @@
#include <sys/stat.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -18,7 +18,7 @@
#include <io.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -52,7 +52,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>

View file

@ -15,7 +15,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -17,7 +17,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -14,6 +14,6 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>

View file

@ -13,7 +13,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -2,7 +2,7 @@
#include <fcntl.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -18,7 +18,7 @@
#include <io.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -26,7 +26,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -16,7 +16,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#define BUFSIZE 4096
/*

View file

@ -13,7 +13,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -13,7 +13,7 @@
#include <stdlib.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
unsigned int __setlc_active;
unsigned int __unguarded_readlc_active;

View file

@ -6,7 +6,7 @@
#include "precomp.h"
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#ifndef __GNUC__

View file

@ -12,7 +12,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
unsigned int _osver = 0;

View file

@ -19,7 +19,7 @@
#include "precomp.h"
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#include <internal/mtdll.h>
typedef struct

View file

@ -1,7 +1,7 @@
#include "precomp.h"
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*********************************************************************
* $I10_OUTPUT (MSVCRT.@)

View file

@ -7,7 +7,7 @@
#include <tchar.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#ifdef _UNICODE
#define find_execT find_execW

View file

@ -89,7 +89,7 @@ __p_sig_fn_t signal(int sig, __p_sig_fn_t func)
int
raise(int sig)
{
__p_sig_fn_t temp;// = SIG_DFL;
__p_sig_fn_t temp = 0;
int i;
switch (sig)

View file

@ -6,7 +6,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -8,7 +8,7 @@
#include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -4,7 +4,7 @@
#include <tchar.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*
* @implemented

View file

@ -2,7 +2,7 @@
#include <stdlib.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
#undef environ

View file

@ -3,7 +3,7 @@
#include <string.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/* misc/environ.c */
int SetEnv(const wchar_t *option);

View file

@ -4,7 +4,7 @@
#include <tchar.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*

View file

@ -3,7 +3,7 @@
#include <string.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/* misc/environ.c */
int SetEnv(const wchar_t *option);

View file

@ -42,12 +42,13 @@
#include <wchar.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <internal/file.h>
//#include <ntos/heap.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
#include <internal/debug.h>
/*