Sat Dec 23 18:15:59 1995 Alexandre Julliard <julliard@sunsite.unc.edu> * [configure.in] [Makefile.in] [tools/install-sh] New 'install' target installs Wine binary, library and man page. Library is now more logically named libwine.a. Split toolkit/ directory into library (for library code) and libtest (for test programs). * [controls/edit.c] Quick hack to partially support EM_PASSWORD style (avoids displaying your passwords on the screen when testing programs...) * [configure.in] [controls/menu.c] [include/resource.h] [misc/commdlg.c] [misc/ole2nls.c] [misc/shell.c] [windows/msgbox.c] Language is now a run-time option (wine -language xx). * [debugger/dbg.y] Dump some more debugging info on crash. * [misc/profile.c] Only consider ';' as a comment if it's the first non-blank character on the line. * [miscemu/dpmi.c] More debugging info for real-mode callback. * [objects/gdiobj.c] Rewrote EnumObjects() to do the Right Thing. * [resources/sysres*] New directory containing system resources. Fri Dec 22 11:24:39 GMT 1995 John Harvey <john@division.co.uk> * [win32/file.c] [win32/memory.c] Unixware doesn't have MAP_ANON ifdefed out for now. * [misc/dos_fs.c] DOS_GetDosFileName didn't truncate paths starting ./ properly. * [tools/build.c] Produces assembly code that works with the unixware assembler. Wed Dec 20 22:22:29 +0100 1995 Morten Welinder <terra@diku.dk> * [miscemu/instr.c] INSTR_GetOperandAddr: 16-bit addresses should be masked to 16 bits. * [misc/dos_fs.c] DOS_readdir should always return directories, even if they don't match the file name mask. Tue Dec 19 18:00:00 1995 Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de> * [misc/exec.c] Give arguments to winhelp. * [miscemu/int21.c] Implemented Interrupt 21 AX=6C00 EXTENDED OPEN/CREATE. Created function ExtendedOpenCreateFile. Give for some Windows95 interrupts the return value 'not implemented'. Sun Dec 17 16:51:56 EST 1995 Jim Peterson <jspeter@birch.ee.vt.edu> * [include/kernel32.h] [include/windows.h] Moved the typedefs for SYSTEMTIME and LPSYSTEMTIME from include/kernel32.h to include/windows.h and declared the new Win32 API functions Sleep(), GetLocalTime(), and GetSystemTime(). Redefined INFINITE as 0xFFFFFFFF if WINELIB32. * [rc/rc (new file)] Created the shell script 'rc', which should simplify resource compilation. * [win32/environment.c] Kludged around an undefined reference to wine_files. This change should be fixed some time. * [win32/time.c] [if1632/kernel32.spec] Added the functions GetSystemTime(), and Sleep(). * [miscemu/int21.c] Renamed static function GetSystemTime to INT21_GetSystemTime to avoid conflicts with the API function of the same name. * [include/wintypes.h] Added the SPFMT definition for printf statements. * [misc/shell.c] [include/shell.h] Changed ERROR_* defines to SHELL_ERROR_*, as they were conflicting with the ones in include/winerror.h. They should probably use the versions in winerror.h, but I'm not certain, and that can be done later. * [windows/mdi.c] Translated WM_MDIACTIVATE(?,(LOhwnd,HIhwnd)) messages to WM_MDIACTIVATE(HIhwnd,LOhwnd) for WINELIB32. The ? parameter (boolean) was discarded with this translation. Translated handler of WM_MDISETMENU(ref,(loHMENU,hiHMENU)) to handle WM_MDISETMENU(loHMENU, hiHMENU) messages in WINELIB32 (ref assumed false, call DrawMenuBar() if desired). * [*/*] General explicit casts and more rigid typing to remove warnings. * [include/winpos.h] [windows/winpos.c] Changed return type of WINPOS_ChangeActiveWindow to BOOL. * [include/commdlg.h] [misc/commdlg.c] Added prototypes for ChooseColor(), CommDlgExtendedError(), FindText() GetFileTitle(), GetOpenFileName(), GetSaveFileName(), PrintDlg, and ReplaceText(). Renamed the CommDlgExtendError() function to CommDlgExtendedError(). Made GetFileTitle return a short, as per the API definition. * [Makefile.in] Added line to clean and distclean that removes temporaries from the include directory. Sat Dec 16 19:39:14 MET 1995 Steffen Moeller <smoe0024@rz.uni-hildesheim.de> * [controls/edit.c] Almost rewrote EDIT_GetLineMsg. Sat Dec 16 13:51:48 MST 1995 Andrew Taylor <andrew@riscan.com> * [windows/mdi.c] Fixed MDITile() bug that occurs when 0 windows are present or all windows are minimized. Wed Dec 12 23:30:00 1995 Uwe Bonnes <bon@elektron.ikp.physik.th-darmstadt.de> * [misc/profile.c] Try harder to find files, especially in the working directory. Look in $HOME/.wine too and create it there if it isn't found.
470 lines
12 KiB
C
470 lines
12 KiB
C
/*
|
|
* Win32 kernel functions
|
|
*
|
|
* Copyright 1995 Martin von Loewis, Sven Verdoolaege, and Cameron Heide
|
|
*/
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/mman.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "windows.h"
|
|
#include "winerror.h"
|
|
#include "kernel32.h"
|
|
#include "handle32.h"
|
|
#include "dos_fs.h"
|
|
#include "stddebug.h"
|
|
#define DEBUG_WIN32
|
|
#include "debug.h"
|
|
|
|
|
|
extern FILE_OBJECT *hstdin;
|
|
extern FILE_OBJECT *hstdout;
|
|
extern FILE_OBJECT *hstderr;
|
|
|
|
static void UnixTimeToFileTime(time_t unix_time, FILETIME *filetime);
|
|
static int TranslateCreationFlags(DWORD create_flags);
|
|
static int TranslateAccessFlags(DWORD access_flags);
|
|
#ifndef MAP_ANON
|
|
#define MAP_ANON 0
|
|
#endif
|
|
|
|
/***********************************************************************
|
|
* OpenFileMappingA (KERNEL32.397)
|
|
*
|
|
*/
|
|
WINAPI HANDLE32 OpenFileMapping(DWORD access, BOOL inherit,const char *fname)
|
|
{
|
|
return 0;
|
|
}
|
|
/***********************************************************************
|
|
* CreateFileMappingA (KERNEL32.46)
|
|
*
|
|
*/
|
|
int TranslateProtectionFlags(DWORD);
|
|
WINAPI HANDLE32 CreateFileMapping(HANDLE32 h,SECURITY_ATTRIBUTES *ats,
|
|
DWORD pot, DWORD sh, DWORD hlow, const char * lpName )
|
|
{
|
|
FILE_OBJECT *file_obj;
|
|
FILEMAP_OBJECT *filemap_obj;
|
|
int fd;
|
|
|
|
if (sh)
|
|
{
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
fd = open(lpName, O_CREAT, 0666);
|
|
#if 0
|
|
fd = open(DOS_GetUnixFileName(lpName), 0, 0666);
|
|
#endif
|
|
if(fd == -1)
|
|
{
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
file_obj = (FILE_OBJECT *)
|
|
CreateKernelObject(sizeof(FILE_OBJECT));
|
|
if(file_obj == NULL)
|
|
{
|
|
SetLastError(ERROR_UNKNOWN);
|
|
return 0;
|
|
}
|
|
filemap_obj = (FILEMAP_OBJECT *)
|
|
CreateKernelObject(sizeof(FILEMAP_OBJECT));
|
|
if(filemap_obj == NULL)
|
|
{
|
|
ReleaseKernelObject(file_obj);
|
|
SetLastError(ERROR_UNKNOWN);
|
|
return 0;
|
|
}
|
|
file_obj->common.magic = KERNEL_OBJECT_FILE;
|
|
file_obj->fd = fd;
|
|
file_obj->type = FILE_TYPE_DISK;
|
|
filemap_obj->common.magic = KERNEL_OBJECT_FILEMAP;
|
|
filemap_obj->file_obj = file_obj;
|
|
filemap_obj->prot = TranslateProtectionFlags(pot);
|
|
filemap_obj->size = hlow;
|
|
return (HANDLE32)filemap_obj;;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* MapViewOfFileEx (KERNEL32.386)
|
|
*
|
|
*/
|
|
WINAPI void *MapViewOfFileEx(HANDLE32 handle, DWORD access, DWORD offhi,
|
|
DWORD offlo, DWORD size, DWORD st)
|
|
{
|
|
if (!size) size = ((FILEMAP_OBJECT *)handle)->size;
|
|
return mmap ((caddr_t)st, size, ((FILEMAP_OBJECT *)handle)->prot,
|
|
MAP_ANON|MAP_PRIVATE,
|
|
((FILEMAP_OBJECT *)handle)->file_obj->fd,
|
|
offlo);
|
|
}
|
|
|
|
/***********************************************************************
|
|
* GetFileInformationByHandle (KERNEL32.219)
|
|
*
|
|
*/
|
|
DWORD WINAPI GetFileInformationByHandle(FILE_OBJECT *hFile,
|
|
BY_HANDLE_FILE_INFORMATION *lpfi)
|
|
{
|
|
struct stat file_stat;
|
|
int rc;
|
|
|
|
if(ValidateKernelObject((HANDLE32)hFile) != 0)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
if(hFile->common.magic != KERNEL_OBJECT_FILE)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
|
|
rc = fstat(hFile->fd, &file_stat);
|
|
if(rc == -1)
|
|
{
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return 0;
|
|
}
|
|
|
|
/* Translate the file attributes.
|
|
*/
|
|
lpfi->dwFileAttributes = 0;
|
|
if(file_stat.st_mode & S_IFREG)
|
|
lpfi->dwFileAttributes |= FILE_ATTRIBUTE_NORMAL;
|
|
if(file_stat.st_mode & S_IFDIR)
|
|
lpfi->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
|
|
if((file_stat.st_mode & S_IWRITE) == 0)
|
|
lpfi->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
|
|
|
|
/* Translate the file times. Use the last modification time
|
|
* for both the creation time and write time.
|
|
*/
|
|
UnixTimeToFileTime(file_stat.st_mtime, &(lpfi->ftCreationTime));
|
|
UnixTimeToFileTime(file_stat.st_mtime, &(lpfi->ftLastWriteTime));
|
|
UnixTimeToFileTime(file_stat.st_atime, &(lpfi->ftLastAccessTime));
|
|
|
|
lpfi->nFileSizeLow = file_stat.st_size;
|
|
lpfi->nNumberOfLinks = file_stat.st_nlink;
|
|
lpfi->nFileIndexLow = file_stat.st_ino;
|
|
|
|
/* Zero out currently unused fields.
|
|
*/
|
|
lpfi->dwVolumeSerialNumber = 0;
|
|
lpfi->nFileSizeHigh = 0;
|
|
lpfi->nFileIndexHigh = 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
static void UnixTimeToFileTime(time_t unix_time, FILETIME *filetime)
|
|
{
|
|
/* This isn't anywhere close to being correct, but should
|
|
* work for now.
|
|
*/
|
|
filetime->dwLowDateTime = (unix_time & 0x0000FFFF) << 16;
|
|
filetime->dwHighDateTime = (unix_time & 0xFFFF0000) >> 16;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetFileType (KERNEL32.222)
|
|
*
|
|
* GetFileType currently only supports stdin, stdout, and stderr, which
|
|
* are considered to be of type FILE_TYPE_CHAR.
|
|
*/
|
|
DWORD GetFileType(FILE_OBJECT *hFile)
|
|
{
|
|
if(ValidateKernelObject((HANDLE32)hFile) != 0)
|
|
{
|
|
SetLastError(ERROR_UNKNOWN);
|
|
return FILE_TYPE_UNKNOWN;
|
|
}
|
|
if(hFile->common.magic != KERNEL_OBJECT_FILE)
|
|
{
|
|
SetLastError(ERROR_UNKNOWN);
|
|
return FILE_TYPE_UNKNOWN;
|
|
}
|
|
|
|
return hFile->type;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* GetStdHandle (KERNEL32.276)
|
|
*/
|
|
HANDLE32 GetStdHandle(DWORD nStdHandle)
|
|
{
|
|
HANDLE32 rc;
|
|
|
|
switch(nStdHandle)
|
|
{
|
|
case STD_INPUT_HANDLE:
|
|
rc = (HANDLE32)hstdin;
|
|
break;
|
|
|
|
case STD_OUTPUT_HANDLE:
|
|
rc = (HANDLE32)hstdout;
|
|
break;
|
|
|
|
case STD_ERROR_HANDLE:
|
|
rc = (HANDLE32)hstderr;
|
|
break;
|
|
|
|
default:
|
|
rc = INVALID_HANDLE_VALUE;
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
break;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* SetFilePointer (KERNEL32.492)
|
|
*
|
|
* Luckily enough, this function maps almost directly into an lseek
|
|
* call, the exception being the use of 64-bit offsets.
|
|
*/
|
|
DWORD SetFilePointer(FILE_OBJECT *hFile, LONG distance, LONG *highword,
|
|
DWORD method)
|
|
{
|
|
int rc;
|
|
|
|
if(ValidateKernelObject((HANDLE32)hFile) != 0)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return ((DWORD)0xFFFFFFFF);
|
|
}
|
|
if(hFile->common.magic != KERNEL_OBJECT_FILE)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return ((DWORD)0xFFFFFFFF);
|
|
}
|
|
|
|
if(highword != NULL)
|
|
{
|
|
if(*highword != 0)
|
|
{
|
|
dprintf_win32(stddeb, "SetFilePointer: 64-bit offsets not yet supported.\n");
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
rc = lseek(hFile->fd, distance, method);
|
|
if(rc == -1)
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return rc;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* WriteFile (KERNEL32.578)
|
|
*/
|
|
BOOL WriteFile(FILE_OBJECT *hFile, LPVOID lpBuffer, DWORD numberOfBytesToWrite,
|
|
LPDWORD numberOfBytesWritten, LPOVERLAPPED lpOverlapped)
|
|
{
|
|
int written;
|
|
|
|
if(ValidateKernelObject((HANDLE32)hFile) != 0)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
if(hFile->common.magic != KERNEL_OBJECT_FILE)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
|
|
written = write(hFile->fd, lpBuffer, numberOfBytesToWrite);
|
|
if(numberOfBytesWritten)
|
|
*numberOfBytesWritten = written;
|
|
|
|
return 1;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* ReadFile (KERNEL32.428)
|
|
*/
|
|
BOOL ReadFile(FILE_OBJECT *hFile, LPVOID lpBuffer, DWORD numtoread,
|
|
LPDWORD numread, LPOVERLAPPED lpOverlapped)
|
|
{
|
|
int actual_read;
|
|
|
|
if(ValidateKernelObject((HANDLE32)hFile) != 0)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
if(hFile->common.magic != KERNEL_OBJECT_FILE)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return 0;
|
|
}
|
|
|
|
actual_read = read(hFile->fd, lpBuffer, numtoread);
|
|
if(actual_read == -1)
|
|
{
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return 0;
|
|
}
|
|
if(numread)
|
|
*numread = actual_read;
|
|
|
|
return 1;
|
|
}
|
|
|
|
/*************************************************************************
|
|
* CreateFile (KERNEL32.45)
|
|
*
|
|
* Doesn't support character devices, pipes, template files, or a
|
|
* lot of the 'attributes' flags yet.
|
|
*/
|
|
HANDLE32 CreateFileA(LPSTR filename, DWORD access, DWORD sharing,
|
|
LPSECURITY_ATTRIBUTES security, DWORD creation,
|
|
DWORD attributes, HANDLE32 template)
|
|
{
|
|
int access_flags, create_flags;
|
|
int fd;
|
|
FILE_OBJECT *file_obj;
|
|
int type;
|
|
|
|
/* Translate the various flags to Unix-style.
|
|
*/
|
|
access_flags = TranslateAccessFlags(access);
|
|
create_flags = TranslateCreationFlags(creation);
|
|
|
|
if(template)
|
|
dprintf_win32(stddeb, "CreateFile: template handles not supported.\n");
|
|
|
|
/* If the name starts with '\\?' or '\\.', ignore the first 3 chars.
|
|
*/
|
|
if(!strncmp(filename, "\\\\?", 3) || !strncmp(filename, "\\\\.", 3))
|
|
filename += 3;
|
|
|
|
/* If the name still starts with '\\', it's a UNC name.
|
|
*/
|
|
if(!strncmp(filename, "\\\\", 2))
|
|
{
|
|
dprintf_win32(stddeb, "CreateFile: UNC names not supported.\n");
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
|
|
/* If the name is either CONIN$ or CONOUT$, give them stdin
|
|
* or stdout, respectively.
|
|
*/
|
|
if(!strcmp(filename, "CONIN$"))
|
|
{
|
|
type = FILE_TYPE_CHAR;
|
|
fd = 0;
|
|
}
|
|
else if(!strcmp(filename, "CONOUT$"))
|
|
{
|
|
type = FILE_TYPE_CHAR;
|
|
fd = 1;
|
|
}
|
|
else
|
|
{
|
|
type = FILE_TYPE_DISK;
|
|
|
|
/* Try to open the file.
|
|
*/
|
|
fd = open(DOS_GetUnixFileName(filename),
|
|
access_flags | create_flags, 0666);
|
|
if(fd == -1)
|
|
{
|
|
SetLastError(ErrnoToLastError(errno));
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
}
|
|
|
|
/* We seem to have succeeded, so allocate a kernel object
|
|
* and set it up.
|
|
*/
|
|
file_obj = (FILE_OBJECT *)CreateKernelObject(sizeof(FILE_OBJECT));
|
|
if(file_obj == NULL)
|
|
{
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
return INVALID_HANDLE_VALUE;
|
|
}
|
|
file_obj->common.magic = KERNEL_OBJECT_FILE;
|
|
file_obj->fd = fd;
|
|
file_obj->type = type;
|
|
file_obj->misc_flags = attributes;
|
|
file_obj->access_flags = access_flags;
|
|
file_obj->create_flags = create_flags;
|
|
|
|
return (HANDLE32)file_obj;
|
|
}
|
|
|
|
int CloseFileHandle(FILE_OBJECT *hFile)
|
|
{
|
|
/* If it's one of the 3 standard handles, don't really
|
|
* close it.
|
|
*/
|
|
if(hFile->fd > 2)
|
|
close(hFile->fd);
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int TranslateAccessFlags(DWORD access_flags)
|
|
{
|
|
int rc = 0;
|
|
|
|
switch(access_flags)
|
|
{
|
|
case GENERIC_READ:
|
|
rc = O_RDONLY;
|
|
break;
|
|
|
|
case GENERIC_WRITE:
|
|
rc = O_WRONLY;
|
|
break;
|
|
|
|
case (GENERIC_READ | GENERIC_WRITE):
|
|
rc = O_RDWR;
|
|
break;
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int TranslateCreationFlags(DWORD create_flags)
|
|
{
|
|
int rc = 0;
|
|
|
|
switch(create_flags)
|
|
{
|
|
case CREATE_NEW:
|
|
rc = O_CREAT | O_EXCL;
|
|
break;
|
|
|
|
case CREATE_ALWAYS:
|
|
rc = O_CREAT | O_TRUNC;
|
|
break;
|
|
|
|
case OPEN_EXISTING:
|
|
rc = 0;
|
|
break;
|
|
|
|
case OPEN_ALWAYS:
|
|
rc = O_CREAT;
|
|
break;
|
|
|
|
case TRUNCATE_EXISTING:
|
|
rc = O_TRUNC;
|
|
break;
|
|
}
|
|
|
|
return rc;
|
|
}
|