source: trunk/src/kernel32/oslibdos.cpp@ 707

Last change on this file since 707 was 707, checked in by sandervl, 26 years ago

VirtualProtect bugfix + some additions to oslib

File size: 5.1 KB
Line 
1/* $Id: oslibdos.cpp,v 1.2 1999-08-26 15:05:14 sandervl Exp $ */
2
3/*
4 * Wrappers for OS/2 Dos* API
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_BASE
13#define INCL_DOSEXCEPTIONS
14#define INCL_DOSMEMMGR
15#define INCL_DOSPROCESS
16#include <os2wrap.h> //Odin32 OS/2 api wrappers
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20#include <win32type.h>
21#include <misc.h>
22#include "initterm.h"
23#include "oslibdos.h"
24
25//******************************************************************************
26//******************************************************************************
27DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags)
28{
29// return DosAllocMem(lplpMemAddr, size, flags | flAllocMem);
30 return DosAllocMem(lplpMemAddr, size, flags);
31}
32//******************************************************************************
33//******************************************************************************
34DWORD OSLibDosFreeMem(LPVOID lpMemAddr)
35{
36 return DosFreeMem(lpMemAddr);
37}
38//******************************************************************************
39//******************************************************************************
40DWORD OSLibDosQueryMem(LPVOID lpMemAddr, DWORD *lpRangeSize, DWORD *lpAttr)
41{
42 return DosQueryMem(lpMemAddr, lpRangeSize, lpAttr);
43}
44//******************************************************************************
45//******************************************************************************
46DWORD OSLibDosSetMem(LPVOID lpMemAddr, DWORD size, DWORD flags)
47{
48 APIRET rc;
49
50 rc = DosSetMem(lpMemAddr, size, flags);
51 switch(rc) {
52 case ERROR_INVALID_ADDRESS:
53 return OSLIB_ERROR_INVALID_ADDRESS;
54 case ERROR_ACCESS_DENIED:
55 return OSLIB_ERROR_ACCESS_DENIED;
56 default:
57 return rc;
58 }
59}
60//******************************************************************************
61//******************************************************************************
62DWORD OSLibDosOpen(char *lpszFileName, DWORD flags)
63{
64 APIRET rc;
65 HFILE hFile;
66 ULONG ulAction;
67 DWORD os2flags = OPEN_FLAGS_NOINHERIT;
68
69
70 if(flags & OSLIB_ACCESS_READONLY)
71 os2flags |= OPEN_ACCESS_READONLY;
72 else
73 if(flags & OSLIB_ACCESS_READWRITE)
74 os2flags |= OPEN_ACCESS_READWRITE;
75
76 if(flags & OSLIB_ACCESS_SHAREDENYNONE)
77 os2flags |= OPEN_SHARE_DENYNONE;
78 else
79 if(flags & OSLIB_ACCESS_SHAREDENYREAD)
80 os2flags |= OPEN_SHARE_DENYREAD;
81 else
82 if(flags & OSLIB_ACCESS_SHAREDENYWRITE)
83 os2flags |= OPEN_SHARE_DENYWRITE;
84
85 rc = DosOpen(lpszFileName, /* File path name */
86 &hFile, /* File handle */
87 &ulAction, /* Action taken */
88 0L, /* File primary allocation */
89 0L, /* File attribute */
90 OPEN_ACTION_FAIL_IF_NEW |
91 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
92 os2flags,
93 0L); /* No extended attribute */
94
95 if(rc) {
96 return 0;
97 }
98 else return hFile;
99}
100//******************************************************************************
101//******************************************************************************
102DWORD OSLibDosClose(DWORD hFile)
103{
104 return DosClose(hFile);
105}
106//******************************************************************************
107//******************************************************************************
108DWORD OSLibDosGetFileSize(DWORD hFile)
109{
110 ULONG ulLocal, filesize = 0;
111
112 DosSetFilePtr(hFile, 0L, FILE_BEGIN, &ulLocal);
113 DosSetFilePtr(hFile, 0L, FILE_END, &filesize);
114 DosSetFilePtr(hFile, 0L, FILE_BEGIN, &ulLocal);
115 return filesize;
116}
117//******************************************************************************
118//******************************************************************************
119DWORD OSLibDosRead(DWORD hFile, LPVOID lpBuffer, DWORD size, DWORD *nrBytesRead)
120{
121 return DosRead(hFile, lpBuffer, size, nrBytesRead);
122}
123//******************************************************************************
124//******************************************************************************
125DWORD OSLibDosWrite(DWORD hFile, LPVOID lpBuffer, DWORD size, DWORD *nrBytesWritten)
126{
127 return DosWrite(hFile, lpBuffer, size, nrBytesWritten);
128}
129//******************************************************************************
130//******************************************************************************
131DWORD OSLibDosSetFilePtr(DWORD hFile, DWORD offset, DWORD method)
132{
133 DWORD os2method;
134 DWORD newoffset;
135 APIRET rc;
136
137 switch(method) {
138 case OSLIB_SETPTR_FILE_CURRENT:
139 os2method = FILE_CURRENT;
140 break;
141 case OSLIB_SETPTR_FILE_BEGIN:
142 os2method = FILE_BEGIN ;
143 break;
144 case OSLIB_SETPTR_FILE_END:
145 os2method = FILE_END;
146 break;
147 default:
148 return OSLIB_ERROR_INVALID_PARAMETER;
149 }
150 rc = DosSetFilePtr(hFile, offset, os2method, &newoffset);
151 if(rc) {
152 return -1;
153 }
154 else return newoffset;
155}
156//******************************************************************************
157//******************************************************************************
Note: See TracBrowser for help on using the repository browser.