Release 960913

Wed Sep 11 18:08:30 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [windows/event.c]
	Minor improvements in setting event time in MSG struct.

	* [windows/hook.c]
	Removed an useless 'unimplemented hook' message.

	* [windows/win.c]
	Added a WH_CBT hook call during window creation: good for CTL3D.DLL

Wed Sep 11 11:19:56 1996  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>
	* [loader/pe_image.c]
	Fixed imports with no name/ordinal list (MFC30.DLL).
	Added borland style - ordinal import (wsock32.dll).

	* [files/file.c] [win32/file.c] [if1632/kernel.spec]
	  [if1632/kernel32.spec] [include/windows.h]
	Win32 and Win16 code use the same filehandles/HFILEs.
	Added SetEndOfFile, MoveFile*, diverse *W functions.

	* [loader/pe_image.c]
	Fixed argument 2 to DllEntry.

	* [misc/comm.c]
	Adapt to filehandling changes, win32 code still broken.

	* [misc/registry.c]
	Use Wine filehandling.
	StartupRegistry to add startup-detected registry entries.

	* [miscemu/dpmi.c] [miscemu/int21.c]
	Some missing interrupt-functions added.

	* [if1632/gdi32.spec][if1632/user32.spec]
	Some thunks to 16 bit equivalent functions added.

Sat Sep  7 11:36:57 EDT 1996  Matthew Ghio <ghio@netcom.com>

	* [misc/winsocket.c]
	Rewrote WINSOCK_select() and WSAFDIsSet() to properly convert
	Windows fd_set structs.

	* [if1632/winsock.spec]
	Corrected arguments to select().
diff --git a/files/file.c b/files/file.c
index d638140..ee4a7e8 100644
--- a/files/file.c
+++ b/files/file.c
@@ -18,6 +18,7 @@
 #include <utime.h>
 
 #include "windows.h"
+#include "winerror.h"
 #include "directory.h"
 #include "dos_fs.h"
 #include "drive.h"
@@ -42,6 +43,7 @@
     char               *unix_name;
     WORD                filedate;
     WORD                filetime;
+    DWORD               type;         /* Type for win32 apps */
 } DOS_FILE;
 
 /* Global files array */
@@ -72,6 +74,7 @@
     file->count = 1;
     file->unix_handle = -1;
     file->unix_name = NULL;
+    file->type = FILE_TYPE_DISK;
     return file;
 }
 
@@ -217,7 +220,7 @@
  *
  * Close all open files of a given PDB. Used on task termination.
  */
