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