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

Last change on this file since 6496 was 6199, checked in by sandervl, 24 years ago

Rewrote Atom functions + GetAtomNameW fix

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