-void FILE_CloseAllFiles( HANDLE hPDB )
+void FILE_CloseAllFiles( HANDLE16 hPDB )
 {
     BYTE *files;
     WORD count;
@@ -314,7 +317,7 @@
     struct stat st;
 
     if (!(file = FILE_Alloc())) return NULL;
-    if ((file->unix_handle = open( name, mode )) == -1)
+    if ((file->unix_handle = open( name, mode, 0666 )) == -1)
     {
         if (Options.allowReadOnly && (mode == O_RDWR))
         {
@@ -346,9 +349,11 @@
 /***********************************************************************
  *           FILE_Open
  */
-static DOS_FILE *FILE_Open( LPCSTR path, int mode )
+HFILE FILE_Open( LPCSTR path, INT32 mode )
 {
     const char *unixName;
+    DOS_FILE *file;
+    HFILE handle;
 
     dprintf_file(stddeb, "FILE_Open: '%s' %04x\n", path, mode );
     if ((unixName = DOSFS_IsDevice( path )) != NULL)
@@ -358,11 +363,16 @@
         {
             dprintf_file(stddeb, "FILE_Open: Non-existing device\n");
             DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
-            return NULL;
+            return HFILE_ERROR;
         }
     }
-    else if (!(unixName = DOSFS_GetUnixFileName( path, TRUE ))) return NULL;
-    return FILE_OpenUnixFile( unixName, mode );
+    else if (!(unixName = DOSFS_GetUnixFileName( path, TRUE )))
+        return HFILE_ERROR;
+
+    if (!(file = FILE_OpenUnixFile( unixName, mode ))) return HFILE_ERROR;
+    if ((handle = FILE_AllocTaskHandle( file )) == HFILE_ERROR)
+        FILE_Close( file );
+    return handle;
 }
 
 
@@ -434,7 +444,7 @@
  *
  * Get the date and time of a file.
  */
-int FILE_GetDateTime( HFILE hFile, WORD *pdate, WORD *ptime, BOOL refresh )
+int FILE_GetDateTime( HFILE hFile, WORD *pdate, WORD *ptime, BOOL32 refresh )
 {
     DOS_FILE *file;
 
@@ -596,6 +606,8 @@
     {
         lstrcpyn32A( buffer, DOSFS_GetDosTrueName( buffer, FALSE ), 144 );
         dprintf_file( stddeb, "GetTempFileName: returning %s\n", buffer );
+	if (-1==access(DOSFS_GetUnixFileName(buffer,TRUE),W_OK))
+	    fprintf(stderr,"Warning: GetTempFileName returns '%s', which doesn't seem to be writeable. Please check your configuration file if this generates a failure.\n",buffer);
         return unique;
     }
 
@@ -617,6 +629,8 @@
 
     lstrcpyn32A( buffer, DOSFS_GetDosTrueName( buffer, FALSE ), 144 );
     dprintf_file( stddeb, "GetTempFileName: returning %s\n", buffer );
+    if (-1==access(DOSFS_GetUnixFileName(buffer,TRUE),W_OK))
+	fprintf(stderr,"Warning: GetTempFileName returns '%s', which doesn't seem to be writeable. Please check your configuration file if this generates a failure.\n",buffer);
     return num;
 }
 
@@ -965,11 +979,46 @@
 
 
 /***********************************************************************
- *           _lread   (KERNEL.82)
+ *           WIN16_hread
  */
-INT _lread( HFILE hFile, SEGPTR buffer, WORD count )
+LONG WIN16_hread( HFILE hFile, SEGPTR buffer, LONG count )
 {
-    return (INT)_hread( hFile, buffer, (LONG)count );
+    LONG maxlen;
+
+    dprintf_file( stddeb, "_hread16: %d %08lx %ld\n",
+                  hFile, (DWORD)buffer, count );
+
+    /* Some programs pass a count larger than the allocated buffer */
+    maxlen = GetSelectorLimit( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
+    if (count > maxlen) count = maxlen;
+    return FILE_Read( hFile, PTR_SEG_TO_LIN(buffer), count );
+}
+
+
+/***********************************************************************
+ *           WIN16_lread
+ */
+UINT16 WIN16_lread( HFILE hFile, SEGPTR buffer, UINT16 count )
+{
+    return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
+}
+
+
+/***********************************************************************
+ *           _lread32   (KERNEL32.596)
+ */
+UINT32 _lread32( HFILE hFile, LPVOID buffer, UINT32 count )
+{
+    return (UINT32)FILE_Read( hFile, buffer, (LONG)count );
+}
+
+
+/***********************************************************************
+ *           _lread16   (KERNEL.82)
+ */
+UINT16 _lread16( HFILE hFile, LPVOID buffer, UINT16 count )
+{
+    return (UINT16)FILE_Read( hFile, buffer, (LONG)count );
 }
 
 
@@ -1010,9 +1059,9 @@
 
 
 /***********************************************************************
- *           _llseek   (KERNEL.84)
+ *           _llseek   (KERNEL.84) (KERNEL32.594)
  */
-LONG _llseek( HFILE hFile, LONG lOffset, INT nOrigin )
+LONG _llseek( HFILE hFile, LONG lOffset, INT32 nOrigin )
 {
     DOS_FILE *file;
     int origin, result;
@@ -1039,9 +1088,7 @@
  */
 HFILE _lopen( LPCSTR path, INT32 mode )
 {
-    DOS_FILE *file;
-    int unixMode;
-    HFILE handle;
+    INT32 unixMode;
 
     dprintf_file(stddeb, "_lopen('%s',%04x)\n", path, mode );
 
@@ -1058,38 +1105,33 @@
         unixMode = O_RDONLY;
         break;
     }
-    if (!(file = FILE_Open( path, unixMode ))) return HFILE_ERROR;
-    if ((handle = FILE_AllocTaskHandle( file )) == HFILE_ERROR)
-        FILE_Close( file );
-    return handle;
+    return FILE_Open( path, unixMode );
 }
 
 
 /***********************************************************************
- *           _lwrite   (KERNEL.86)
+ *           _lwrite16   (KERNEL.86)
  */
-INT _lwrite( HFILE hFile, LPCSTR buffer, WORD count )
+UINT16 _lwrite16( HFILE hFile, LPCSTR buffer, UINT16 count )
 {
-    return (INT)_hwrite( hFile, buffer, (LONG)count );
+    return (UINT16)_hwrite( hFile, buffer, (LONG)count );
+}
+
+/***********************************************************************
+ *           _lwrite32   (KERNEL.86)
+ */
+UINT32 _lwrite32( HFILE hFile, LPCSTR buffer, UINT32 count )
+{
+    return (UINT32)_hwrite( hFile, buffer, (LONG)count );
 }
 
 
 /***********************************************************************
  *           _hread   (KERNEL.349)
  */
-LONG _hread( HFILE hFile, SEGPTR buffer, LONG count )
+LONG _hread( HFILE hFile, LPVOID buffer, LONG count)
 {
-#ifndef WINELIB
-    LONG maxlen;
-
-    dprintf_file( stddeb, "_hread: %d %08lx %ld\n",
-                  hFile, (DWORD)buffer, count );
-
-    /* Some programs pass a count larger than the allocated buffer */
-    maxlen = GetSelectorLimit( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
-    if (count > maxlen) count = maxlen;
-#endif
-    return FILE_Read( hFile, PTR_SEG_TO_LIN(buffer), count );
+    return FILE_Read( hFile, buffer, count );
 }
 
 
@@ -1117,9 +1159,9 @@
 
 
 /***********************************************************************
- *           SetHandleCount   (KERNEL.199)
+ *           SetHandleCount16   (KERNEL.199)
  */
-WORD SetHandleCount( WORD count )
+UINT16 SetHandleCount16( UINT16 count )
 {
     HANDLE hPDB = GetCurrentPDB();
     PDB *pdb = (PDB *)GlobalLock16( hPDB );
@@ -1345,3 +1387,31 @@
     free(xpath);
     return ret;
 }
+
+
+/***********************************************************************
+ *           FILE_SetFileType
+ */
+BOOL32 FILE_SetFileType( HFILE hFile, DWORD type )
+{
+    DOS_FILE *file = FILE_GetFile(hFile);
+    if (!file) return FALSE;
+    file->type = type;
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           GetFileType   (KERNEL32.222)
+ */
+DWORD GetFileType( HFILE hFile )
+{
+    DOS_FILE *file = FILE_GetFile(hFile);
+    
+    if (!file)
+    {
+    	SetLastError( ERROR_INVALID_HANDLE );
+    	return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
+    }
+    return file->type;
+}