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

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

fixes for FS macro changes

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