[10083] | 1 | /* $Id: lfile.cpp,v 1.8 2003-05-12 15:29:09 sandervl Exp $ */
|
---|
[100] | 2 |
|
---|
[51] | 3 | /*
|
---|
| 4 | *
|
---|
| 5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 6 | *
|
---|
| 7 | */
|
---|
| 8 | /*
|
---|
| 9 | * Win32 compatibility file functions for OS/2
|
---|
| 10 | *
|
---|
| 11 | * 1998/06/12 PH Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
| 12 | *
|
---|
[64] | 13 | * @(#) LFILE.C 1.0.0 1998/06/12 PH added HandleManager support
|
---|
[51] | 14 | * 1.1.0 1998/08/29 KSO corrected error codes and forwarded
|
---|
[64] | 15 | * to Win32 file api as NT/95 does.
|
---|
| 16 | * 1.1.1 1999/06/09 PH NOTE: only forard to KERNEL32:FILEIO
|
---|
| 17 | * calls, never do anything else !
|
---|
[51] | 18 | */
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | /*****************************************************************************
|
---|
| 22 | * Includes *
|
---|
| 23 | *****************************************************************************/
|
---|
| 24 |
|
---|
| 25 | #include <os2win.h>
|
---|
| 26 |
|
---|
[2802] | 27 | #define DBG_LOCALLOG DBG_lfile
|
---|
| 28 | #include "dbglocal.h"
|
---|
[51] | 29 |
|
---|
[2802] | 30 |
|
---|
[51] | 31 | /*****************************************************************************
|
---|
| 32 | * Name : HFILE WIN32API _lclose
|
---|
| 33 | * Purpose : forward call to CloseHandle
|
---|
| 34 | * Parameters:
|
---|
| 35 | * Variables :
|
---|
| 36 | * Result :
|
---|
| 37 | * Remark : Depends on CloseHandle working.
|
---|
| 38 | * Status : Tested
|
---|
| 39 | *
|
---|
| 40 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 41 | *****************************************************************************/
|
---|
| 42 |
|
---|
| 43 | HFILE WIN32API _lclose(HFILE arg1)
|
---|
| 44 | {
|
---|
[64] | 45 | dprintf(("KERNEL32: _lclose(%08xh)\n",
|
---|
| 46 | arg1));
|
---|
| 47 |
|
---|
| 48 | if (CloseHandle(arg1))
|
---|
| 49 | return 0;
|
---|
| 50 | else
|
---|
| 51 | return -1;
|
---|
[51] | 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | /*****************************************************************************
|
---|
| 56 | * Name : HFILE WIN32API _lcreat
|
---|
| 57 | * Purpose : forward call to CreateFileA
|
---|
| 58 | * Parameters:
|
---|
| 59 | * Variables :
|
---|
| 60 | * Result :
|
---|
| 61 | * Remark : Depends on CreateFile working.
|
---|
| 62 | * Status : Tested
|
---|
| 63 | *
|
---|
| 64 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 65 | *****************************************************************************/
|
---|
| 66 |
|
---|
| 67 | HFILE WIN32API _lcreat(LPCSTR arg1,
|
---|
[64] | 68 | int arg2)
|
---|
[51] | 69 | {
|
---|
[64] | 70 | HANDLE hFile;
|
---|
[51] | 71 |
|
---|
[64] | 72 | dprintf(("KERNEL32: _lcreat(%s, %08xh)\n",
|
---|
| 73 | arg1,
|
---|
| 74 | arg2));
|
---|
[51] | 75 |
|
---|
[64] | 76 | //if (arg2 & ~(1 | 2 | 4))
|
---|
| 77 | // dprintf(("KERNEL32: Warning: _lcreat has unknown flag(s) set - fails.\n"));
|
---|
| 78 |
|
---|
| 79 | //SetLastError(0); - CreateFileA sets error
|
---|
| 80 | hFile = CreateFileA(arg1, /* filename */
|
---|
| 81 | GENERIC_READ | GENERIC_WRITE, /* readwrite access */
|
---|
| 82 | FILE_SHARE_READ | FILE_SHARE_WRITE,/* share all */
|
---|
| 83 | NULL, /* ignore scurity */
|
---|
| 84 | CREATE_ALWAYS, /* create (trunkate don't work) */
|
---|
| 85 | arg2 & 0x3fb7, /* so M$ does (that is more attributes than I could find in the headers and in the docs!) */
|
---|
| 86 | NULL); /* no template */
|
---|
| 87 |
|
---|
| 88 | dprintf(("KERNEL32: _lcreat returns %08xh.\n",
|
---|
| 89 | hFile));
|
---|
| 90 | return hFile;
|
---|
[51] | 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | /*****************************************************************************
|
---|
| 95 | * Name : HFILE WIN32API _lopen
|
---|
| 96 | * Purpose : forward call to CreateFileA
|
---|
| 97 | * Parameters:
|
---|
| 98 | * Variables :
|
---|
| 99 | * Result :
|
---|
| 100 | * Remark :
|
---|
| 101 | * Status : Tested
|
---|
| 102 | *
|
---|
| 103 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 104 | *****************************************************************************/
|
---|
| 105 |
|
---|
| 106 | HFILE WIN32API _lopen(LPCSTR pszFileName,
|
---|
[10083] | 107 | int mode)
|
---|
[51] | 108 | {
|
---|
[64] | 109 | ULONG ulAccess = 0;
|
---|
| 110 | ULONG ulShare;
|
---|
| 111 | HANDLE hFile;
|
---|
[51] | 112 |
|
---|
[64] | 113 | dprintf(("KERNEL32: _lopen(%s, %08xh)\n",
|
---|
| 114 | pszFileName,
|
---|
[10083] | 115 | mode));
|
---|
[51] | 116 |
|
---|
[10083] | 117 | if (mode & ~(OF_READ|OF_READWRITE|OF_WRITE|OF_SHARE_COMPAT|OF_SHARE_DENY_NONE|OF_SHARE_DENY_READ|OF_SHARE_DENY_WRITE|OF_SHARE_EXCLUSIVE))
|
---|
[64] | 118 | dprintf(("KERNEL32: (warn) _lopen has unknown flag(s) set.\n"));
|
---|
[51] | 119 |
|
---|
[64] | 120 | /* Access */
|
---|
[10083] | 121 | switch(mode & 0x03)
|
---|
| 122 | {
|
---|
| 123 | case OF_READ: ulAccess = GENERIC_READ; break;
|
---|
| 124 | case OF_WRITE: ulAccess = GENERIC_WRITE; break;
|
---|
| 125 | case OF_READWRITE: ulAccess = GENERIC_READ | GENERIC_WRITE; break;
|
---|
| 126 | default: ulAccess = 0; break;
|
---|
| 127 | }
|
---|
[51] | 128 |
|
---|
[64] | 129 | /* Share */
|
---|
[10083] | 130 | ulShare = mode & (OF_SHARE_COMPAT | OF_SHARE_DENY_NONE | OF_SHARE_DENY_READ | OF_SHARE_DENY_WRITE | OF_SHARE_EXCLUSIVE);
|
---|
[64] | 131 | if (ulShare == OF_SHARE_DENY_READ)
|
---|
| 132 | ulShare = FILE_SHARE_WRITE;
|
---|
| 133 | else if (ulShare == OF_SHARE_DENY_WRITE)
|
---|
| 134 | ulShare = FILE_SHARE_READ;
|
---|
| 135 | else if (ulShare == OF_SHARE_DENY_NONE)
|
---|
| 136 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
| 137 | else if (ulShare == OF_SHARE_EXCLUSIVE)
|
---|
| 138 | ulShare = 0; //no share
|
---|
| 139 | else if (ulShare == OF_SHARE_COMPAT)
|
---|
| 140 | ulShare = FILE_SHARE_READ | FILE_SHARE_WRITE;
|
---|
| 141 | else
|
---|
| 142 | {
|
---|
| 143 | dprintf(("KERNEL32: _lopen - warning incorrect value for arg2 (or incorrect implementation...)\n"));
|
---|
| 144 | ulShare = 0;
|
---|
| 145 | }
|
---|
[51] | 146 |
|
---|
[64] | 147 | hFile = CreateFileA(pszFileName, /* filename */
|
---|
| 148 | ulAccess, /* */
|
---|
| 149 | ulShare, /* */
|
---|
| 150 | NULL, /* ignore scurity */
|
---|
| 151 | OPEN_EXISTING, /* open existing file, fail if new */
|
---|
| 152 | FILE_ATTRIBUTE_NORMAL, /* normal attribs - no flags */ //m$ sets this to 0
|
---|
| 153 | NULL); /* no template */
|
---|
[51] | 154 |
|
---|
[64] | 155 | dprintf(("KERNEL32: _lopen returns %08xh.\n",
|
---|
| 156 | hFile));
|
---|
| 157 |
|
---|
[1155] | 158 | // map correct return code for _lopen
|
---|
| 159 | if (hFile != INVALID_HANDLE_VALUE)
|
---|
| 160 | return hFile;
|
---|
| 161 | else
|
---|
| 162 | return HFILE_ERROR;
|
---|
[51] | 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 | /*****************************************************************************
|
---|
| 167 | * Name : HFILE WIN32API _lread
|
---|
| 168 | * Purpose : forward call to ReadFile
|
---|
| 169 | * Parameters:
|
---|
| 170 | * Variables :
|
---|
| 171 | * Result :
|
---|
| 172 | * Remark : Depend on that ReadFile works properly.
|
---|
| 173 | * Status : Tested
|
---|
| 174 | *
|
---|
| 175 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 176 | *****************************************************************************/
|
---|
| 177 |
|
---|
| 178 | UINT WIN32API _lread(HFILE arg1,
|
---|
[64] | 179 | PVOID arg2,
|
---|
| 180 | UINT arg3)
|
---|
[51] | 181 | {
|
---|
[64] | 182 | ULONG rc;
|
---|
[51] | 183 |
|
---|
[1403] | 184 | // dprintf(("KERNEL32: _lread(%08xh, %08xh, %08xh)\n",
|
---|
| 185 | // arg1,
|
---|
| 186 | // arg2,
|
---|
| 187 | // arg3));
|
---|
[51] | 188 |
|
---|
[64] | 189 | if (!ReadFile(arg1,
|
---|
| 190 | arg2,
|
---|
| 191 | arg3,
|
---|
| 192 | &rc,
|
---|
| 193 | NULL))
|
---|
| 194 | rc = -1;
|
---|
[51] | 195 |
|
---|
[1403] | 196 | // dprintf(("KERNEL32: _lread returns %08xh.",
|
---|
| 197 | // rc));
|
---|
[64] | 198 |
|
---|
| 199 | return rc;
|
---|
[51] | 200 | }
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | /*****************************************************************************
|
---|
| 204 | * Name : HFILE WIN32API _llseek
|
---|
| 205 | * Purpose : forward call to SetFilePointer
|
---|
| 206 | * Parameters:
|
---|
| 207 | * Variables :
|
---|
| 208 | * Result :
|
---|
| 209 | * Remark : Depends on SetFilePointer working
|
---|
| 210 | * Status : Tested.
|
---|
| 211 | *
|
---|
| 212 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 213 | *****************************************************************************/
|
---|
| 214 |
|
---|
| 215 | LONG WIN32API _llseek(HFILE arg1,
|
---|
[64] | 216 | LONG arg2,
|
---|
| 217 | int arg3)
|
---|
[51] | 218 | {
|
---|
[64] | 219 | ULONG rc;
|
---|
[51] | 220 |
|
---|
[64] | 221 | dprintf(("KERNEL32: _llseek(%08xh, %08xh, %08xh)\n",
|
---|
| 222 | arg1,
|
---|
| 223 | arg2,
|
---|
| 224 | arg3));
|
---|
| 225 | if (!(arg3 == FILE_BEGIN ||
|
---|
| 226 | arg3 == FILE_CURRENT ||
|
---|
| 227 | arg3 == FILE_END))
|
---|
| 228 | {
|
---|
| 229 | dprintf(("KERNEL32: _llseek - incorrect origin - fails.\n" ));
|
---|
| 230 | return -1;
|
---|
| 231 | }
|
---|
[3714] | 232 |
|
---|
[64] | 233 | rc = SetFilePointer(arg1,
|
---|
| 234 | arg2,
|
---|
| 235 | NULL,
|
---|
[3714] | 236 | arg3);
|
---|
| 237 | //returns -1 on error (-1 == 0xffffffff)
|
---|
[64] | 238 |
|
---|
| 239 | dprintf(("KERNEL32: _llseek returns %08xh", rc));
|
---|
| 240 |
|
---|
| 241 | return rc;
|
---|
[51] | 242 | }
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | /*****************************************************************************
|
---|
| 246 | * Name : HFILE WIN32API _lwrite
|
---|
| 247 | * Purpose : forward call to WriteFile
|
---|
| 248 | * Parameters:
|
---|
| 249 | * Variables :
|
---|
| 250 | * Result :
|
---|
| 251 | * Remark : Depends on WriteFile working
|
---|
| 252 | * Status : Tested
|
---|
| 253 | *
|
---|
| 254 | * Author : Patrick Haller [Fri, 1998/06/12 03:44]
|
---|
| 255 | *****************************************************************************/
|
---|
| 256 |
|
---|
[21302] | 257 | UINT WIN32API _lwrite(HFILE hFile,
|
---|
| 258 | LPCSTR lpBuffer,
|
---|
| 259 | UINT cbWrite)
|
---|
[51] | 260 | {
|
---|
[64] | 261 | ULONG rc;
|
---|
[21302] | 262 | dprintf(("KERNEL32: _lwrite(%08xh, %08xh, %08xh)\n", hFile, lpBuffer, cbWrite));
|
---|
[51] | 263 |
|
---|
[21302] | 264 | if (!cbWrite)
|
---|
| 265 | rc = SetEndOfFile(hFile) ? 0 : HFILE_ERROR;
|
---|
| 266 | else
|
---|
| 267 | {
|
---|
| 268 | if (!WriteFile(hFile,
|
---|
| 269 | (PVOID)lpBuffer,
|
---|
| 270 | cbWrite,
|
---|
[64] | 271 | &rc,
|
---|
| 272 | NULL))
|
---|
[21302] | 273 | rc = HFILE_ERROR;
|
---|
| 274 | }
|
---|
[64] | 275 |
|
---|
[21302] | 276 | dprintf(("KERNEL32: _lwrite returns %08xh.\n", rc));
|
---|
[64] | 277 | return rc;
|
---|
[51] | 278 | }
|
---|
| 279 |
|
---|