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

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

CopyFileExA/W, CreateDirectoryExA/W unstubbed, GetShortPathNameA/W fixes

File size: 40.4 KB
Line 
1/* $Id: Fileio.cpp,v 1.36 2000-07-04 08:41:12 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 return 1;
414#else
415 rc = OSLibDosDelete((LPSTR)lpszFile);
416 if(!rc) {
417 dprintf(("DeleteFileA %s returned FALSE; last error %x", lpszFile, GetLastError()));
418 if(GetLastError() == 20) {
419 return TRUE;
420 }
421 }
422 else dprintf(("DeleteFileA %s", lpszFile));
423
424 return rc;
425#endif
426}
427//******************************************************************************
428//******************************************************************************
429ODINFUNCTION1(BOOL, DeleteFileW,
430 LPCWSTR, arg1)
431{
432 BOOL rc;
433 char *astring;
434
435 astring = UnicodeToAsciiString((LPWSTR)arg1);
436 rc = ODIN_DeleteFileA(astring);
437 FreeAsciiString(astring);
438 return(rc);
439}
440//******************************************************************************
441//******************************************************************************
442ODINFUNCTION4(UINT, GetTempFileNameA,
443 LPCSTR, arg1,
444 LPCSTR, arg2,
445 UINT, arg3,
446 LPSTR, arg4)
447{
448 return O32_GetTempFileName(arg1, arg2, arg3, arg4);
449}
450//******************************************************************************
451//******************************************************************************
452ODINFUNCTION4(UINT, GetTempFileNameW,
453 LPCWSTR, lpPathName,
454 LPCWSTR, lpPrefixString,
455 UINT, uUnique,
456 LPWSTR, lpTempFileName)
457{
458 char *asciipath, *asciiprefix;
459 char *asciitemp = (char *)malloc(MAX_PATH+1);
460 UINT rc;
461
462 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
463 asciiprefix = UnicodeToAsciiString((LPWSTR)lpPrefixString);
464 rc = O32_GetTempFileName(asciipath, asciiprefix, uUnique, asciitemp);
465 if(rc) AsciiToUnicode(asciitemp, lpTempFileName);
466 FreeAsciiString(asciiprefix);
467 FreeAsciiString(asciipath);
468 free(asciitemp);
469 return(rc);
470}
471//******************************************************************************
472//******************************************************************************
473ODINFUNCTION2(UINT, GetTempPathA,
474 UINT, arg1,
475 LPSTR, arg2)
476{
477 return O32_GetTempPath(arg1, arg2);
478}
479//******************************************************************************
480//******************************************************************************
481ODINFUNCTION2(UINT, GetTempPathW,
482 UINT, nBufferLength,
483 LPWSTR, lpBuffer)
484{
485 char *asciibuffer = (char *)malloc(nBufferLength+1);
486 DWORD rc;
487
488 rc = O32_GetTempPath(nBufferLength, asciibuffer);
489 if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
490 free(asciibuffer);
491 return(rc);
492}
493//******************************************************************************
494//******************************************************************************
495ODINFUNCTION5(BOOL, ReadFile,
496 HANDLE, hFile,
497 PVOID, pBuffer,
498 DWORD, dwLength,
499 PDWORD, lpNumberOfBytesRead,
500 LPOVERLAPPED, lpOverlapped)
501{
502 return (HMReadFile(hFile,
503 pBuffer,
504 dwLength,
505 lpNumberOfBytesRead,
506 lpOverlapped));
507}
508//******************************************************************************
509//******************************************************************************
510ODINFUNCTION5(BOOL, ReadFileEx,
511 HANDLE, hFile,
512 LPVOID, lpBuffer,
513 DWORD, nNumberOfBytesToRead,
514 LPOVERLAPPED, lpOverlapped,
515 LPOVERLAPPED_COMPLETION_ROUTINE, lpCompletionRoutine)
516{
517 return (HMReadFileEx(hFile,
518 lpBuffer,
519 nNumberOfBytesToRead,
520 lpOverlapped, lpCompletionRoutine));
521}
522//******************************************************************************
523//******************************************************************************
524ODINFUNCTION5(BOOL, WriteFile,
525 HANDLE, hFile,
526 LPCVOID, buffer,
527 DWORD, nrbytes,
528 LPDWORD, nrbyteswritten,
529 LPOVERLAPPED, lpOverlapped)
530{
531 return (HMWriteFile(hFile,
532 buffer,
533 nrbytes,
534 nrbyteswritten,
535 lpOverlapped));
536}
537/*****************************************************************************
538 * Name : BOOL WriteFileEx
539 * Purpose : The WriteFileEx function writes data to a file. It is designed
540 * solely for asynchronous operation, unlike WriteFile, which is
541 * designed for both synchronous and asynchronous operation.
542 * WriteFileEx reports its completion status asynchronously,
543 * calling a specified completion routine when writing is completed
544 * and the calling thread is in an alertable wait state.
545 * Parameters: HANDLE hFile handle of file to write
546 * LPVOID lpBuffer address of buffer
547 * DWORD nNumberOfBytesToRead number of bytes to write
548 * LPOVERLAPPED lpOverlapped address of offset
549 * LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine
550 * Variables :
551 * Result : TRUE / FALSE
552 * Remark :
553 * Status : UNTESTED STUB
554 *
555 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
556 *****************************************************************************/
557
558ODINFUNCTION5(BOOL, WriteFileEx,
559 HANDLE, hFile,
560 LPVOID, lpBuffer,
561 DWORD, nNumberOfBytesToWrite,
562 LPOVERLAPPED, lpOverlapped,
563 LPOVERLAPPED_COMPLETION_ROUTINE, lpCompletionRoutine)
564{
565 return (HMWriteFileEx(hFile,
566 lpBuffer,
567 nNumberOfBytesToWrite,
568 lpOverlapped, lpCompletionRoutine));
569}
570//******************************************************************************
571//******************************************************************************
572ODINFUNCTION4(DWORD, SetFilePointer,
573 HANDLE, hFile,
574 LONG, lDistanceToMove,
575 PLONG, lpDistanceToMoveHigh,
576 DWORD, dwMoveMethod)
577{
578 return(HMSetFilePointer(hFile,
579 lDistanceToMove,
580 lpDistanceToMoveHigh,
581 dwMoveMethod));
582}
583//******************************************************************************
584//******************************************************************************
585ODINFUNCTION1(DWORD, GetFileAttributesA,
586 LPCSTR, lpszFileName)
587{
588 DWORD rc, error;
589
590 if((NULL!=lpszFileName) && strlen(lpszFileName)==2 && lpszFileName[1] == ':')
591 {
592 char szDrive[4];
593 szDrive[0] = lpszFileName[0];
594 szDrive[1] = lpszFileName[1];
595 szDrive[2] = '\\';
596 szDrive[3] = 0x00;
597 rc = O32_GetFileAttributes((LPSTR)szDrive);
598 }
599 else {
600 rc = O32_GetFileAttributes((LPSTR)lpszFileName);
601 if(rc == -1 && lpszFileName[strlen(lpszFileName)-1] != '\\') {
602 char *filename = (char *)alloca(strlen(lpszFileName)+1);
603 strcpy(filename, lpszFileName);
604 strcat(filename, "\\");
605 rc = O32_GetFileAttributes((LPSTR)filename);
606 }
607 }
608 //SvL: Open32 returns FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL for
609 // directories whereas NT 4 (SP6) only returns FILE_ATTRIBUTE_DIRECTORY
610 if(rc != -1 && (rc & FILE_ATTRIBUTE_DIRECTORY)) {
611 rc = FILE_ATTRIBUTE_DIRECTORY;
612 }
613
614#if 0 // need more tests, maybe there is also a better way to hide simulated b:
615 if(rc == -1 && lpszFileName != NULL && !strnicmp(lpszFileName, "B:", 2))
616 {
617 error = GetLastError();
618 if(error = ERROR_DISK_CHANGE)
619 SetLastError(ERROR_NOT_READY);
620 else
621 SetLastError(error);
622 }
623#endif
624 dprintf(("KERNEL32: GetFileAttributes of %s returned %d\n", lpszFileName, rc));
625 return(rc);
626}
627//******************************************************************************
628//******************************************************************************
629ODINFUNCTION1(DWORD, GetFileAttributesW,
630 LPCWSTR, arg1)
631{
632 DWORD rc;
633 char *astring;
634
635 astring = UnicodeToAsciiString((LPWSTR)arg1);
636 rc = ODIN_GetFileAttributesA(astring);
637 FreeAsciiString(astring);
638 return(rc);
639}
640//******************************************************************************
641//******************************************************************************
642ODINFUNCTION2(BOOL, SetFileAttributesA,
643 LPCSTR, arg1,
644 DWORD, arg2)
645{
646 dprintf(("KERNEL32: SetFileAttributes of %s\n", arg1));
647 return O32_SetFileAttributes(arg1, arg2);
648}
649//******************************************************************************
650//******************************************************************************
651ODINFUNCTION2(BOOL, SetFileAttributesW,
652 LPCWSTR, lpFileName,
653 DWORD, dwFileAttributes)
654{
655 char *asciifile;
656 BOOL rc;
657
658 asciifile = UnicodeToAsciiString((LPWSTR)lpFileName);
659 rc = O32_SetFileAttributes(asciifile, dwFileAttributes);
660 FreeAsciiString(asciifile);
661 return(rc);
662}
663//******************************************************************************
664//******************************************************************************
665ODINFUNCTION4(DWORD, GetFullPathNameA,
666 LPCSTR, arg1,
667 DWORD, arg2,
668 LPSTR, arg3,
669 LPSTR *, arg4)
670{
671 char *ptr;
672 dprintf(("KERNEL32: GetFullPathName %s\n", arg1));
673 while((ptr = strchr(arg1, '/')) != NULL)
674 *ptr = '\\';
675 return O32_GetFullPathName(arg1, arg2, arg3, arg4);
676}
677//******************************************************************************
678//******************************************************************************
679ODINFUNCTION4(DWORD, GetFullPathNameW,
680 LPCWSTR, lpFileName,
681 DWORD, nBufferLength,
682 LPWSTR, lpBuffer,
683 LPWSTR *, lpFilePart)
684{
685 char *astring, *asciibuffer, *asciipart;
686 DWORD rc;
687
688 asciibuffer = (char *)malloc(nBufferLength+1);
689 astring = UnicodeToAsciiString((LPWSTR)lpFileName);
690
691 rc = ODIN_GetFullPathNameA(astring,
692 nBufferLength,
693 asciibuffer,
694 &asciipart);
695
696 dprintf(("KERNEL32: GetFullPathNameW %s returns %s\n",
697 astring,
698 asciibuffer));
699
700 if(rc)
701 AsciiToUnicode(asciibuffer,
702 lpBuffer);
703
704 if(lpFilePart)
705 *lpFilePart = lpBuffer + ((int)asciipart - (int)asciibuffer);
706
707 FreeAsciiString(astring);
708 free(asciibuffer);
709 return(rc);
710}
711//******************************************************************************
712//******************************************************************************
713ODINFUNCTION5(BOOL, LockFile,
714 HANDLE, arg1,
715 DWORD, arg2,
716 DWORD, arg3,
717 DWORD, arg4,
718 DWORD, arg5)
719{
720 return HMLockFile(arg1,
721 arg2,
722 arg3,
723 arg4,
724 arg5);
725}
726
727
728/*****************************************************************************
729 * Name : BOOL LockFileEx
730 * Purpose : The LockFileEx function locks a byte range within an open file for shared or exclusive access.
731 * Parameters: HANDLE hFile handle of file to lock
732 * DWORD dwFlags functional behavior modification flags
733 * DWORD dwReserved reserved, must be set to zero
734 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
735 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
736 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
737 * Variables :
738 * Result : TRUE / FALSE
739 * Remark :
740 * Status : UNTESTED STUB
741 *
742 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
743 *****************************************************************************/
744
745ODINFUNCTION6(BOOL, LockFileEx,
746 HANDLE, hFile,
747 DWORD, dwFlags,
748 DWORD, dwReserved,
749 DWORD, nNumberOfBytesToLockLow,
750 DWORD, nNumberOfBytesToLockHigh,
751 LPOVERLAPPED, lpOverlapped)
752{
753 return(HMLockFile(hFile,
754 lpOverlapped->Offset,
755 lpOverlapped->OffsetHigh,
756 nNumberOfBytesToLockLow,
757 nNumberOfBytesToLockHigh));
758}
759
760
761
762
763//******************************************************************************
764//******************************************************************************
765ODINFUNCTION2(BOOL, MoveFileA,
766 LPCSTR, arg1,
767 LPCSTR, arg2)
768{
769 dprintf(("KERNEL32: MoveFileA %s %s", arg1, arg2));
770 return O32_MoveFile(arg1, arg2);
771}
772//******************************************************************************
773//******************************************************************************
774ODINFUNCTION3(BOOL, MoveFileExA,
775 LPCSTR, arg1,
776 LPCSTR, arg2,
777 DWORD, fdwFlags)
778{
779 dprintf(("KERNEL32: MoveFileExA %s to %s, not complete!\n", arg1, arg2));
780 return O32_MoveFile(arg1, arg2);
781}
782//******************************************************************************
783//******************************************************************************
784ODINFUNCTION2(BOOL, MoveFileW,
785 LPCWSTR, lpSrc,
786 LPCWSTR, lpDest)
787{
788 char *asciisrc, *asciidest;
789 BOOL rc;
790
791 asciisrc = UnicodeToAsciiString((LPWSTR)lpSrc);
792 asciidest = UnicodeToAsciiString((LPWSTR)lpDest);
793 rc = O32_MoveFile(asciisrc, asciidest);
794 FreeAsciiString(asciisrc);
795 FreeAsciiString(asciidest);
796 return(rc);
797}
798//******************************************************************************
799//******************************************************************************
800ODINFUNCTION3(BOOL, MoveFileExW,
801 LPCWSTR, arg1,
802 LPCWSTR, arg2,
803 DWORD, fdwFlags)
804{
805 dprintf(("KERNEL32: MoveFileExW %s to %s, not complete!\n", arg1, arg2));
806 return MoveFileW(arg1, arg2);
807}
808//******************************************************************************
809/*****************************************************************************
810ODINFUNCTION3(*, :,
811 HFILE, WIN32API,
812 OpenFile *, Purpose,
813 :, forwardOpenFile to Open32
814 * Parameters:
815 * Variables :
816 * Result : API returncode
817 * Remark : modified for handle translation support
818 * Status : @@@PH verify if 0 is a valid "invalid handle" :)
819 *
820 * Author : Patrick Haller [Fri, 1998/06/12 02:53]
821 *****************************************************************************/
822
823ODINFUNCTION3(HFILE, OpenFile,
824 LPCSTR, lpszFile,
825 OFSTRUCT *, lpOpenBuff,
826 UINT, fuMode)
827{
828 HFILE hFile;
829
830 dprintf(("KERNEL32: OpenFile(%s, %08xh, %08xh)\n",
831 lpszFile,
832 lpOpenBuff,
833 fuMode));
834
835 hFile = HMOpenFile(lpszFile, /* call open32 */
836 lpOpenBuff,
837 fuMode);
838
839 return (hFile);
840}
841//******************************************************************************
842//******************************************************************************
843ODINFUNCTION5(BOOL, UnlockFile,
844 HANDLE, arg1,
845 DWORD, arg2,
846 DWORD, arg3,
847 DWORD, arg4,
848 DWORD, arg5)
849{
850 return HMUnlockFile(arg1,
851 arg2,
852 arg3,
853 arg4,
854 arg5);
855}
856
857
858/*****************************************************************************
859 * Name : BOOL UnlockFileEx
860 * Purpose : The UnlockFileEx function unlocks a previously locked byte range in an open file.
861 * Parameters: HANDLE hFile handle of file to lock
862 * DWORD dwReserved reserved, must be set to zero
863 * DWORD nNumberOfBytesToLockLow low-order 32 bits of length to lock
864 * DWORD nNumberOfBytesToLockHigh high-order 32 bits of length to lock
865 * LPOVERLAPPED LPOVERLAPPED addr. of structure with lock region start offset
866 * Variables :
867 * Result : TRUE / FALSE
868 * Remark :
869 * Status : UNTESTED STUB
870 *
871 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
872 *****************************************************************************/
873
874ODINFUNCTION5(BOOL, UnlockFileEx,
875 HANDLE, hFile,
876 DWORD, dwReserved,
877 DWORD, nNumberOfBytesToLockLow,
878 DWORD, nNumberOfBytesToLockHigh,
879 LPOVERLAPPED, lpOverlapped)
880{
881 return(HMUnlockFileEx(hFile, dwReserved,
882 nNumberOfBytesToLockLow,
883 nNumberOfBytesToLockHigh,
884 lpOverlapped));
885}
886//******************************************************************************
887//Behaviour in NT 4, SP6:
888//- converts long filename to 8.3 short filname (TODO: not yet done here!)
889//- fails on volume that doesn't support 8.3 filenames
890//- if lpszShortPath 0 or cchBuffer too small -> return required length
891// (INCLUDING 0 terminator)
892//- if lpszLongPath == NULL -> ERROR_INVALID_PARAMETER (return 0)
893//- if lpszLongPath empty -> proceed as if nothing is wrong
894//- does NOT clear the last error if successful!
895//- if successful -> return length of string (excluding 0 terminator)
896//******************************************************************************
897ODINFUNCTION3(DWORD, GetShortPathNameA,
898 LPCTSTR, lpszLongPath,
899 LPTSTR, lpszShortPath,
900 DWORD, cchBuffer)
901{
902 int length;
903
904 dprintf(("KERNEL32: GetShortPathNameA of %s, just copying it", lpszLongPath));
905
906 if(!lpszLongPath) {
907 SetLastError(ERROR_INVALID_PARAMETER);
908 return 0;
909 }
910
911 length = lstrlenA(lpszLongPath) + 1;
912 if(length > cchBuffer) {
913 if(lpszShortPath) {
914 *lpszShortPath = 0;
915 }
916 return(length); //return length required (including 0 terminator)
917 }
918 lstrcpyA(lpszShortPath, lpszLongPath);
919 return(length-1);
920}
921//******************************************************************************
922//******************************************************************************
923ODINFUNCTION3(DWORD, GetShortPathNameW,
924 LPCWSTR, lpszLongPath,
925 LPWSTR, lpszShortPath,
926 DWORD, cchBuffer)
927{
928 int length;
929
930 dprintf(("KERNEL32: GetShortPathNameW; just copying it"));
931 if(!lpszLongPath) {
932 SetLastError(ERROR_INVALID_PARAMETER);
933 return 0;
934 }
935
936 length = lstrlenW(lpszLongPath) + 1;
937 if(length > cchBuffer) {
938 if(lpszShortPath) {
939 *lpszShortPath = 0;
940 }
941 return(length); //return length required (including 0 terminator)
942 }
943 lstrcpyW(lpszShortPath, lpszLongPath);
944 return(length-1);
945}
946//******************************************************************************
947//******************************************************************************
948ODINPROCEDURE0(SetFileApisToANSI)
949{
950 dprintf(("SetFileApisToANSI() stub\n"));
951}
952
953/*****************************************************************************
954 * Name : DWORD GetCompressedFileSizeA
955 * Purpose : The GetCompressedFileSizeA function obtains the compressed
956 * size, in bytes, of a specified file.
957 * Parameters: LPCTSTR lpFileName, // pointer to name of file
958 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
959 * high-order doubleword of file size
960 * Variables :
961 * Result : size of compressed file
962 * Remark :
963 * Status : UNTESTED
964 *
965 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
966 *****************************************************************************/
967
968ODINFUNCTION2(DWORD, GetCompressedFileSizeA,
969 LPCTSTR, lpFileName,
970 LPDWORD, lpFileSizeHigh)
971{
972 dprintf(("KERNEL32: GetCompressedFileSizeA (%s, %08xh) not implemented.\n",
973 lpFileName,
974 lpFileSizeHigh));
975
976 /* @@@PH: simply return the standard filesize */
977 return 0;
978}
979
980
981/*****************************************************************************
982 * Name : DWORD GetCompressedFileSizeW
983 * Purpose : The GetCompressedFileSizeE function obtains the compressed
984 * size, in bytes, of a specified file.
985 * Parameters: LPCWSTR lpFileName, // pointer to name of file
986 * LPDWORD lpFileSizeHigh // pointer to DWORD to receive
987 * high-order doubleword of file size
988 * Variables :
989 * Result : size of compressed file
990 * Remark :
991 * Status : UNTESTED
992 *
993 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
994 *****************************************************************************/
995
996ODINFUNCTION2(DWORD, GetCompressedFileSizeW,
997 LPCWSTR, lpFileName,
998 LPDWORD, lpFileSizeHigh)
999{
1000 LPCTSTR lpAsciiFileName; /* converted filename */
1001 DWORD rc; /* function result */
1002
1003 dprintf(("KERNEL32: GetCompressedFileSizeW (%s, %08xh)\n",
1004 lpFileName,
1005 lpFileSizeHigh));
1006
1007 lpAsciiFileName = UnicodeToAsciiString( (LPWSTR) lpFileName);
1008
1009 rc = GetCompressedFileSizeA(lpAsciiFileName,
1010 lpFileSizeHigh);
1011
1012 FreeAsciiString( (char *) lpAsciiFileName);
1013
1014 return (rc); /* return result */
1015}
1016
1017
1018/*****************************************************************************
1019 * Name : BOOL GetFileAttributesExA
1020 * Purpose :
1021 * Parameters:
1022 * Variables :
1023 * Result :
1024 * Remark : KERNEL32.874
1025 * Status : UNTESTED
1026 *
1027 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1028 *****************************************************************************/
1029
1030ODINFUNCTION3(BOOL, GetFileAttributesExA,
1031 LPCSTR, lpFileName,
1032 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1033 LPVOID, lpFileInformation)
1034{
1035 BOOL rc;
1036
1037 dprintf(("KERNEL32: GetFileAttributesExA(%s,%08xh,%08xh) mostly implemented.\n",
1038 lpFileName,
1039 fInfoLevelId,
1040 lpFileInformation));
1041
1042 if (lpFileName == NULL) return FALSE;
1043 if (lpFileInformation == NULL) return FALSE;
1044
1045 if (fInfoLevelId == GetFileExInfoStandard)
1046 {
1047 LPWIN32_FILE_ATTRIBUTE_DATA lpFad = (LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation;
1048
1049 rc = OSLibDosGetFileAttributesEx((LPSTR)lpFileName,
1050 fInfoLevelId,
1051 lpFileInformation);
1052 return (rc);
1053 }
1054 else
1055 {
1056 dprintf(("KERNEL32: GetFileAttributesExA - invalid info level %d!\n",
1057 fInfoLevelId));
1058 return FALSE;
1059 }
1060}
1061
1062
1063/*****************************************************************************
1064 * Name : BOOL GetFileAttributesExW
1065 * Purpose :
1066 * Parameters:
1067 * Variables :
1068 * Result :
1069 * Remark : KERNEL32.875
1070 * Status : UNTESTED
1071 *
1072 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1073 *****************************************************************************/
1074
1075ODINFUNCTION3(BOOL, GetFileAttributesExW,
1076 LPCWSTR, lpFileName,
1077 GET_FILEEX_INFO_LEVELS, fInfoLevelId,
1078 LPVOID, lpFileInformation)
1079{
1080 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
1081 BOOL res = GetFileAttributesExA( nameA, fInfoLevelId, lpFileInformation);
1082 HeapFree( GetProcessHeap(), 0, nameA );
1083 return res;
1084}
1085
1086//******************************************************************************
1087//******************************************************************************
1088ODINFUNCTION3(HANDLE, FindFirstChangeNotificationA,
1089 LPCSTR, lpPathName,
1090 BOOL, bWatchSubtree,
1091 DWORD, dwNotifyFilter)
1092{
1093 dprintf(("KERNEL32: FindFirstChangeNotificationA, Not implemented (faked)\n"));
1094 return -1;
1095}
1096//******************************************************************************
1097//******************************************************************************
1098ODINFUNCTION1(BOOL, FindNextChangeNotification,
1099 HANDLE, hChange)
1100{
1101 dprintf(("KERNEL32: FindNextChangeNotification (%08xh), Not implemented\n",
1102 hChange));
1103
1104 return FALSE;
1105}
1106//******************************************************************************
1107//******************************************************************************
1108ODINFUNCTION1(BOOL, FindCloseChangeNotification, HANDLE, hChange)
1109{
1110 dprintf(("KERNEL32: OS2FindNextChangeNotification, Not implemented\n"));
1111
1112 return(TRUE);
1113}
1114/*****************************************************************************
1115 * Name : HANDLE WIN32API FindFirstChangeNotificationW
1116 * Purpose : The FindFirstChangeNotification function creates a change
1117 * notification handle and sets up initial change notification
1118 * filter conditions. A wait on a notification handle succeeds when
1119 * a change matching the filter conditions occurs in the specified
1120 * directory or subtree.
1121 * Parameters: LPCWSTR lpPathName pointer to name of directory to watch
1122 * BOOL bWatchSubtree flag for monitoring directory or
1123 * directory tree
1124 * DWORD dwNotifyFilter filter conditions to watch for
1125 * Variables :
1126 * Result : If the function succeeds, the return value is a handle to a find
1127 * change notification object.
1128 * If the function fails, the return value is INVALID_HANDLE_VALUE
1129 * Remark :
1130 * Status : UNTESTED STUB
1131 *
1132 * Author : Markus Montkowski [Tha, 1998/05/21 20:57]
1133 *****************************************************************************/
1134ODINFUNCTION3(HANDLE, FindFirstChangeNotificationW, LPCWSTR, lpPathName,
1135 BOOL, bWatchSubtree,
1136 DWORD, dwNotifyFilter)
1137{
1138 LPSTR lpAsciiPath;
1139 HANDLE hChange;
1140
1141 lpAsciiPath = UnicodeToAsciiString( (LPWSTR) lpPathName);
1142 hChange = FindFirstChangeNotificationA(lpAsciiPath, bWatchSubtree,
1143 dwNotifyFilter );
1144 if (lpAsciiPath) FreeAsciiString(lpAsciiPath);
1145 return hChange;
1146}
1147//******************************************************************************
1148//******************************************************************************
Note: See TracBrowser for help on using the repository browser.