source: trunk/src/kernel32/Fileio.cpp@ 4230

Last change on this file since 4230 was 4230, checked in by sandervl, 25 years ago

memory map fixes + extra reg keys for init

File size: 41.0 KB
Line 
1/* $Id: Fileio.cpp,v 1.38 2000-09-10 21:54:05 sandervl Exp $ */
2
3/*
4 * Win32 File IO API functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
7 * Copyright 1998 Patrick Haller
8 *
9 * Some parts copied from Wine (CopyFileExA/W)
10 *
11 * Copyright 1993 John Burton
12 * Copyright 1996 Alexandre Julliard
13 *
14 *
15 * Project Odin Software License can be found in LICENSE.TXT
16 *
17 */
18
19
20/*****************************************************************************
21 * Includes *
22 *****************************************************************************/
23
24#include <odin.h>
25#include <odinwrap.h>
26#include <os2sel.h>
27
28#include <os2win.h>
29#include <stdlib.h>
30#include <string.h>
31#include "unicode.h"
32#include <heapstring.h>
33#include "handlemanager.h"
34#include "oslibdos.h"
35
36#define DBG_LOCALLOG DBG_fileio
37#include "dbglocal.h"
38
39ODINDEBUGCHANNEL(KERNEL32-FILEIO)
40
41//******************************************************************************
42//******************************************************************************
43ODINFUNCTION7(HFILE, CreateFileA,
44 LPCSTR, lpszName,
45 DWORD, fdwAccess,
46 DWORD, fdwShareMode,
47 LPSECURITY_ATTRIBUTES, lpsa,
48 DWORD, fdwCreate,
49 DWORD, fdwAttrsAndFlags,
50 HANDLE, hTemplateFile)
51{
52 dprintf(("CreateFileA %s", lpszName));
53 return(HMCreateFile(lpszName,
54 fdwAccess,
55 fdwShareMode,
56 lpsa,
57 fdwCreate,
58 fdwAttrsAndFlags,
59 hTemplateFile));
60}
61
62//******************************************************************************
63//******************************************************************************
64ODINFUNCTION7(HFILE, CreateFileW,
65 LPCWSTR, arg1,
66 DWORD, arg2,
67 DWORD, arg3,
68 PSECURITY_ATTRIBUTES, arg4,
69 DWORD, arg5,
70 DWORD, arg6,
71 HANDLE, arg7)
72{
73 HANDLE rc;
74 char *astring;
75
76 astring = UnicodeToAsciiString((LPWSTR)arg1);
77 rc = CreateFileA(astring, arg2, arg3, arg4, arg5, arg6, arg7);
78 FreeAsciiString(astring);
79 return(rc);
80}
81//******************************************************************************
82//******************************************************************************
83ODINFUNCTION2(HANDLE, FindFirstFileA,
84 LPCSTR, lpFileName,
85 WIN32_FIND_DATAA *, lpFindFileData)
86{
87 HANDLE hFind;
88 char *filename;
89 int namelen;
90
91 dprintf(("FindFirstFileA %s", lpFileName));
92 if(lpFileName == NULL || lpFindFileData == NULL) {
93 SetLastError(ERROR_INVALID_PARAMETER);
94 return -1;
95 }
96 namelen = strlen(lpFileName);
97 if(lpFileName[namelen-1] == '\\') {
98 filename = (char *)alloca(namelen+1);
99 strcpy(filename, lpFileName);
100 filename[namelen-1] = 0;
101 }
102 else filename = (char *)lpFileName;
103
104 return (HANDLE)OSLibDosFindFirst(filename,lpFindFileData);
105}
106//******************************************************************************
107// internal function for faster access (SHELL32)
108//******************************************************************************
109ODINFUNCTION3(HANDLE, FindFirstFileMultiA,
110 LPCSTR, lpFileName,
111 WIN32_FIND_DATAA *, lpFindFileData,
112 DWORD *,count)
113{
114 return (HANDLE)OSLibDosFindFirstMulti(lpFileName,lpFindFileData,count);
115}
116//******************************************************************************
117//******************************************************************************
118ODINFUNCTION2(HANDLE, FindFirstFileW,
119 LPCWSTR, lpFileName,
120 WIN32_FIND_DATAW *, lpFindFileData)
121{
122 HANDLE rc;
123 char *astring;
124 WIN32_FIND_DATAA wfda;
125
126 astring = UnicodeToAsciiString((LPWSTR)lpFileName);
127 rc = (HANDLE)OSLibDosFindFirst(astring,&wfda);
128
129 if(rc == -1) {
130 memset(lpFindFileData, 0, sizeof(WIN32_FIND_DATAW));
131 }
132 else {
133 // convert back the result structure
134 memcpy(lpFindFileData,
135 &wfda,
136 sizeof(WIN32_FIND_DATAA));
137
138 lstrcpynAtoW (lpFindFileData->cFileName,
139 wfda.cFileName,
140 sizeof(wfda.cFileName));
141
142 lstrcpynAtoW (lpFindFileData->cAlternateFileName,
143 wfda.cAlternateFileName,
144 sizeof(wfda.cAlternateFileName));
145 }
146 FreeAsciiString(astring);
147 return(rc);
148}
149//******************************************************************************
150//******************************************************************************
151ODINFUNCTION2(BOOL, FindNextFileA,
152 HANDLE, hFindFile,
153 WIN32_FIND_DATAA *, lpFindFileData)
154{
155 return OSLibDosFindNext(hFindFile,lpFindFileData);
156}
157//******************************************************************************
158// internal function for faster access (SHELL32)
159//******************************************************************************
160ODINFUNCTION3(BOOL, FindNextFileMultiA,
161 HANDLE, hFindFile,
162 WIN32_FIND_DATAA *, lpFindFileData,
163 DWORD *,count)
164{
165 return OSLibDosFindNextMulti(hFindFile,lpFindFileData,count);
166}
167//******************************************************************************
168//******************************************************************************
169ODINFUNCTION2(BOOL, FindNextFileW,
170 HANDLE, hFindFile,
171 WIN32_FIND_DATAW *, lpFindFileData)
172{
173 WIN32_FIND_DATAA wfda;
174 BOOL rc;
175
176 rc = OSLibDosFindNext(hFindFile,&wfda);
177
178 if(rc == 0) {
179 memset(lpFindFileData, 0, sizeof(WIN32_FIND_DATAW));
180 }
181 else {
182 // convert back the result structure
183 memcpy(lpFindFileData,
184 &wfda,
185 sizeof(WIN32_FIND_DATAA));
186
187 lstrcpynAtoW (lpFindFileData->cFileName,
188 wfda.cFileName,
189 sizeof(wfda.cFileName));
190
191 lstrcpynAtoW (lpFindFileData->cAlternateFileName,
192 wfda.cAlternateFileName,
193 sizeof(wfda.cAlternateFileName));
194 }
195 return rc;
196}
197//******************************************************************************
198//******************************************************************************
199ODINFUNCTION1(BOOL, FindClose,
200 HANDLE, hFindFile)
201{
202 return OSLibDosFindClose(hFindFile);
203}
204//******************************************************************************
205//******************************************************************************
206ODINFUNCTION1(DWORD, GetFileType,
207 HANDLE, hFile)
208{
209 return(HMGetFileType(hFile));
210}
211//******************************************************************************
212//******************************************************************************
213ODINFUNCTION2(DWORD, GetFileInformationByHandle,
214 HANDLE, arg1,
215 BY_HANDLE_FILE_INFORMATION *, arg2)
216{
217 return(HMGetFileInformationByHandle(arg1,arg2));
218}
219//******************************************************************************
220//******************************************************************************
221ODINFUNCTION1(BOOL, SetEndOfFile,
222 HANDLE, arg1)
223{
224 return HMSetEndOfFile(arg1);
225}
226//******************************************************************************
227//******************************************************************************
228ODINFUNCTION4(BOOL, SetFileTime,
229 HANDLE, arg1,
230 const FILETIME *, arg2,
231 const FILETIME *, arg3,
232 const FILETIME *, arg4)
233{
234 return HMSetFileTime(arg1,
235 arg2,
236 arg3,
237 arg4);
238}
239//******************************************************************************
240//******************************************************************************
241ODINFUNCTION2(INT, CompareFileTime,
242 FILETIME *, lpft1,
243 FILETIME *, lpft2)
244{
245 if (lpft1 == NULL || lpft2 == NULL) {
246 SetLastError(ERROR_INVALID_PARAMETER);
247 return -1;
248 }
249
250 if(lpft1->dwHighDateTime > lpft2->dwHighDateTime)
251 return 1;
252
253 if(lpft1->dwHighDateTime < lpft2->dwHighDateTime)
254 return -1;
255
256 if(lpft1->dwLowDateTime > lpft2->dwLowDateTime)
257 return 1;
258
259 if(lpft1->dwLowDateTime < lpft2->dwLowDateTime)
260 return -1;
261
262 return 0; //equal
263}
264//******************************************************************************
265//******************************************************************************
266ODINFUNCTION4(BOOL, GetFileTime, HANDLE, hFile, LPFILETIME, arg2, LPFILETIME, arg3, LPFILETIME, arg4)
267{
268 return HMGetFileTime(hFile, arg2, arg3, arg4);
269}
270//******************************************************************************
271//******************************************************************************
272ODINFUNCTION3(BOOL, CopyFileA,
273 LPCSTR, arg1,
274 LPCSTR, arg2,
275 BOOL, arg3)
276{
277 return O32_CopyFile(arg1, arg2, arg3);
278}
279//******************************************************************************
280//SvL: 24-6-'97 - Added
281//******************************************************************************
282ODINFUNCTION3(BOOL, CopyFileW,
283 LPCWSTR, arg1,
284 LPCWSTR, arg2,
285 BOOL, arg3)
286{
287 BOOL rc;
288 char *astring1, *astring2;
289
290 astring1 = UnicodeToAsciiString((LPWSTR)arg1);
291 astring2 = UnicodeToAsciiString((LPWSTR)arg2);
292 rc = O32_CopyFile(astring1, astring2, arg3);
293 FreeAsciiString(astring2);
294 FreeAsciiString(astring1);
295 return(rc);
296}
297/*****************************************************************************
298 * Name : BOOL WIN32API CopyFileExA
299 * Purpose : The CopyFileExA function copies an existing file to a new file.
300 * This function preserves extended attributes, OLE structured
301 * storage, NTFS alternate data streams, and file attributes.
302 * Security attributes for the existing file are not copied to
303 * the new file.
304 * Parameters: LPCSTR lpExistingFileName pointer to name of an existing file
305 * LPCSTR lpNewFileName pointer to filename to copy to
306 * LPPROGRESS_ROUTINE lpProgressRoutine pointer to the callback function
307 * LPVOID lpData to be passed to the callback function
308 * LPBOOL pbCancel flag that can be used to cancel the operation
309 * DWORD dwCopyFlags flags that specify how the file is copied
310 * Variables :
311 * Result : f the function succeeds, the return value is nonzero.
312 * If the function fails, the return value is zero.
313 * To get extended error information call GetLastError.
314 * Remark :
315 * Status : UNTESTED STUB
316 *
317 * Author : Markus Montkowski [Thu, 1998/05/19 11:46]
318 *****************************************************************************/
319
320BOOL WIN32API CopyFileExA( LPCSTR lpExistingFileName,
321 LPCSTR lpNewFileName,
322 LPPROGRESS_ROUTINE lpProgressRoutine,
323 LPVOID lpData,
324 LPBOOL pbCancel,
325 DWORD dwCopyFlags)
326{
327
328 dprintf(("KERNEL32: CopyFileExA(%08x,%08x,%08x,%08x,%08x,%08x) not properly implemented\n",
329 lpExistingFileName,
330 lpNewFileName,
331 lpProgressRoutine,
332 lpData,
333 pbCancel,
334 dwCopyFlags
335 ));
336
337 BOOL failIfExists = FALSE;
338
339 /*
340 * Interpret the only flag that CopyFile can interpret.
341 */
342 if((dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0)
343 {
344 failIfExists = TRUE;
345 }
346
347 return CopyFileA(lpExistingFileName, lpNewFileName, failIfExists);
348}
349
350
351/*****************************************************************************
352 * Name : BOOL WIN32API CopyFileExW
353 * Purpose : The CopyFileExW function copies an existing file to a new file.
354 * This function preserves extended attributes, OLE structured
355 * storage, NTFS alternate data streams, and file attributes.
356 * Security attributes for the existing file are not copied to
357 * the new file.
358 * Parameters: LPCWSTR lpExistingFileName pointer to name of an existing file
359 * LPCWSTR lpNewFileName pointer to filename to copy to
360 * LPPROGRESS_ROUTINE lpProgressRoutine pointer to the callback function
361 * LPVOID lpData to be passed to the callback function
362 * LPBOOL pbCancel flag that can be used to cancel the operation
363 * DWORD dwCopyFlags flags that specify how the file is copied
364 * Variables :
365 * Result : f the function succeeds, the return value is nonzero.
366 * If the function fails, the return value is zero.
367 * To get extended error information call GetLastError.
368 * Remark :
369 * Status : UNTESTED STUB
370 *
371 * Author : Markus Montkowski [Thu, 1998/05/19 11:46]
372 *****************************************************************************/
373
374BOOL WIN32API CopyFileExW( LPCWSTR lpExistingFileName,
375 LPCWSTR lpNewFileName,
376 LPPROGRESS_ROUTINE lpProgressRoutine,
377 LPVOID lpData,
378 LPBOOL pbCancel,
379 DWORD dwCopyFlags)
380{
381 LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpExistingFileName );
382 LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpNewFileName );
383
384 BOOL ret = CopyFileExA(sourceA,
385 destA,
386 lpProgressRoutine,
387 lpData,
388 pbCancel,
389 dwCopyFlags);
390
391 HeapFree( GetProcessHeap(), 0, sourceA );
392 HeapFree( GetProcessHeap(), 0, destA );
393
394 return ret;
395}
396//******************************************************************************
397//******************************************************************************
398ODINFUNCTION2(DWORD, GetFileSize,
399 HANDLE, arg1,
400 PDWORD, arg2)
401{
402 return HMGetFileSize(arg1,
403 arg2);
404}
405//******************************************************************************
406//******************************************************************************
407ODINFUNCTION1(BOOL, DeleteFileA,
408 LPCSTR, lpszFile)
409{
410 BOOL rc;
411
412#if 1
413 dprintf(("DeleteFileA %s", lpszFile));
414 return 1;
415#else
416 rc = OSLibDosDelete((LPSTR)lpszFile);
417 if(!rc) {
418 dprintf(("DeleteFileA %s returned FALSE; last error %x", lpszFile, GetLastError()));
419 if(GetLastError() == 20) {
420 return TRUE;
421 }
422 }
423 else dprintf(("DeleteFileA %s", lpszFile));
424
425 return rc;
426#endif
427}
428//******************************************************************************
429//******************************************************************************
430ODINFUNCTION1(BOOL, DeleteFileW,
431 LPCWSTR, arg1)
432{
433 BOOL rc;
434 char *astring;
435
436 astring = UnicodeToAsciiString((LPWSTR)arg1);
437 rc = ODIN_DeleteFileA(astring);
438 FreeAsciiString(astring);
439 return(rc);
440}
441//******************************************************************************
442//******************************************************************************
443ODINFUNCTION4(UINT, GetTempFileNameA,
444 LPCSTR, arg1,
445 LPCSTR, arg2,
446 UINT, arg3,
447 LPSTR, arg4)
448{
449 return O32_GetTempFileName(arg1, arg2, arg3, arg4);
450}
451//******************************************************************************
452//******************************************************************************
453ODINFUNCTION4(UINT, GetTempFileNameW,
454 LPCWSTR, lpPathName,
455 LPCWSTR, lpPrefixString,
456 UINT, uUnique,
457 LPWSTR, lpTempFileName)
458{
459 char *asciipath, *asciiprefix;
460 char *asciitemp = (char *)malloc(MAX_PATH+1);
461 UINT rc;
462
463 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
464 asciiprefix = UnicodeToAsciiString((LPWSTR)lpPrefixString);
465 rc = O32_GetTempFileName(asciipath, asciiprefix, uUnique, asciitemp);
466 if(rc) AsciiToUnicode(asciitemp, lpTempFileName);
467 FreeAsciiString(asciiprefix);
468 FreeAsciiString(asciipath);
469 free(asciitemp);
470 return(rc);
471}
472//******************************************************************************
473//******************************************************************************
474ODINFUNCTION2(UINT, GetTempPathA,
475 UINT, arg1,
476 LPSTR, arg2)
477{
478 return O32_GetTempPath(arg1, arg2);
479}
480//******************************************************************************
481//******************************************************************************
482ODINFUNCTION2(UINT, GetTempPathW,
483 UINT, nBufferLength,
484 LPWSTR, lpBuffer)
485{
486 char *asciibuffer = (char *)malloc(nBufferLength+1);
487 DWORD rc;
488
489 rc = O32_GetTempPath(nBufferLength, asciibuffer);
490 if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
491 free(asciibuffer);
492 return(rc);
493}
494//******************************************************************************
495//******************************************************************************
496ODINFUNCTION5(BOOL, ReadFile,
497 HANDLE, hFile,
498 PVOID, pBuffer,
499 DWORD, dwLength,
500 PDWORD, lpNumberOfBytesRead,
501 LPOVERLAPPED, lpOverlapped)
502{
503 return (HMReadFile(hFile,
504 pBuffer,
505 dwLength,
506 lpNumberOfBytesRead,
507 lpOverlapped));
508}
509//******************************************************************************
510//******************************************************************************
511ODINFUNCTION5(BOOL, ReadFileEx,
512 HANDLE, hFile,
513 LPVOID, lpBuffer,
514 DWORD, nNumberOfBytesToRead,
515 LPOVERLAPPED, lpOverlapped,
516 LPOVERLAPPED_COMPLETION_ROUTINE, lpCompletionRoutine)
517{
518 return (HMReadFileEx(hFile,
519 lpBuffer,
520 nNumberOfBytesToRead,
521 lpOverlapped, lpCompletionRoutine));
522}
523//******************************************************************************
524//******************************************************************************
525ODINFUNCTION5(BOOL, WriteFile,
526 HANDLE, hFile,
527 LPCVOID, buffer,
528 DWORD, nrbytes,
529 LPDWORD, nrbyteswritten,
530 LPOVERLAPPED, lpOverlapped)
531{
532 return (HMWriteFile(hFile,
533 buffer,
534 nrbytes,
535 nrbyteswritten,
536 lpOverlapped));
537}
538/*****************************************************************************
539 * Name : BOOL WriteFileEx
540 * Purpose : The WriteFileEx function writes data to a file. It is designed
541 * solely for asynchronous operation, unlike WriteFile, which is
542 * designed for both synchronous and asynchronous operation.
543 * WriteFileEx reports its completion status asynchronously,
544 * calling a specified completion routine when writing is completed
545 * and the calling thread is in an alertable wait state.
546 * Parameters: HANDLE hFile handle of file to write
547 * LPVOID lpBuffer address of buffer
548 * DWORD nNumberOfBytesToRead number of bytes to write
549 * LPOVERLAPPED lpOverlapped address of offset
550 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
551 * Variables :
552 * Result : TRUE / FALSE
553 * Remark :
554 * Status : UNTESTED STUB
555 *
556 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
557 *****************************************************************************/
558
559ODINFUNCTION5(BOOL, WriteFileEx,
560 HANDLE, hFile,
561 LPVOID, lpBuffer,
562 DWORD, nNumberOfBytesToWrite,
563 LPOVERLAPPED, lpOverlapped,
564 LPOVERLAPPED_COMPLETION_ROUTINE, lpCompletionRoutine)
565{
566 return (HMWriteFileEx(hFile,
567 lpBuffer,
568 nNumberOfBytesToWrite,
569 lpOverlapped, lpCompletionRoutine));
570}
571//******************************************************************************
572//******************************************************************************
573ODINFUNCTION4(DWORD, SetFilePointer,
574 HANDLE, hFile,
575 LONG, lDistanceToMove,
576 PLONG, lpDistanceToMoveHigh,
577 DWORD, dwMoveMethod)
578{
579 return(HMSetFilePointer(hFile,
580 lDistanceToMove,
581 lpDistanceToMoveHigh,
582 dwMoveMethod));
583}
584//******************************************************************************
585//******************************************************************************
586ODINFUNCTION1(DWORD, GetFileAttributesA,
587 LPCSTR, lpszFileName)
588{
589 DWORD rc, error;
590
591 if((NULL!=lpszFileName) && strlen(lpszFileName)==2 && lpszFileName[1] == ':')
592 {
593 char szDrive[4];
594 szDrive[0] = lpszFileName[0];
595 szDrive[1] = lpszFileName[1];
596 szDrive[2] = '\\';
597 szDrive[3] = 0x00;
598 rc = O32_GetFileAttributes((LPSTR)szDrive);
599 }
600 else {
601 rc = O32_GetFileAttributes((LPSTR)lpszFileName);
602 if(rc == -1 && lpszFileName[strlen(lpszFileName)-1] != '\\') {
603 char *filename = (char *)alloca(strlen(lpszFileName)+2); //+2!!!!!!
604 strcpy(filename, lpszFileName);
605 strcat(filename, "\\");
606 rc = O32_GetFileAttributes((LPSTR)filename);
607 }
608 }
609 //SvL: Open32 returns FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL for
610 // directories whereas NT 4 (SP6) only returns FILE_ATTRIBUTE_DIRECTORY
611 if(rc != -1 && (rc & FILE_ATTRIBUTE_DIRECTORY)) {
612 rc = FILE_ATTRIBUTE_DIRECTORY;
613 }
614
615#if 0 // need more tests, maybe there is also a better way to hide simulated b:
616 if(rc == -1 && lpszFileName != NULL && !strnicmp(lpszFileName, "B:", 2))
617 {
618 error = GetLastError();
619 if(error = ERROR_DISK_CHANGE)
620 SetLastError(ERROR_NOT_READY);
621 else
622 SetLastError(error);
623 }
624#endif
625 dprintf(("KERNEL32: GetFileAttributes of %s returned %d\n", lpszFileName, rc));
626 return(rc);
627}
628//******************************************************************************
629//******************************************************************************
630ODINFUNCTION1(DWORD, GetFileAttributesW,
631 LPCWSTR, arg1)
632{
633 DWORD rc;
634 char *astring;
635
636 astring = UnicodeToAsciiString((LPWSTR)arg1);
637 rc = ODIN_GetFileAttributesA(astring);
638 FreeAsciiString(astring);
639 return(rc);
640}
641//******************************************************************************
642//******************************************************************************
643ODINFUNCTION2(BOOL, SetFileAttributesA,
644 LPCSTR, arg1,
645 DWORD, arg2)
646{
647 dprintf(("KERNEL32: SetFileAttributes of %s\n", arg1));
648 return O32_SetFileAttributes(arg1, arg2);
649}
650//******************************************************************************
651//******************************************************************************
652ODINFUNCTION2(BOOL, SetFileAttributesW,
653 LPCWSTR, lpFileName,
654 DWORD, dwFileAttributes)
655{
656 char *asciifile;
657 BOOL rc;
658
659 asciifile = UnicodeToAsciiString((LPWSTR)lpFileName);
660 rc = O32_SetFileAttributes(asciifile, dwFileAttributes);
661 FreeAsciiString(asciifile);
662 return(rc);
663}
664//******************************************************************************
665//******************************************************************************
666ODINFUNCTION4(DWORD, GetFullPathNameA,
667 LPCSTR, arg1,
668 DWORD, arg2,
669 LPSTR, arg3,
670 LPSTR *, arg4)
671{
672 char *ptr;
673 dprintf(("KERNEL32: GetFullPathName %s\n", arg1));
674 while((ptr = strchr(arg1, '/')) != NULL)
675 *ptr = '\\';
676 return O32_GetFullPathName(arg1, arg2, arg3, arg4);
677}
678//******************************************************************************
679//******************************************************************************
680ODINFUNCTION4(DWORD, GetFullPathNameW,
681 LPCWSTR, lpFileName,
682 DWORD, nBufferLength,
683 LPWSTR, lpBuffer,
684 LPWSTR *, lpFilePart)
685{
686 char *astring, *asciibuffer, *asciipart;
687 DWORD rc;
688
689 asciibuffer = (char *)malloc(nBufferLength+1);
690 astring = UnicodeToAsciiString((LPWSTR)lpFileName);
691
692 rc = ODIN_GetFullPathNameA(astring,
693 nBufferLength,
694 asciibuffer,
695 &asciipart);
696
697 dprintf(("KERNEL32: GetFullPathNameW %s returns %s\n",
698 astring,
699 asciibuffer));
700
701 if(rc)
702 AsciiToUnicode(asciibuffer,
703 lpBuffer);
704
705 if(lpFilePart)
706 *lpFilePart = lpBuffer + ((int)asciipart - (int)asciibuffer);
707
708 FreeAsciiString(astring);
709 free(asciibuffer);
710 return(rc);
711}
712//******************************************************************************
713//******************************************************************************
714ODINFUNCTION5(BOOL, LockFile,
715 HANDLE, arg1,
716 DWORD, arg2,
717 DWORD, arg3,
718 DWORD, arg4,
719 DWORD, arg5)
720{
721 return HMLockFile(arg1,
722 arg2,
723 arg3,
724 arg4,
725 arg5);
726}
727
728
729/*****************************************************************************
730 * Name : BOOL LockFileEx
731 * Purpose : The LockFileEx function locks a byte range within an open file for shared or exclusive access.
732 * Parameters: HANDLE hFile handle of file to lock
733 * DWORD dwFlags functional behavior modification flags
734 * DWORD dwReserved reserved, must be set to zero
735 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
736 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
737 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
738 * Variables :
739 * Result : TRUE / FALSE
740 * Remark :
741 * Status : UNTESTED STUB
742 *
743 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
744 *****************************************************************************/
745
746ODINFUNCTION6(BOOL, LockFileEx,
747 HANDLE, hFile,
748 DWORD, dwFlags,
749 DWORD, dwReserved,
750 DWORD, nNumberOfBytesToLockLow,
751 DWORD, nNumberOfBytesToLockHigh,
752 LPOVERLAPPED, lpOverlapped)
753{
754 return(HMLockFile(hFile,
755 lpOverlapped->Offset,
756 lpOverlapped->OffsetHigh,
757 nNumberOfBytesToLockLow,
758 nNumberOfBytesToLockHigh));
759}
760
761
762
763
764//******************************************************************************
765//******************************************************************************
766ODINFUNCTION2(BOOL, MoveFileA,
767 LPCSTR, arg1,
768 LPCSTR, arg2)
769{
770 dprintf(("KERNEL32: MoveFileA %s %s", arg1, arg2));
771 return O32_MoveFile(arg1, arg2);
772}
773//******************************************************************************
774//******************************************************************************
775ODINFUNCTION3(BOOL, MoveFileExA,
776 LPCSTR, arg1,
777 LPCSTR, arg2,
778 DWORD, fdwFlags)
779{
780 dprintf(("KERNEL32: MoveFileExA %s to %s, not complete!\n", arg1, arg2));
781 return O32_MoveFile(arg1, arg2);
782}
783//******************************************************************************
784//******************************************************************************
785ODINFUNCTION2(BOOL, MoveFileW,
786 LPCWSTR, lpSrc,
787 LPCWSTR, lpDest)
788{
789 char *asciisrc, *asciidest;
790 BOOL rc;
791
792 asciisrc = UnicodeToAsciiString((LPWSTR)lpSrc);
793 asciidest = UnicodeToAsciiString((LPWSTR)lpDest);
794 rc = O32_MoveFile(asciisrc, asciidest);
795 FreeAsciiString(asciisrc);
796 FreeAsciiString(asciidest);
797 return(rc);
798}
799//******************************************************************************
800//******************************************************************************
801ODINFUNCTION3(BOOL, MoveFileExW,
802 LPCWSTR, arg1,
803 LPCWSTR, arg2,
804 DWORD, fdwFlags)
805{
806 dprintf(("KERNEL32: MoveFileExW %s to %s, not complete!\n", arg1, arg2));
807 return MoveFileW(arg1, arg2);
808}
809//******************************************************************************
810/*****************************************************************************
811ODINFUNCTION3(*, :,
812 HFILE, WIN32API,
813 OpenFile *, Purpose,
814 :, forwardOpenFile to Open32
815 * Parameters:
816 * Variables :
817 * Result : API returncode
818 * Remark : modified for handle translation support
819 * Status : @@@PH verify if 0 is a valid "invalid handle" :)
820 *
821 * Author : Patrick Haller [Fri, 1998/06/12 02:53]
822 *****************************************************************************/
823
824ODINFUNCTION3(HFILE, OpenFile,
825 LPCSTR, lpszFile,
826 OFSTRUCT *, lpOpenBuff,
827 UINT, fuMode)
828{
829 HFILE hFile;
830
831 dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",
832 lpszFile,
833 lpOpenBuff,
834 fuMode));
835
836 hFile = HMOpenFile(lpszFile, /* call open32 */
837 lpOpenBuff,
838 fuMode);
839
840 return (hFile);
841}
842//******************************************************************************
843//******************************************************************************
844ODINFUNCTION5(BOOL, UnlockFile,
845 HANDLE, arg1,
846 DWORD, arg2,
847 DWORD, arg3,
848 DWORD, arg4,
849 DWORD, arg5)
850{
851 return HMUnlockFile(arg1,
852 arg2,
853 arg3,
854 arg4,
855 arg5);
856}
857
858
859/*****************************************************************************
860 * Name : BOOL UnlockFileEx
861 * Purpose : The UnlockFileEx function unlocks a previously locked byte range in an open file.
862 * Parameters: HANDLE hFile handle of file to lock
863 * DWORD dwReserved reserved, must be set to zero
864 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
865 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
866 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
867 * Variables :
868 * Result : TRUE / FALSE
869 * Remark :
870 * Status : UNTESTED STUB
871 *
872 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
873 *****************************************************************************/
874
875ODINFUNCTION5(BOOL, UnlockFileEx,
876 HANDLE, hFile,
877 DWORD, dwReserved,
878 DWORD, nNumberOfBytesToLockLow,
879 DWORD, nNumberOfBytesToLockHigh,
880 LPOVERLAPPED, lpOverlapped)
881{
882 return(HMUnlockFileEx(hFile, dwReserved,
883 nNumberOfBytesToLockLow,
884 nNumberOfBytesToLockHigh,
885 lpOverlapped));
886}
887//******************************************************************************
888//Behaviour in NT 4, SP6:
889//- converts long filename to 8.3 short filname (TODO: not yet done here!)
890//- fails on volume that doesn't support 8.3 filenames
891//- if lpszShortPath 0 or cchBuffer too small -> return required length
892// (INCLUDING 0 terminator)
893//- if lpszLongPath == NULL -> ERROR_INVALID_PARAMETER (return 0)
894//- if lpszLongPath empty -> proceed as if nothing is wrong
895//- does NOT clear the last error if successful!
896//- if successful -> return length of string (excluding 0 terminator)
897//******************************************************************************
898ODINFUNCTION3(DWORD, GetShortPathNameA,
899 LPCTSTR, lpszLongPath,
900 LPTSTR, lpszShortPath,
901 DWORD, cchBuffer)
902{
903 int length;
904
905 dprintf(("KERNEL32: GetShortPathNameA of %s, just copying it", lpszLongPath));
906
907 if(!lpszLongPath) {
908 SetLastError(ERROR_INVALID_PARAMETER);
909 return 0;
910 }
911
912 length = lstrlenA(lpszLongPath) + 1;
913 if(length > cchBuffer) {
914 if(lpszShortPath) {
915 *lpszShortPath = 0;
916 }
917 return(length); //return length required (including 0 terminator)
918 }
919 lstrcpyA(lpszShortPath, lpszLongPath);
920 return(length-1);
921}
922//******************************************************************************
923//******************************************************************************
924ODINFUNCTION3(DWORD, GetShortPathNameW,
925 LPCWSTR, lpszLongPath,
926 LPWSTR, lpszShortPath,
927 DWORD, cchBuffer)
928{
929 int length;
930
931 dprintf(("KERNEL32: GetShortPathNameW; just copying it"));
932 if(!lpszLongPath) {
933 SetLastError(ERROR_INVALID_PARAMETER);
934 return 0;
935 }
936
937 length = lstrlenW(lpszLongPath) + 1;
938 if(length > cchBuffer) {
939 if(lpszShortPath) {
940 *lpszShortPath = 0;
941 }
942 return(length); //return length required (including 0 terminator)
943 }
944 lstrcpyW(lpszShortPath, lpszLongPath);
945 return(length-1);
946}
947//******************************************************************************
948//******************************************************************************
949ODINPROCEDURE0(SetFileApisToANSI)
950{
951 dprintf(("SetFileApisToANSI() stub\n"));
952}
953
954/*****************************************************************************
955 * Name : DWORD GetCompressedFileSizeA
956 * Purpose : The GetCompressedFileSizeA function obtains the compressed
957 * size, in bytes, of a specified file.
958 * Parameters: LPCTSTR lpFileName, // pointer to name of file
959 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
960 * high-order doubleword of file size
961 * Variables :
962 * Result : size of compressed file
963 * Remark :
964 * Status : UNTESTED
965 *
966 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
967 *****************************************************************************/
968
969ODINFUNCTION2(DWORD, GetCompressedFileSizeA,
970 LPCTSTR, lpFileName,
971 LPDWORD, lpFileSizeHigh)
972{
973 dprintf(("KERNEL32: GetCompressedFileSizeA (%s, %08xh) not implemented.\n",
974 lpFileName,
975 lpFileSizeHigh));
976
977 /* @@@PH: simply return the standard filesize */
978 return 0;
979}
980
981
982/*****************************************************************************
983 * Name : DWORD GetCompressedFileSizeW
984 * Purpose : The GetCompressedFileSizeE function obtains the compressed
985 * size, in bytes, of a specified file.
986 * Parameters: LPCWSTR lpFileName, // pointer to name of file
987 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
988 * high-order doubleword of file size
989 * Variables :
990 * Result : size of compressed file
991 * Remark :
992 * Status : UNTESTED
993 *
994 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
995 *****************************************************************************/
996
997ODINFUNCTION2(DWORD, GetCompressedFileSizeW,
998 LPCWSTR, lpFileName,
999 LPDWORD, lpFileSizeHigh)
1000{
1001 LPCTSTR lpAsciiFileName; /* converted filename */
1002 DWORD rc; /* function result */
1003
1004 dprintf(("KERNEL32: GetCompressedFileSizeW (%s, %08xh)\n",
1005 lpFileName,
1006 lpFileSizeHigh));
1007
1008 lpAsciiFileName = UnicodeToAsciiString( (LPWSTR) lpFileName);
1009
1010 rc = GetCompressedFileSizeA(lpAsciiFileName,
1011 lpFileSizeHigh);
1012
1013 FreeAsciiString( (char *) lpAsciiFileName);
1014
1015 return (rc); /* return result */
1016}
1017
1018
1019/*****************************************************************************
1020 * Name : BOOL GetFileAttributesExA
1021 * Purpose :
1022 * Parameters:
1023 * Variables :
1024 * Result :
1025 * Remark : KERNEL32.874
1026 * Status : UNTESTED
1027 *
1028 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1029 *****************************************************************************/
1030
1031ODINFUNCTION3(BOOL, GetFileAttributesExA,
1032 LPCSTR, lpFileName,
1033 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1034 LPVOID, lpFileInformation)
1035{
1036 BOOL rc;
1037
1038 dprintf(("KERNEL32: GetFileAttributesExA(%s,%08xh,%08xh) mostly implemented.\n",
1039 lpFileName,
1040 fInfoLevelId,
1041 lpFileInformation));
1042
1043 if (lpFileName == NULL) return FALSE;
1044 if (lpFileInformation == NULL) return FALSE;
1045
1046 if (fInfoLevelId == GetFileExInfoStandard)
1047 {
1048 LPWIN32_FILE_ATTRIBUTE_DATA lpFad = (LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation;
1049
1050 rc = OSLibDosGetFileAttributesEx((LPSTR)lpFileName,
1051 fInfoLevelId,
1052 lpFileInformation);
1053 return (rc);
1054 }
1055 else
1056 {
1057 dprintf(("KERNEL32: GetFileAttributesExA - invalid info level %d!\n",
1058 fInfoLevelId));
1059 return FALSE;
1060 }
1061}
1062
1063
1064/*****************************************************************************
1065 * Name : BOOL GetFileAttributesExW
1066 * Purpose :
1067 * Parameters:
1068 * Variables :
1069 * Result :
1070 * Remark : KERNEL32.875
1071 * Status : UNTESTED
1072 *
1073 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1074 *****************************************************************************/
1075
1076ODINFUNCTION3(BOOL, GetFileAttributesExW,
1077 LPCWSTR, lpFileName,
1078 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1079 LPVOID, lpFileInformation)
1080{
1081 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
1082 BOOL res = GetFileAttributesExA( nameA, fInfoLevelId, lpFileInformation);
1083 HeapFree( GetProcessHeap(), 0, nameA );
1084 return res;
1085}
1086
1087//******************************************************************************
1088//******************************************************************************
1089ODINFUNCTION3(HANDLE, FindFirstChangeNotificationA,
1090 LPCSTR, lpPathName,
1091 BOOL, bWatchSubtree,
1092 DWORD, dwNotifyFilter)
1093{
1094 dprintf(("KERNEL32: FindFirstChangeNotificationA, Not implemented (faked)\n"));
1095 return -1;
1096}
1097//******************************************************************************
1098//******************************************************************************
1099ODINFUNCTION1(BOOL, FindNextChangeNotification,
1100 HANDLE, hChange)
1101{
1102 dprintf(("KERNEL32: FindNextChangeNotification (%08xh), Not implemented\n",
1103 hChange));
1104
1105 return FALSE;
1106}
1107//******************************************************************************
1108//******************************************************************************
1109ODINFUNCTION1(BOOL, FindCloseChangeNotification, HANDLE, hChange)
1110{
1111 dprintf(("KERNEL32: OS2FindNextChangeNotification, Not implemented\n"));
1112
1113 return(TRUE);
1114}
1115/*****************************************************************************
1116 * Name : HANDLE WIN32API FindFirstChangeNotificationW
1117 * Purpose : The FindFirstChangeNotification function creates a change
1118 * notification handle and sets up initial change notification
1119 * filter conditions. A wait on a notification handle succeeds when
1120 * a change matching the filter conditions occurs in the specified
1121 * directory or subtree.
1122 * Parameters: LPCWSTR lpPathName pointer to name of directory to watch
1123 * BOOL bWatchSubtree flag for monitoring directory or
1124 * directory tree
1125 * DWORD dwNotifyFilter filter conditions to watch for
1126 * Variables :
1127 * Result : If the function succeeds, the return value is a handle to a find
1128 * change notification object.
1129 * If the function fails, the return value is INVALID_HANDLE_VALUE
1130 * Remark :
1131 * Status : UNTESTED STUB
1132 *
1133 * Author : Markus Montkowski [Tha, 1998/05/21 20:57]
1134 *****************************************************************************/
1135ODINFUNCTION3(HANDLE, FindFirstChangeNotificationW, LPCWSTR, lpPathName,
1136 BOOL, bWatchSubtree,
1137 DWORD, dwNotifyFilter)
1138{
1139 LPSTR lpAsciiPath;
1140 HANDLE hChange;
1141
1142 lpAsciiPath = UnicodeToAsciiString( (LPWSTR) lpPathName);
1143 hChange = FindFirstChangeNotificationA(lpAsciiPath, bWatchSubtree,
1144 dwNotifyFilter );
1145 if (lpAsciiPath) FreeAsciiString(lpAsciiPath);
1146 return hChange;
1147}
1148//******************************************************************************
1149//******************************************************************************
1150ODINFUNCTION8(BOOL, DeviceIoControl, HANDLE, hDevice, DWORD, dwIoControlCode,
1151 LPVOID, lpInBuffer, DWORD, nInBufferSize,
1152 LPVOID, lpOutBuffer, DWORD, nOutBufferSize,
1153 LPDWORD, lpBytesReturned, LPOVERLAPPED, lpOverlapped)
1154{
1155 return HMDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize,
1156 lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
1157}
1158//******************************************************************************
1159//******************************************************************************
Note: See TracBrowser for help on using the repository browser.