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

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

MN: GetFullPathNameW fix

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