diff --git a/dlls/crtdll/crtdll.spec b/dlls/crtdll/crtdll.spec index 02d9a1d4dc5..8d227a783c5 100644 --- a/dlls/crtdll/crtdll.spec +++ b/dlls/crtdll/crtdll.spec @@ -40,8 +40,8 @@ debug_channels (crtdll) @ cdecl __iscsymf(long) CRTDLL___iscsymf @ stub __mb_cur_max_dll @ stub __pxcptinfoptrs -@ cdecl __threadhandle() GetCurrentThread -@ cdecl __threadid() GetCurrentThreadId +@ forward __threadhandle kernel32.GetCurrentThread +@ forward __threadid kernel32.GetCurrentThreadId @ cdecl __toascii(long) CRTDLL___toascii @ cdecl _abnormal_termination() CRTDLL__abnormal_termination @ cdecl _access(str long) CRTDLL__access @@ -467,7 +467,7 @@ debug_channels (crtdll) @ cdecl sinh(double) sinh @ varargs sprintf() sprintf @ cdecl sqrt(double) sqrt -@ cdecl srand(long) CRTDLL_srand +@ cdecl srand(long) srand @ varargs sscanf() sscanf @ cdecl strcat(str str) strcat @ cdecl strchr(str long) strchr diff --git a/dlls/crtdll/crtdll_main.c b/dlls/crtdll/crtdll_main.c index 86c51375485..a939b202bc9 100644 --- a/dlls/crtdll/crtdll_main.c +++ b/dlls/crtdll/crtdll_main.c @@ -28,7 +28,6 @@ UB 000416: #include #include #include -#include "file.h" #include "ntddk.h" #include "wingdi.h" #include "winuser.h" @@ -257,16 +256,6 @@ INT __cdecl CRTDLL__setjmp(LPDWORD *jmpbuf) } -/********************************************************************* - * srand (CRTDLL.460) - */ -void __cdecl CRTDLL_srand(DWORD seed) -{ - /* FIXME: should of course be thread? process? local */ - srand(seed); -} - - /********************************************************************* * _beep (CRTDLL.045) * @@ -301,10 +290,8 @@ INT __cdecl CRTDLL_rand() */ UINT __cdecl CRTDLL__rotl(UINT x,INT shift) { - unsigned int ret = (x >> shift)|( x >>((sizeof(x))-shift)); - - TRACE("got 0x%08x rot %d ret 0x%08x\n", x,shift,ret); - return ret; + shift &= 31; + return (x << shift) | (x >> (32-shift)); } @@ -313,10 +300,8 @@ UINT __cdecl CRTDLL__rotl(UINT x,INT shift) */ DWORD __cdecl CRTDLL__lrotl(DWORD x,INT shift) { - unsigned long ret = (x >> shift)|( x >>((sizeof(x))-shift)); - - TRACE("got 0x%08lx rot %d ret 0x%08lx\n", x,shift,ret); - return ret; + shift &= 31; + return (x << shift) | (x >> (32-shift)); } @@ -325,10 +310,8 @@ DWORD __cdecl CRTDLL__lrotl(DWORD x,INT shift) */ DWORD __cdecl CRTDLL__lrotr(DWORD x,INT shift) { - /* Depends on "long long" being 64 bit or greater */ - unsigned long long arg = x; - unsigned long long ret = (arg << 32 | (x & 0xFFFFFFFF)) >> (shift & 0x1f); - return ret & 0xFFFFFFFF; + shift &= 0x1f; + return (x >> shift) | (x << (32-shift)); } @@ -337,10 +320,8 @@ DWORD __cdecl CRTDLL__lrotr(DWORD x,INT shift) */ DWORD __cdecl CRTDLL__rotr(UINT x,INT shift) { - /* Depends on "long long" being 64 bit or greater */ - unsigned long long arg = x; - unsigned long long ret = (arg << 32 | (x & 0xFFFFFFFF)) >> (shift & 0x1f); - return ret & 0xFFFFFFFF; + shift &= 0x1f; + return (x >> shift) | (x << (32-shift)); } @@ -413,15 +394,12 @@ BOOL __cdecl CRTDLL__isctype(CHAR x,CHAR type) */ LPSTR __cdecl CRTDLL__fullpath(LPSTR buf, LPCSTR name, INT size) { - DOS_FULL_NAME full_name; - if (!buf) { size = 256; if(!(buf = CRTDLL_malloc(size))) return NULL; } - if (!DOSFS_GetFullName( name, FALSE, &full_name )) return NULL; - lstrcpynA(buf,full_name.short_name,size); + if (!GetFullPathNameA( name, size, buf, NULL )) return NULL; TRACE("CRTDLL_fullpath got %s\n",buf); return buf; } diff --git a/dlls/crtdll/dir.c b/dlls/crtdll/dir.c index 5122cb490b9..4251bba22a6 100644 --- a/dlls/crtdll/dir.c +++ b/dlls/crtdll/dir.c @@ -14,9 +14,8 @@ #include "crtdll.h" #include -#include "drive.h" +#include "ntddk.h" #include -#include "file.h" DEFAULT_DEBUG_CHANNEL(crtdll); @@ -24,7 +23,7 @@ DEFAULT_DEBUG_CHANNEL(crtdll); static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft); static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft) { - static DWORD dummy; + DWORD dw; /* Tested with crtdll.dll Version 2.50.4170 (NT) from win98 SE: * attrib 0x80 (FILE_ATTRIBUTE_NORMAL)is returned as 0. @@ -34,9 +33,12 @@ static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft) else ft->attrib = fd->dwFileAttributes; - ft->time_create = DOSFS_FileTimeToUnixTime(&fd->ftCreationTime,&dummy); - ft->time_access = DOSFS_FileTimeToUnixTime(&fd->ftLastAccessTime,&dummy); - ft->time_write = DOSFS_FileTimeToUnixTime(&fd->ftLastWriteTime,&dummy); + RtlTimeToSecondsSince1970( &fd->ftCreationTime, &dw ); + ft->time_create = dw; + RtlTimeToSecondsSince1970( &fd->ftLastAccessTime, &dw ); + ft->time_access = dw; + RtlTimeToSecondsSince1970( &fd->ftLastWriteTime, &dw ); + ft->time_write = dw; ft->size = fd->nFileSizeLow; strcpy(ft->name, fd->cFileName); } @@ -81,7 +83,9 @@ INT __cdecl CRTDLL__chdir(LPCSTR newdir) */ BOOL __cdecl CRTDLL__chdrive(INT newdrive) { - if (!DRIVE_SetCurrentDrive(newdrive-1)) + char buffer[3] = "A:"; + buffer[0] += newdrive - 1; + if (!SetCurrentDirectoryA( buffer )) { __CRTDLL__set_errno(GetLastError()); if (newdrive <= 0) @@ -233,7 +237,7 @@ CHAR* __cdecl CRTDLL__getdcwd(INT drive,LPSTR buf, INT size) { static CHAR* dummy; - if (!drive || --drive == DRIVE_GetCurrentDrive()) + if (!drive || drive == CRTDLL__getdrive()) return CRTDLL__getcwd(buf,size); /* current */ else { @@ -241,7 +245,7 @@ CHAR* __cdecl CRTDLL__getdcwd(INT drive,LPSTR buf, INT size) char drivespec[4] = {'A', ':', '\\', 0}; int dir_len; - drivespec[0] += drive; + drivespec[0] += drive - 1; if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE) { CRTDLL_errno = EACCES; @@ -302,7 +306,10 @@ UINT __cdecl CRTDLL__getdiskfree(UINT disk, diskfree_t* d) */ INT __cdecl CRTDLL__getdrive(VOID) { - return DRIVE_GetCurrentDrive() + 1; + char buffer[MAX_PATH]; + if (!GetCurrentDirectoryA( sizeof(buffer), buffer )) return 0; + if (buffer[1] != ':') return 0; + return toupper(buffer[0]) - 'A' + 1; } diff --git a/dlls/crtdll/file.c b/dlls/crtdll/file.c index ea4edbf5fa0..e48118a1ed4 100644 --- a/dlls/crtdll/file.c +++ b/dlls/crtdll/file.c @@ -39,9 +39,7 @@ #include #include #include -#include "drive.h" -#include "file.h" - +#include "ntddk.h" DEFAULT_DEBUG_CHANNEL(crtdll); @@ -470,7 +468,7 @@ CRTDLL_FILE* __cdecl CRTDLL__fsopen(LPCSTR path, LPCSTR mode, INT share) */ int __cdecl CRTDLL__fstat(int fd, struct _stat* buf) { - static DWORD dummy; + DWORD dw; BY_HANDLE_FILE_INFORMATION hfi; HANDLE hand = __CRTDLL__fdtoh(fd); @@ -496,9 +494,10 @@ int __cdecl CRTDLL__fstat(int fd, struct _stat* buf) FIXME(":dwFileAttributes = %d, mode set to 0",hfi.dwFileAttributes); buf->st_nlink = hfi.nNumberOfLinks; buf->st_size = hfi.nFileSizeLow; - buf->st_atime = DOSFS_FileTimeToUnixTime(&hfi.ftCreationTime,&dummy); - buf->st_mtime = DOSFS_FileTimeToUnixTime(&hfi.ftLastAccessTime,&dummy); - buf->st_ctime = DOSFS_FileTimeToUnixTime(&hfi.ftLastWriteTime,&dummy); + RtlTimeToSecondsSince1970( &hfi.ftLastAccessTime, &dw ); + buf->st_atime = dw; + RtlTimeToSecondsSince1970( &hfi.ftLastWriteTime, &dw ); + buf->st_mtime = buf->st_ctime = dw; return 0; } @@ -763,27 +762,18 @@ INT __cdecl CRTDLL__setmode(INT fd,INT mode) */ INT __cdecl CRTDLL__stat(const char* path, struct _stat * buf) { - static DWORD dummy; - DOS_FULL_NAME full_name; - BY_HANDLE_FILE_INFORMATION hfi; + DWORD dw; + WIN32_FILE_ATTRIBUTE_DATA hfi; unsigned short mode = CRTDLL_S_IREAD; int plen; TRACE(":file (%s) buf(%p)\n",path,buf); - if (!DOSFS_GetFullName( path, TRUE, &full_name )) - { - TRACE("failed-last error (%ld)\n",GetLastError()); - __CRTDLL__set_errno(ERROR_FILE_NOT_FOUND); - return -1; - } - - memset(&hfi,0,sizeof(hfi)); - if (!FILE_Stat(full_name.long_name,&hfi)) + if (!GetFileAttributesExA( path, GetFileExInfoStandard, &hfi )) { - TRACE("failed-last error (%ld)\n",GetLastError()); - __CRTDLL__set_errno(ERROR_FILE_NOT_FOUND); - return -1; + TRACE("failed-last error (%ld)\n",GetLastError()); + __CRTDLL__set_errno(ERROR_FILE_NOT_FOUND); + return -1; } memset(buf,0,sizeof(struct _stat)); @@ -792,7 +782,7 @@ INT __cdecl CRTDLL__stat(const char* path, struct _stat * buf) if (isalpha(*path)) buf->st_dev = buf->st_rdev = toupper(*path - 'A'); /* drive num */ else - buf->st_dev = buf->st_rdev = DRIVE_GetCurrentDrive(); + buf->st_dev = buf->st_rdev = CRTDLL__getdrive() - 1; plen = strlen(path); @@ -817,11 +807,12 @@ INT __cdecl CRTDLL__stat(const char* path, struct _stat * buf) mode |= CRTDLL_S_IWRITE; buf->st_mode = mode; - buf->st_nlink = hfi.nNumberOfLinks; + buf->st_nlink = 1; buf->st_size = hfi.nFileSizeLow; - buf->st_atime = DOSFS_FileTimeToUnixTime(&hfi.ftCreationTime,&dummy); - buf->st_mtime = - buf->st_ctime = DOSFS_FileTimeToUnixTime(&hfi.ftLastWriteTime,&dummy); + RtlTimeToSecondsSince1970( &hfi.ftLastAccessTime, &dw ); + buf->st_atime = dw; + RtlTimeToSecondsSince1970( &hfi.ftLastWriteTime, &dw ); + buf->st_mtime = buf->st_ctime = dw; TRACE("\n%d %d %d %d %d %d\n", buf->st_mode,buf->st_nlink,buf->st_size, buf->st_atime,buf->st_mtime, buf->st_ctime); return 0; diff --git a/dlls/crtdll/spawn.c b/dlls/crtdll/spawn.c index 20c308e068f..5768469dedf 100644 --- a/dlls/crtdll/spawn.c +++ b/dlls/crtdll/spawn.c @@ -41,7 +41,6 @@ #include "crtdll.h" #include #include "process.h" -#include "options.h" #include @@ -182,44 +181,6 @@ HANDLE __cdecl CRTDLL__spawnve(INT flags, LPSTR name, LPSTR *argv, LPSTR *envv) */ INT __cdecl CRTDLL_system(LPSTR x) { -#define SYSBUF_LENGTH 1500 - char buffer[SYSBUF_LENGTH]; - unsigned char *y = x; - unsigned char *bp; - int i; - - strcpy(buffer, argv0); - bp = buffer + strlen(buffer); - *bp++ = ' '; - *bp++ = '"'; - *bp++ = 0; - i = strlen(buffer) + strlen(x) +2; - - /* Calculate needed buffer size to prevent overflow. */ - while (*y) { - if (*y =='\\') i++; - y++; - } - /* If buffer too short, exit. */ - if (i > SYSBUF_LENGTH) { - TRACE("_system buffer to small\n"); - return 127; - } - - y =x; - - while (*y) { - *bp = *y; - bp++; y++; - if (*(y-1) =='\\') *bp++ = '\\'; - } - /* Remove spaces from end of string. */ - while (*(y-1) == ' ') { - bp--;y--; - } - *bp++ = '"'; - *bp = 0; - TRACE("_system got '%s', executing '%s'\n",x,buffer); - - return system(buffer); + /* FIXME: should probably launch cmd interpreter in COMSPEC */ + return __CRTDLL__spawn(_P_WAIT, NULL, x, NULL); }