source: trunk/src/kernel32/old/oslibdos.cpp@ 1036

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

Backup copy of old kernel32

File size: 5.4 KB
Line 
1/* $Id: oslibdos.cpp,v 1.1 1999-09-15 23:32:59 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
25APIRET APIENTRY DosAliasMem(PVOID pb, ULONG cb, PPVOID ppbAlias, ULONG fl);
26
27//******************************************************************************
28//******************************************************************************
29DWORD OSLibDosAliasMem(LPVOID pb, ULONG cb, LPVOID *ppbAlias, ULONG fl)
30{
31 return DosAliasMem(pb, cb, ppbAlias, fl);
32}
33//******************************************************************************
34//******************************************************************************
35DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags)
36{
37 return DosAllocMem(lplpMemAddr, size, flags | flAllocMem);
38}
39//******************************************************************************
40//******************************************************************************
41DWORD OSLibDosFreeMem(LPVOID lpMemAddr)
42{
43 return DosFreeMem(lpMemAddr);
44}
45//******************************************************************************
46//******************************************************************************
47DWORD OSLibDosQueryMem(LPVOID lpMemAddr, DWORD *lpRangeSize, DWORD *lpAttr)
48{
49 return DosQueryMem(lpMemAddr, lpRangeSize, lpAttr);
50}
51//******************************************************************************
52//******************************************************************************
53DWORD OSLibDosSetMem(LPVOID lpMemAddr, DWORD size, DWORD flags)
54{
55 APIRET rc;
56
57 rc = DosSetMem(lpMemAddr, size, flags);
58 switch(rc) {
59 case ERROR_INVALID_ADDRESS:
60 return OSLIB_ERROR_INVALID_ADDRESS;
61 case ERROR_ACCESS_DENIED:
62 return OSLIB_ERROR_ACCESS_DENIED;
63 default:
64 return rc;
65 }
66}
67//******************************************************************************
68//******************************************************************************
69DWORD OSLibDosOpen(char *lpszFileName, DWORD flags)
70{
71 APIRET rc;
72 HFILE hFile;
73 ULONG ulAction;
74 DWORD os2flags = OPEN_FLAGS_NOINHERIT;
75
76
77 if(flags & OSLIB_ACCESS_READONLY)
78 os2flags |= OPEN_ACCESS_READONLY;
79 else
80 if(flags & OSLIB_ACCESS_READWRITE)
81 os2flags |= OPEN_ACCESS_READWRITE;
82
83 if(flags & OSLIB_ACCESS_SHAREDENYNONE)
84 os2flags |= OPEN_SHARE_DENYNONE;
85 else
86 if(flags & OSLIB_ACCESS_SHAREDENYREAD)
87 os2flags |= OPEN_SHARE_DENYREAD;
88 else
89 if(flags & OSLIB_ACCESS_SHAREDENYWRITE)
90 os2flags |= OPEN_SHARE_DENYWRITE;
91
92 rc = DosOpen(lpszFileName, /* File path name */
93 &hFile, /* File handle */
94 &ulAction, /* Action taken */
95 0L, /* File primary allocation */
96 0L, /* File attribute */
97 OPEN_ACTION_FAIL_IF_NEW |
98 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
99 os2flags,
100 0L); /* No extended attribute */
101
102 if(rc) {
103 return 0;
104 }
105 else return hFile;
106}
107//******************************************************************************
108//******************************************************************************
109DWORD OSLibDosClose(DWORD hFile)
110{
111 return DosClose(hFile);
112}
113//******************************************************************************
114//******************************************************************************
115DWORD OSLibDosGetFileSize(DWORD hFile)
116{
117 ULONG ulLocal, filesize = 0;
118
119 DosSetFilePtr(hFile, 0L, FILE_BEGIN, &ulLocal);
120 DosSetFilePtr(hFile, 0L, FILE_END, &filesize);
121 DosSetFilePtr(hFile, 0L, FILE_BEGIN, &ulLocal);
122 return filesize;
123}
124//******************************************************************************
125//******************************************************************************
126DWORD OSLibDosRead(DWORD hFile, LPVOID lpBuffer, DWORD size, DWORD *nrBytesRead)
127{
128 return DosRead(hFile, lpBuffer, size, nrBytesRead);
129}
130//******************************************************************************
131//******************************************************************************
132DWORD OSLibDosWrite(DWORD hFile, LPVOID lpBuffer, DWORD size, DWORD *nrBytesWritten)
133{
134 return DosWrite(hFile, lpBuffer, size, nrBytesWritten);
135}
136//******************************************************************************
137//******************************************************************************
138DWORD OSLibDosSetFilePtr(DWORD hFile, DWORD offset, DWORD method)
139{
140 DWORD os2method;
141 DWORD newoffset;
142 APIRET rc;
143
144 switch(method) {
145 case OSLIB_SETPTR_FILE_CURRENT:
146 os2method = FILE_CURRENT;
147 break;
148 case OSLIB_SETPTR_FILE_BEGIN:
149 os2method = FILE_BEGIN ;
150 break;
151 case OSLIB_SETPTR_FILE_END:
152 os2method = FILE_END;
153 break;
154 default:
155 return OSLIB_ERROR_INVALID_PARAMETER;
156 }
157 rc = DosSetFilePtr(hFile, offset, os2method, &newoffset);
158 if(rc) {
159 return -1;
160 }
161 else return newoffset;
162}
163//******************************************************************************
164//******************************************************************************
Note: See TracBrowser for help on using the repository browser.