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

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

matchModName bugs fixed

File size: 41.0 KB
Line 
1/* $Id: Fileio.cpp,v 1.40 2000-09-18 19:26:15 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 0
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
677 return O32_GetFullPathName(arg1, arg2, arg3, arg4);
678}
679//******************************************************************************
680//******************************************************************************
681ODINFUNCTION4(DWORD, GetFullPathNameW,
682 LPCWSTR, lpFileName,
683 DWORD, nBufferLength,
684 LPWSTR, lpBuffer,
685 LPWSTR *, lpFilePart)
686{
687 char *astring, *asciibuffer, *asciipart;
688 DWORD rc;
689
690 asciibuffer = (char *)malloc(nBufferLength+1);
691 astring = UnicodeToAsciiString((LPWSTR)lpFileName);
692
693 rc = ODIN_GetFullPathNameA(astring,
694 nBufferLength,
695 asciibuffer,
696 &asciipart);
697
698 dprintf(("KERNEL32: GetFullPathNameW %s returns %s\n",
699 astring,
700 asciibuffer));
701
702 if(rc)
703 AsciiToUnicode(asciibuffer,
704 lpBuffer);
705
706 if(lpFilePart)
707 *lpFilePart = lpBuffer + ((int)asciipart - (int)asciibuffer);
708
709 FreeAsciiString(astring);
710 free(asciibuffer);
711 return(rc);
712}
713//******************************************************************************
714//******************************************************************************
715ODINFUNCTION5(BOOL, LockFile,
716 HANDLE, arg1,
717 DWORD, arg2,
718 DWORD, arg3,
719 DWORD, arg4,
720 DWORD, arg5)
721{
722 return HMLockFile(arg1,
723 arg2,
724 arg3,
725 arg4,
726 arg5);
727}
728
729
730/*****************************************************************************
731 * Name : BOOL LockFileEx
732 * Purpose : The LockFileEx function locks a byte range within an open file for shared or exclusive access.
733 * Parameters: HANDLE hFile handle of file to lock
734 * DWORD dwFlags functional behavior modification flags
735 * DWORD dwReserved reserved, must be set to zero
736 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
737 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
738 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
739 * Variables :
740 * Result : TRUE / FALSE
741 * Remark :
742 * Status : UNTESTED STUB
743 *
744 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
745 *****************************************************************************/
746
747ODINFUNCTION6(BOOL, LockFileEx,
748 HANDLE, hFile,
749 DWORD, dwFlags,
750 DWORD, dwReserved,
751 DWORD, nNumberOfBytesToLockLow,
752 DWORD, nNumberOfBytesToLockHigh,
753 LPOVERLAPPED, lpOverlapped)
754{
755 return(HMLockFile(hFile,
756 lpOverlapped->Offset,
757 lpOverlapped->OffsetHigh,
758 nNumberOfBytesToLockLow,
759 nNumberOfBytesToLockHigh));
760}
761
762
763
764
765//******************************************************************************
766//******************************************************************************
767ODINFUNCTION2(BOOL, MoveFileA,
768 LPCSTR, arg1,
769 LPCSTR, arg2)
770{
771 dprintf(("KERNEL32: MoveFileA %s %s", arg1, arg2));
772 return O32_MoveFile(arg1, arg2);
773}
774//******************************************************************************
775//******************************************************************************
776ODINFUNCTION3(BOOL, MoveFileExA,
777 LPCSTR, arg1,
778 LPCSTR, arg2,
779 DWORD, fdwFlags)
780{
781 dprintf(("KERNEL32: MoveFileExA %s to %s, not complete!\n", arg1, arg2));
782 return O32_MoveFile(arg1, arg2);
783}
784//******************************************************************************
785//******************************************************************************
786ODINFUNCTION2(BOOL, MoveFileW,
787 LPCWSTR, lpSrc,
788 LPCWSTR, lpDest)
789{
790 char *asciisrc, *asciidest;
791 BOOL rc;
792
793 asciisrc = UnicodeToAsciiString((LPWSTR)lpSrc);
794 asciidest = UnicodeToAsciiString((LPWSTR)lpDest);
795 rc = O32_MoveFile(asciisrc, asciidest);
796 FreeAsciiString(asciisrc);
797 FreeAsciiString(asciidest);
798 return(rc);
799}
800//******************************************************************************
801//******************************************************************************
802ODINFUNCTION3(BOOL, MoveFileExW,
803 LPCWSTR, arg1,
804 LPCWSTR, arg2,
805 DWORD, fdwFlags)
806{
807 dprintf(("KERNEL32: MoveFileExW %s to %s, not complete!\n", arg1, arg2));
808 return MoveFileW(arg1, arg2);
809}
810//******************************************************************************
811/*****************************************************************************
812ODINFUNCTION3(*, :,
813 HFILE, WIN32API,
814 OpenFile *, Purpose,
815 :, forwardOpenFile to Open32
816 * Parameters:
817 * Variables :
818 * Result : API returncode
819 * Remark : modified for handle translation support
820 * Status : @@@PH verify if 0 is a valid "invalid handle" :)
821 *
822 * Author : Patrick Haller [Fri, 1998/06/12 02:53]
823 *****************************************************************************/
824
825ODINFUNCTION3(HFILE, OpenFile,
826 LPCSTR, lpszFile,
827 OFSTRUCT *, lpOpenBuff,
828 UINT, fuMode)
829{
830 HFILE hFile;
831
832 dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",
833 lpszFile,
834 lpOpenBuff,
835 fuMode));
836
837 hFile = HMOpenFile(lpszFile, /* call open32 */
838 lpOpenBuff,
839 fuMode);
840
841 return (hFile);
842}
843//******************************************************************************
844//******************************************************************************
845ODINFUNCTION5(BOOL, UnlockFile,
846 HANDLE, arg1,
847 DWORD, arg2,
848 DWORD, arg3,
849 DWORD, arg4,
850 DWORD, arg5)
851{
852 return HMUnlockFile(arg1,
853 arg2,
854 arg3,
855 arg4,
856 arg5);
857}
858
859
860/*****************************************************************************
861 * Name : BOOL UnlockFileEx
862 * Purpose : The UnlockFileEx function unlocks a previously locked byte range in an open file.
863 * Parameters: HANDLE hFile handle of file to lock
864 * DWORD dwReserved reserved, must be set to zero
865 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
866 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
867 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
868 * Variables :
869 * Result : TRUE / FALSE
870 * Remark :
871 * Status : UNTESTED STUB
872 *
873 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
874 *****************************************************************************/
875
876ODINFUNCTION5(BOOL, UnlockFileEx,
877 HANDLE, hFile,
878 DWORD, dwReserved,
879 DWORD, nNumberOfBytesToLockLow,
880 DWORD, nNumberOfBytesToLockHigh,
881 LPOVERLAPPED, lpOverlapped)
882{
883 return(HMUnlockFileEx(hFile, dwReserved,
884 nNumberOfBytesToLockLow,
885 nNumberOfBytesToLockHigh,
886 lpOverlapped));
887}
888//******************************************************************************
889//Behaviour in NT 4, SP6:
890//- converts long filename to 8.3 short filname (TODO: not yet done here!)
891//- fails on volume that doesn't support 8.3 filenames
892//- if lpszShortPath 0 or cchBuffer too small -> return required length
893// (INCLUDING 0 terminator)
894//- if lpszLongPath == NULL -> ERROR_INVALID_PARAMETER (return 0)
895//- if lpszLongPath empty -> proceed as if nothing is wrong
896//- does NOT clear the last error if successful!
897//- if successful -> return length of string (excluding 0 terminator)
898//******************************************************************************
899ODINFUNCTION3(DWORD, GetShortPathNameA,
900 LPCTSTR, lpszLongPath,
901 LPTSTR, lpszShortPath,
902 DWORD, cchBuffer)
903{
904 int length;
905
906 dprintf(("KERNEL32: GetShortPathNameA of %s, just copying it", lpszLongPath));
907
908 if(!lpszLongPath) {
909 SetLastError(ERROR_INVALID_PARAMETER);
910 return 0;
911 }
912
913 length = lstrlenA(lpszLongPath) + 1;
914 if(length > cchBuffer) {
915 if(lpszShortPath) {
916 *lpszShortPath = 0;
917 }
918 return(length); //return length required (including 0 terminator)
919 }
920 lstrcpyA(lpszShortPath, lpszLongPath);
921 return(length-1);
922}
923//******************************************************************************
924//******************************************************************************
925ODINFUNCTION3(DWORD, GetShortPathNameW,
926 LPCWSTR, lpszLongPath,
927 LPWSTR, lpszShortPath,
928 DWORD, cchBuffer)
929{
930 int length;
931
932 dprintf(("KERNEL32: GetShortPathNameW; just copying it"));
933 if(!lpszLongPath) {
934 SetLastError(ERROR_INVALID_PARAMETER);
935 return 0;
936 }
937
938 length = lstrlenW(lpszLongPath) + 1;
939 if(length > cchBuffer) {
940 if(lpszShortPath) {
941 *lpszShortPath = 0;
942 }
943 return(length); //return length required (including 0 terminator)
944 }
945 lstrcpyW(lpszShortPath, lpszLongPath);
946 return(length-1);
947}
948//******************************************************************************
949//******************************************************************************
950ODINPROCEDURE0(SetFileApisToANSI)
951{
952 dprintf(("SetFileApisToANSI() stub\n"));
953}
954
955/*****************************************************************************
956 * Name : DWORD GetCompressedFileSizeA
957 * Purpose : The GetCompressedFileSizeA function obtains the compressed
958 * size, in bytes, of a specified file.
959 * Parameters: LPCTSTR lpFileName, // pointer to name of file
960 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
961 * high-order doubleword of file size
962 * Variables :
963 * Result : size of compressed file
964 * Remark :
965 * Status : UNTESTED
966 *
967 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
968 *****************************************************************************/
969
970ODINFUNCTION2(DWORD, GetCompressedFileSizeA,
971 LPCTSTR, lpFileName,
972 LPDWORD, lpFileSizeHigh)
973{
974 dprintf(("KERNEL32: GetCompressedFileSizeA (%s, %08xh) not implemented.\n",
975 lpFileName,
976 lpFileSizeHigh));
977
978 /* @@@PH: simply return the standard filesize */
979 return 0;
980}
981
982
983/*****************************************************************************
984 * Name : DWORD GetCompressedFileSizeW
985 * Purpose : The GetCompressedFileSizeE function obtains the compressed
986 * size, in bytes, of a specified file.
987 * Parameters: LPCWSTR lpFileName, // pointer to name of file
988 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
989 * high-order doubleword of file size
990 * Variables :
991 * Result : size of compressed file
992 * Remark :
993 * Status : UNTESTED
994 *
995 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
996 *****************************************************************************/
997
998ODINFUNCTION2(DWORD, GetCompressedFileSizeW,
999 LPCWSTR, lpFileName,
1000 LPDWORD, lpFileSizeHigh)
1001{
1002 LPCTSTR lpAsciiFileName; /* converted filename */
1003 DWORD rc; /* function result */
1004
1005 dprintf(("KERNEL32: GetCompressedFileSizeW (%s, %08xh)\n",
1006 lpFileName,
1007 lpFileSizeHigh));
1008
1009 lpAsciiFileName = UnicodeToAsciiString( (LPWSTR) lpFileName);
1010
1011 rc = GetCompressedFileSizeA(lpAsciiFileName,
1012 lpFileSizeHigh);
1013
1014 FreeAsciiString( (char *) lpAsciiFileName);
1015
1016 return (rc); /* return result */
1017}
1018
1019
1020/*****************************************************************************
1021 * Name : BOOL GetFileAttributesExA
1022 * Purpose :
1023 * Parameters:
1024 * Variables :
1025 * Result :
1026 * Remark : KERNEL32.874
1027 * Status : UNTESTED
1028 *
1029 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1030 *****************************************************************************/
1031
1032ODINFUNCTION3(BOOL, GetFileAttributesExA,
1033 LPCSTR, lpFileName,
1034 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1035 LPVOID, lpFileInformation)
1036{
1037 BOOL rc;
1038
1039 dprintf(("KERNEL32: GetFileAttributesExA(%s,%08xh,%08xh) mostly implemented.\n",
1040 lpFileName,
1041 fInfoLevelId,
1042 lpFileInformation));
1043
1044 if (lpFileName == NULL) return FALSE;
1045 if (lpFileInformation == NULL) return FALSE;
1046
1047 if (fInfoLevelId == GetFileExInfoStandard)
1048 {
1049 LPWIN32_FILE_ATTRIBUTE_DATA lpFad = (LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation;
1050
1051 rc = OSLibDosGetFileAttributesEx((LPSTR)lpFileName,
1052 fInfoLevelId,
1053 lpFileInformation);
1054 return (rc);
1055 }
1056 else
1057 {
1058 dprintf(("KERNEL32: GetFileAttributesExA - invalid info level %d!\n",
1059 fInfoLevelId));
1060 return FALSE;
1061 }
1062}
1063
1064
1065/*****************************************************************************
1066 * Name : BOOL GetFileAttributesExW
1067 * Purpose :
1068 * Parameters:
1069 * Variables :
1070 * Result :
1071 * Remark : KERNEL32.875
1072 * Status : UNTESTED
1073 *
1074 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1075 *****************************************************************************/
1076
1077ODINFUNCTION3(BOOL, GetFileAttributesExW,
1078 LPCWSTR, lpFileName,
1079 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1080 LPVOID, lpFileInformation)
1081{
1082 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
1083 BOOL res = GetFileAttributesExA( nameA, fInfoLevelId, lpFileInformation);
1084 HeapFree( GetProcessHeap(), 0, nameA );
1085 return res;
1086}
1087
1088//******************************************************************************
1089//******************************************************************************
1090ODINFUNCTION3(HANDLE, FindFirstChangeNotificationA,
1091 LPCSTR, lpPathName,
1092 BOOL, bWatchSubtree,
1093 DWORD, dwNotifyFilter)
1094{
1095 dprintf(("KERNEL32: FindFirstChangeNotificationA, Not implemented (faked)\n"));
1096 return -1;
1097}
1098//******************************************************************************
1099//******************************************************************************
1100ODINFUNCTION1(BOOL, FindNextChangeNotification,
1101 HANDLE, hChange)
1102{
1103 dprintf(("KERNEL32: FindNextChangeNotification (%08xh), Not implemented\n",
1104 hChange));
1105
1106 return FALSE;
1107}
1108//******************************************************************************
1109//******************************************************************************
1110ODINFUNCTION1(BOOL, FindCloseChangeNotification, HANDLE, hChange)
1111{
1112 dprintf(("KERNEL32: OS2FindNextChangeNotification, Not implemented\n"));
1113
1114 return(TRUE);
1115}
1116/*****************************************************************************
1117 * Name : HANDLE WIN32API FindFirstChangeNotificationW
1118 * Purpose : The FindFirstChangeNotification function creates a change
1119 * notification handle and sets up initial change notification
1120 * filter conditions. A wait on a notification handle succeeds when
1121 * a change matching the filter conditions occurs in the specified
1122 * directory or subtree.
1123 * Parameters: LPCWSTR lpPathName pointer to name of directory to watch
1124 * BOOL bWatchSubtree flag for monitoring directory or
1125 * directory tree
1126 * DWORD dwNotifyFilter filter conditions to watch for
1127 * Variables :
1128 * Result : If the function succeeds, the return value is a handle to a find
1129 * change notification object.
1130 * If the function fails, the return value is INVALID_HANDLE_VALUE
1131 * Remark :
1132 * Status : UNTESTED STUB
1133 *
1134 * Author : Markus Montkowski [Tha, 1998/05/21 20:57]
1135 *****************************************************************************/
1136ODINFUNCTION3(HANDLE, FindFirstChangeNotificationW, LPCWSTR, lpPathName,
1137 BOOL, bWatchSubtree,
1138 DWORD, dwNotifyFilter)
1139{
1140 LPSTR lpAsciiPath;
1141 HANDLE hChange;
1142
1143 lpAsciiPath = UnicodeToAsciiString( (LPWSTR) lpPathName);
1144 hChange = FindFirstChangeNotificationA(lpAsciiPath, bWatchSubtree,
1145 dwNotifyFilter );
1146 if (lpAsciiPath) FreeAsciiString(lpAsciiPath);
1147 return hChange;
1148}
1149//******************************************************************************
1150//******************************************************************************
1151ODINFUNCTION8(BOOL, DeviceIoControl, HANDLE, hDevice, DWORD, dwIoControlCode,
1152 LPVOID, lpInBuffer, DWORD, nInBufferSize,
1153 LPVOID, lpOutBuffer, DWORD, nOutBufferSize,
1154 LPDWORD, lpBytesReturned, LPOVERLAPPED, lpOverlapped)
1155{
1156 return HMDeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize,
1157 lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
1158}
1159//******************************************************************************
1160//******************************************************************************
Note: See TracBrowser for help on using the repository browser.