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

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

registry fixes (heap corruption) + VirtualAlloc change

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