2 * File handling functions
4 * Copyright 1993 John Burton
5 * Copyright 1996 Alexandre Julliard
8 * Fix the CopyFileEx methods to implement the "extented" functionality.
9 * Right now, they simply call the CopyFile method.
18 #include <sys/errno.h>
19 #include <sys/types.h>
30 #include "wine/winbase16.h"
31 #include "wine/winestring.h"
46 #include "server/request.h"
49 DEFAULT_DEBUG_CHANNEL(file
)
51 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
52 #define MAP_ANON MAP_ANONYMOUS
55 /* Size of per-process table of DOS handles */
56 #define DOS_TABLE_SIZE 256
59 /***********************************************************************
62 * Convert OF_* mode into flags for CreateFile.
64 static void FILE_ConvertOFMode( INT mode
, DWORD
*access
, DWORD
*sharing
)
68 case OF_READ
: *access
= GENERIC_READ
; break;
69 case OF_WRITE
: *access
= GENERIC_WRITE
; break;
70 case OF_READWRITE
: *access
= GENERIC_READ
| GENERIC_WRITE
; break;
71 default: *access
= 0; break;
75 case OF_SHARE_EXCLUSIVE
: *sharing
= 0; break;
76 case OF_SHARE_DENY_WRITE
: *sharing
= FILE_SHARE_READ
; break;
77 case OF_SHARE_DENY_READ
: *sharing
= FILE_SHARE_WRITE
; break;
78 case OF_SHARE_DENY_NONE
:
80 default: *sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
; break;
86 /***********************************************************************
90 * oldmode[I] mode how file was first opened
91 * mode[I] mode how the file should get opened
96 * Look what we have to do with the given SHARE modes
98 * Ralph Brown's interrupt list gives following explication, I guess
99 * the same holds for Windows, DENY ALL should be OF_SHARE_COMPAT
101 * FIXME: Validate this function
102 ========from Ralph Brown's list =========
104 Values of DOS file sharing behavior:
105 | Second and subsequent Opens
106 First |Compat Deny Deny Deny Deny
107 Open | All Write Read None
108 |R W RW R W RW R W RW R W RW R W RW
109 - - - - -| - - - - - - - - - - - - - - - - -
110 Compat R |Y Y Y N N N 1 N N N N N 1 N N
111 W |Y Y Y N N N N N N N N N N N N
112 RW|Y Y Y N N N N N N N N N N N N
114 Deny R |C C C N N N N N N N N N N N N
115 All W |C C C N N N N N N N N N N N N
116 RW|C C C N N N N N N N N N N N N
118 Deny R |2 C C N N N Y N N N N N Y N N
119 Write W |C C C N N N N N N Y N N Y N N
120 RW|C C C N N N N N N N N N Y N N
122 Deny R |C C C N N N N Y N N N N N Y N
123 Read W |C C C N N N N N N N Y N N Y N
124 RW|C C C N N N N N N N N N N Y N
126 Deny R |2 C C N N N Y Y Y N N N Y Y Y
127 None W |C C C N N N N N N Y Y Y Y Y Y
128 RW|C C C N N N N N N N N N Y Y Y
129 Legend: Y = open succeeds, N = open fails with error code 05h
130 C = open fails, INT 24 generated
131 1 = open succeeds if file read-only, else fails with error code
132 2 = open succeeds if file read-only, else fails with INT 24
133 ========end of description from Ralph Brown's List =====
134 For every "Y" in the table we return FALSE
135 For every "N" we set the DOS_ERROR and return TRUE
136 For all other cases we barf,set the DOS_ERROR and return TRUE
139 static BOOL
FILE_ShareDeny( int mode
, int oldmode
)
141 int oldsharemode
= oldmode
& 0x70;
142 int sharemode
= mode
& 0x70;
143 int oldopenmode
= oldmode
& 3;
144 int openmode
= mode
& 3;
146 switch (oldsharemode
)
148 case OF_SHARE_COMPAT
:
149 if (sharemode
== OF_SHARE_COMPAT
) return FALSE
;
150 if (openmode
== OF_READ
) goto test_ro_err05
;
152 case OF_SHARE_EXCLUSIVE
:
153 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
155 case OF_SHARE_DENY_WRITE
:
156 if (openmode
!= OF_READ
)
158 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
163 case OF_SHARE_COMPAT
:
164 if (oldopenmode
== OF_READ
) goto test_ro_int24
;
166 case OF_SHARE_DENY_NONE
:
168 case OF_SHARE_DENY_WRITE
:
169 if (oldopenmode
== OF_READ
) return FALSE
;
170 case OF_SHARE_DENY_READ
:
171 if (oldopenmode
== OF_WRITE
) return FALSE
;
172 case OF_SHARE_EXCLUSIVE
:
177 case OF_SHARE_DENY_READ
:
178 if (openmode
!= OF_WRITE
)
180 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
185 case OF_SHARE_COMPAT
:
187 case OF_SHARE_DENY_NONE
:
189 case OF_SHARE_DENY_WRITE
:
190 if (oldopenmode
== OF_READ
) return FALSE
;
191 case OF_SHARE_DENY_READ
:
192 if (oldopenmode
== OF_WRITE
) return FALSE
;
193 case OF_SHARE_EXCLUSIVE
:
198 case OF_SHARE_DENY_NONE
:
201 case OF_SHARE_COMPAT
:
203 case OF_SHARE_DENY_NONE
:
205 case OF_SHARE_DENY_WRITE
:
206 if (oldopenmode
== OF_READ
) return FALSE
;
207 case OF_SHARE_DENY_READ
:
208 if (oldopenmode
== OF_WRITE
) return FALSE
;
209 case OF_SHARE_EXCLUSIVE
:
214 ERR(file
,"unknown mode\n");
216 ERR(file
,"shouldn't happen\n");
217 ERR(file
,"Please report to bon@elektron.ikp.physik.tu-darmstadt.de\n");
221 if (oldmode
== OF_READ
)
225 FIXME(file
,"generate INT24 missing\n");
226 /* Is this the right error? */
227 SetLastError( ERROR_ACCESS_DENIED
);
231 if (oldmode
== OF_READ
)
235 TRACE(file
,"Access Denied, oldmode 0x%02x mode 0x%02x\n",oldmode
,mode
);
236 SetLastError( ERROR_ACCESS_DENIED
);
242 /***********************************************************************
245 * Set the DOS error code from errno.
247 void FILE_SetDosError(void)
249 int save_errno
= errno
; /* errno gets overwritten by printf */
251 TRACE(file
, "errno = %d %s\n", errno
, strerror(errno
));
255 SetLastError( ERROR_SHARING_VIOLATION
);
258 SetLastError( ERROR_INVALID_HANDLE
);
261 SetLastError( ERROR_HANDLE_DISK_FULL
);
266 SetLastError( ERROR_ACCESS_DENIED
);
269 SetLastError( ERROR_LOCK_VIOLATION
);
272 SetLastError( ERROR_FILE_NOT_FOUND
);
275 SetLastError( ERROR_CANNOT_MAKE
);
279 SetLastError( ERROR_NO_MORE_FILES
);
282 SetLastError( ERROR_FILE_EXISTS
);
286 SetLastError( ERROR_SEEK
);
289 SetLastError( ERROR_DIR_NOT_EMPTY
);
292 perror( "int21: unknown errno" );
293 SetLastError( ERROR_GEN_FAILURE
);
300 /***********************************************************************
303 * Duplicate a Unix handle into a task handle.
305 HFILE
FILE_DupUnixHandle( int fd
, DWORD access
)
308 struct create_file_request req
;
309 struct create_file_reply reply
;
311 if ((unix_handle
= dup(fd
)) == -1)
314 return INVALID_HANDLE_VALUE
;
318 req
.sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
322 CLIENT_SendRequest( REQ_CREATE_FILE
, unix_handle
, 1,
324 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
329 /***********************************************************************
332 * Implementation of CreateFile. Takes a Unix path name.
334 HFILE
FILE_CreateFile( LPCSTR filename
, DWORD access
, DWORD sharing
,
335 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
336 DWORD attributes
, HANDLE
template )
338 struct create_file_request req
;
339 struct create_file_reply reply
;
342 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
343 req
.sharing
= sharing
;
344 req
.create
= creation
;
345 req
.attrs
= attributes
;
346 CLIENT_SendRequest( REQ_CREATE_FILE
, -1, 2,
348 filename
, strlen(filename
) + 1 );
350 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
352 /* If write access failed, retry without GENERIC_WRITE */
354 if ((reply
.handle
== -1) && !Options
.failReadOnly
&&
355 (access
& GENERIC_WRITE
))
357 DWORD lasterror
= GetLastError();
358 if ((lasterror
== ERROR_ACCESS_DENIED
) ||
359 (lasterror
== ERROR_WRITE_PROTECT
))
361 req
.access
&= ~GENERIC_WRITE
;
362 CLIENT_SendRequest( REQ_CREATE_FILE
, -1, 2,
364 filename
, strlen(filename
) + 1 );
366 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
373 /***********************************************************************
376 * Same as FILE_CreateFile but for a device
378 HFILE
FILE_CreateDevice( int client_id
, DWORD access
, LPSECURITY_ATTRIBUTES sa
)
380 struct create_device_request req
;
381 struct create_device_reply reply
;
384 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
386 CLIENT_SendRequest( REQ_CREATE_DEVICE
, -1, 1, &req
, sizeof(req
) );
388 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
393 /*************************************************************************
394 * CreateFile32A [KERNEL32.45] Creates or opens a file or other object
396 * Creates or opens an object, and returns a handle that can be used to
397 * access that object.
401 * filename [I] pointer to filename to be accessed
402 * access [I] access mode requested
403 * sharing [I] share mode
404 * sa [I] pointer to security attributes
405 * creation [I] how to create the file
406 * attributes [I] attributes for newly created file
407 * template [I] handle to file with extended attributes to copy
410 * Success: Open handle to specified file
411 * Failure: INVALID_HANDLE_VALUE
414 * Should call SetLastError() on failure.
418 * Doesn't support character devices, pipes, template files, or a
419 * lot of the 'attributes' flags yet.
421 HFILE WINAPI
CreateFileA( LPCSTR filename
, DWORD access
, DWORD sharing
,
422 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
423 DWORD attributes
, HANDLE
template )
425 DOS_FULL_NAME full_name
;
429 SetLastError( ERROR_INVALID_PARAMETER
);
432 TRACE(file
,"%s %s%s%s%s%s%s%s\n",filename
,
433 ((access
& GENERIC_READ
)==GENERIC_READ
)?"GENERIC_READ ":"",
434 ((access
& GENERIC_WRITE
)==GENERIC_WRITE
)?"GENERIC_WRITE ":"",
435 (!access
)?"QUERY_ACCESS ":"",
436 ((sharing
& FILE_SHARE_READ
)==FILE_SHARE_READ
)?"FILE_SHARE_READ ":"",
437 ((sharing
& FILE_SHARE_WRITE
)==FILE_SHARE_WRITE
)?"FILE_SHARE_WRITE ":"",
438 ((sharing
& FILE_SHARE_DELETE
)==FILE_SHARE_DELETE
)?"FILE_SHARE_DELETE ":"",
439 (creation
==CREATE_NEW
)?"CREATE_NEW":
440 (creation
==CREATE_ALWAYS
)?"CREATE_ALWAYS ":
441 (creation
==OPEN_EXISTING
)?"OPEN_EXISTING ":
442 (creation
==OPEN_ALWAYS
)?"OPEN_ALWAYS ":
443 (creation
==TRUNCATE_EXISTING
)?"TRUNCATE_EXISTING ":"");
445 /* If the name starts with '\\?\', ignore the first 4 chars. */
446 if (!strncmp(filename
, "\\\\?\\", 4))
449 if (!strncmp(filename
, "UNC\\", 4))
451 FIXME( file
, "UNC name (%s) not supported.\n", filename
);
452 SetLastError( ERROR_PATH_NOT_FOUND
);
457 if (!strncmp(filename
, "\\\\.\\", 4))
458 return DEVICE_Open( filename
+4, access
, sa
);
460 /* If the name still starts with '\\', it's a UNC name. */
461 if (!strncmp(filename
, "\\\\", 2))
463 FIXME( file
, "UNC name (%s) not supported.\n", filename
);
464 SetLastError( ERROR_PATH_NOT_FOUND
);
468 /* Open a console for CONIN$ or CONOUT$ */
469 if (!lstrcmpiA(filename
, "CONIN$")) return CONSOLE_OpenHandle( FALSE
, access
, sa
);
470 if (!lstrcmpiA(filename
, "CONOUT$")) return CONSOLE_OpenHandle( TRUE
, access
, sa
);
472 if (DOSFS_GetDevice( filename
))
476 TRACE(file
, "opening device '%s'\n", filename
);
478 if (HFILE_ERROR
!=(ret
=DOSFS_OpenDevice( filename
, access
)))
481 /* Do not silence this please. It is a critical error. -MM */
482 ERR(file
, "Couldn't open device '%s'!\n",filename
);
483 SetLastError( ERROR_FILE_NOT_FOUND
);
487 /* check for filename, don't check for last entry if creating */
488 if (!DOSFS_GetFullName( filename
,
489 (creation
== OPEN_EXISTING
) || (creation
== TRUNCATE_EXISTING
), &full_name
))
492 return FILE_CreateFile( full_name
.long_name
, access
, sharing
,
493 sa
, creation
, attributes
, template );
498 /*************************************************************************
499 * CreateFile32W (KERNEL32.48)
501 HFILE WINAPI
CreateFileW( LPCWSTR filename
, DWORD access
, DWORD sharing
,
502 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
503 DWORD attributes
, HANDLE
template)
505 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
506 HFILE res
= CreateFileA( afn
, access
, sharing
, sa
, creation
, attributes
, template );
507 HeapFree( GetProcessHeap(), 0, afn
);
512 /***********************************************************************
515 * Fill a file information from a struct stat.
517 static void FILE_FillInfo( struct stat
*st
, BY_HANDLE_FILE_INFORMATION
*info
)
519 if (S_ISDIR(st
->st_mode
))
520 info
->dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
522 info
->dwFileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
523 if (!(st
->st_mode
& S_IWUSR
))
524 info
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
526 DOSFS_UnixTimeToFileTime( st
->st_mtime
, &info
->ftCreationTime
, 0 );
527 DOSFS_UnixTimeToFileTime( st
->st_mtime
, &info
->ftLastWriteTime
, 0 );
528 DOSFS_UnixTimeToFileTime( st
->st_atime
, &info
->ftLastAccessTime
, 0 );
530 info
->dwVolumeSerialNumber
= 0; /* FIXME */
531 info
->nFileSizeHigh
= 0;
532 info
->nFileSizeLow
= S_ISDIR(st
->st_mode
) ? 0 : st
->st_size
;
533 info
->nNumberOfLinks
= st
->st_nlink
;
534 info
->nFileIndexHigh
= 0;
535 info
->nFileIndexLow
= st
->st_ino
;
539 /***********************************************************************
542 * Stat a Unix path name. Return TRUE if OK.
544 BOOL
FILE_Stat( LPCSTR unixName
, BY_HANDLE_FILE_INFORMATION
*info
)
548 if (!unixName
|| !info
) return FALSE
;
550 if (stat( unixName
, &st
) == -1)
555 FILE_FillInfo( &st
, info
);
560 /***********************************************************************
561 * GetFileInformationByHandle (KERNEL32.219)
563 DWORD WINAPI
GetFileInformationByHandle( HFILE hFile
,
564 BY_HANDLE_FILE_INFORMATION
*info
)
566 struct get_file_info_request req
;
567 struct get_file_info_reply reply
;
571 CLIENT_SendRequest( REQ_GET_FILE_INFO
, -1, 1, &req
, sizeof(req
) );
572 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
))
574 DOSFS_UnixTimeToFileTime( reply
.write_time
, &info
->ftCreationTime
, 0 );
575 DOSFS_UnixTimeToFileTime( reply
.write_time
, &info
->ftLastWriteTime
, 0 );
576 DOSFS_UnixTimeToFileTime( reply
.access_time
, &info
->ftLastAccessTime
, 0 );
577 info
->dwFileAttributes
= reply
.attr
;
578 info
->dwVolumeSerialNumber
= reply
.serial
;
579 info
->nFileSizeHigh
= reply
.size_high
;
580 info
->nFileSizeLow
= reply
.size_low
;
581 info
->nNumberOfLinks
= reply
.links
;
582 info
->nFileIndexHigh
= reply
.index_high
;
583 info
->nFileIndexLow
= reply
.index_low
;
588 /**************************************************************************
589 * GetFileAttributes16 (KERNEL.420)
591 DWORD WINAPI
GetFileAttributes16( LPCSTR name
)
593 return GetFileAttributesA( name
);
597 /**************************************************************************
598 * GetFileAttributes32A (KERNEL32.217)
600 DWORD WINAPI
GetFileAttributesA( LPCSTR name
)
602 DOS_FULL_NAME full_name
;
603 BY_HANDLE_FILE_INFORMATION info
;
605 if (name
== NULL
|| *name
=='\0') return -1;
607 if (!DOSFS_GetFullName( name
, TRUE
, &full_name
)) return -1;
608 if (!FILE_Stat( full_name
.long_name
, &info
)) return -1;
609 return info
.dwFileAttributes
;
613 /**************************************************************************
614 * GetFileAttributes32W (KERNEL32.218)
616 DWORD WINAPI
GetFileAttributesW( LPCWSTR name
)
618 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
619 DWORD res
= GetFileAttributesA( nameA
);
620 HeapFree( GetProcessHeap(), 0, nameA
);
625 /***********************************************************************
626 * GetFileSize (KERNEL32.220)
628 DWORD WINAPI
GetFileSize( HFILE hFile
, LPDWORD filesizehigh
)
630 BY_HANDLE_FILE_INFORMATION info
;
631 if (!GetFileInformationByHandle( hFile
, &info
)) return 0;
632 if (filesizehigh
) *filesizehigh
= info
.nFileSizeHigh
;
633 return info
.nFileSizeLow
;
637 /***********************************************************************
638 * GetFileTime (KERNEL32.221)
640 BOOL WINAPI
GetFileTime( HFILE hFile
, FILETIME
*lpCreationTime
,
641 FILETIME
*lpLastAccessTime
,
642 FILETIME
*lpLastWriteTime
)
644 BY_HANDLE_FILE_INFORMATION info
;
645 if (!GetFileInformationByHandle( hFile
, &info
)) return FALSE
;
646 if (lpCreationTime
) *lpCreationTime
= info
.ftCreationTime
;
647 if (lpLastAccessTime
) *lpLastAccessTime
= info
.ftLastAccessTime
;
648 if (lpLastWriteTime
) *lpLastWriteTime
= info
.ftLastWriteTime
;
652 /***********************************************************************
653 * CompareFileTime (KERNEL32.28)
655 INT WINAPI
CompareFileTime( LPFILETIME x
, LPFILETIME y
)
657 if (!x
|| !y
) return -1;
659 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
661 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
663 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
665 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
671 /***********************************************************************
672 * GetTempFileName16 (KERNEL.97)
674 UINT16 WINAPI
GetTempFileName16( BYTE drive
, LPCSTR prefix
, UINT16 unique
,
679 if (!(drive
& ~TF_FORCEDRIVE
)) /* drive 0 means current default drive */
680 drive
|= DRIVE_GetCurrentDrive() + 'A';
682 if ((drive
& TF_FORCEDRIVE
) &&
683 !DRIVE_IsValid( toupper(drive
& ~TF_FORCEDRIVE
) - 'A' ))
685 drive
&= ~TF_FORCEDRIVE
;
686 WARN(file
, "invalid drive %d specified\n", drive
);
689 if (drive
& TF_FORCEDRIVE
)
690 sprintf(temppath
,"%c:", drive
& ~TF_FORCEDRIVE
);
692 GetTempPathA( 132, temppath
);
693 return (UINT16
)GetTempFileNameA( temppath
, prefix
, unique
, buffer
);
697 /***********************************************************************
698 * GetTempFileName32A (KERNEL32.290)
700 UINT WINAPI
GetTempFileNameA( LPCSTR path
, LPCSTR prefix
, UINT unique
,
703 static UINT unique_temp
;
704 DOS_FULL_NAME full_name
;
709 if ( !path
|| !prefix
|| !buffer
) return 0;
711 if (!unique_temp
) unique_temp
= time(NULL
) & 0xffff;
712 num
= unique
? (unique
& 0xffff) : (unique_temp
++ & 0xffff);
714 strcpy( buffer
, path
);
715 p
= buffer
+ strlen(buffer
);
717 /* add a \, if there isn't one and path is more than just the drive letter ... */
718 if ( !((strlen(buffer
) == 2) && (buffer
[1] == ':'))
719 && ((p
== buffer
) || (p
[-1] != '\\'))) *p
++ = '\\';
722 for (i
= 3; (i
> 0) && (*prefix
); i
--) *p
++ = *prefix
++;
723 sprintf( p
, "%04x.tmp", num
);
725 /* Now try to create it */
731 HFILE handle
= CreateFileA( buffer
, GENERIC_WRITE
, 0, NULL
,
732 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, -1 );
733 if (handle
!= INVALID_HANDLE_VALUE
)
734 { /* We created it */
735 TRACE(file
, "created %s\n",
737 CloseHandle( handle
);
740 if (GetLastError() != ERROR_FILE_EXISTS
)
741 break; /* No need to go on */
743 sprintf( p
, "%04x.tmp", num
);
744 } while (num
!= (unique
& 0xffff));
747 /* Get the full path name */
749 if (DOSFS_GetFullName( buffer
, FALSE
, &full_name
))
751 /* Check if we have write access in the directory */
752 if ((p
= strrchr( full_name
.long_name
, '/' ))) *p
= '\0';
753 if (access( full_name
.long_name
, W_OK
) == -1)
754 WARN(file
, "returns '%s', which doesn't seem to be writeable.\n",
757 TRACE(file
, "returning %s\n", buffer
);
758 return unique
? unique
: num
;
762 /***********************************************************************
763 * GetTempFileName32W (KERNEL32.291)
765 UINT WINAPI
GetTempFileNameW( LPCWSTR path
, LPCWSTR prefix
, UINT unique
,
773 patha
= HEAP_strdupWtoA( GetProcessHeap(), 0, path
);
774 prefixa
= HEAP_strdupWtoA( GetProcessHeap(), 0, prefix
);
775 ret
= GetTempFileNameA( patha
, prefixa
, unique
, buffera
);
776 lstrcpyAtoW( buffer
, buffera
);
777 HeapFree( GetProcessHeap(), 0, patha
);
778 HeapFree( GetProcessHeap(), 0, prefixa
);
783 /***********************************************************************
786 * Implementation of OpenFile16() and OpenFile32().
788 static HFILE
FILE_DoOpenFile( LPCSTR name
, OFSTRUCT
*ofs
, UINT mode
,
793 WORD filedatetime
[2];
794 DOS_FULL_NAME full_name
;
795 DWORD access
, sharing
;
798 if (!ofs
) return HFILE_ERROR
;
800 TRACE(file
,"%s %s %s %s%s%s%s%s%s%s%s%s\n",name
,
801 ((mode
& 0x3 )==OF_READ
)?"OF_READ":
802 ((mode
& 0x3 )==OF_WRITE
)?"OF_WRITE":
803 ((mode
& 0x3 )==OF_READWRITE
)?"OF_READWRITE":"unknown",
804 ((mode
& 0x70 )==OF_SHARE_COMPAT
)?"OF_SHARE_COMPAT":
805 ((mode
& 0x70 )==OF_SHARE_DENY_NONE
)?"OF_SHARE_DENY_NONE":
806 ((mode
& 0x70 )==OF_SHARE_DENY_READ
)?"OF_SHARE_DENY_READ":
807 ((mode
& 0x70 )==OF_SHARE_DENY_WRITE
)?"OF_SHARE_DENY_WRITE":
808 ((mode
& 0x70 )==OF_SHARE_EXCLUSIVE
)?"OF_SHARE_EXCLUSIVE":"unknown",
809 ((mode
& OF_PARSE
)==OF_PARSE
)?"OF_PARSE ":"",
810 ((mode
& OF_DELETE
)==OF_DELETE
)?"OF_DELETE ":"",
811 ((mode
& OF_VERIFY
)==OF_VERIFY
)?"OF_VERIFY ":"",
812 ((mode
& OF_SEARCH
)==OF_SEARCH
)?"OF_SEARCH ":"",
813 ((mode
& OF_CANCEL
)==OF_CANCEL
)?"OF_CANCEL ":"",
814 ((mode
& OF_CREATE
)==OF_CREATE
)?"OF_CREATE ":"",
815 ((mode
& OF_PROMPT
)==OF_PROMPT
)?"OF_PROMPT ":"",
816 ((mode
& OF_EXIST
)==OF_EXIST
)?"OF_EXIST ":"",
817 ((mode
& OF_REOPEN
)==OF_REOPEN
)?"OF_REOPEN ":""
821 ofs
->cBytes
= sizeof(OFSTRUCT
);
823 if (mode
& OF_REOPEN
) name
= ofs
->szPathName
;
826 ERR(file
, "called with `name' set to NULL ! Please debug.\n");
830 TRACE(file
, "%s %04x\n", name
, mode
);
832 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
833 Are there any cases where getting the path here is wrong?
834 Uwe Bonnes 1997 Apr 2 */
835 if (!GetFullPathNameA( name
, sizeof(ofs
->szPathName
),
836 ofs
->szPathName
, NULL
)) goto error
;
837 FILE_ConvertOFMode( mode
, &access
, &sharing
);
839 /* OF_PARSE simply fills the structure */
843 ofs
->fFixedDisk
= (GetDriveType16( ofs
->szPathName
[0]-'A' )
845 TRACE(file
, "(%s): OF_PARSE, res = '%s'\n",
846 name
, ofs
->szPathName
);
850 /* OF_CREATE is completely different from all other options, so
853 if (mode
& OF_CREATE
)
855 if ((hFileRet
= CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
856 sharing
, NULL
, CREATE_ALWAYS
,
857 FILE_ATTRIBUTE_NORMAL
, -1 ))== INVALID_HANDLE_VALUE
)
862 /* If OF_SEARCH is set, ignore the given path */
864 if ((mode
& OF_SEARCH
) && !(mode
& OF_REOPEN
))
866 /* First try the file name as is */
867 if (DOSFS_GetFullName( name
, TRUE
, &full_name
)) goto found
;
868 /* Now remove the path */
869 if (name
[0] && (name
[1] == ':')) name
+= 2;
870 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
871 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
872 if (!name
[0]) goto not_found
;
875 /* Now look for the file */
877 if (!DIR_SearchPath( NULL
, name
, NULL
, &full_name
, win32
)) goto not_found
;
880 TRACE(file
, "found %s = %s\n",
881 full_name
.long_name
, full_name
.short_name
);
882 lstrcpynA( ofs
->szPathName
, full_name
.short_name
,
883 sizeof(ofs
->szPathName
) );
885 if (mode
& OF_SHARE_EXCLUSIVE
)
886 /* Some InstallShield version uses OF_SHARE_EXCLUSIVE
887 on the file <tempdir>/_ins0432._mp to determine how
888 far installation has proceeded.
889 _ins0432._mp is an executable and while running the
890 application expects the open with OF_SHARE_ to fail*/
892 As our loader closes the files after loading the executable,
893 we can't find the running executable with FILE_InUse.
894 Perhaps the loader should keep the file open.
895 Recheck against how Win handles that case */
897 char *last
= strrchr(full_name
.long_name
,'/');
899 last
= full_name
.long_name
- 1;
900 if (GetModuleHandle16(last
+1))
902 TRACE(file
,"Denying shared open for %s\n",full_name
.long_name
);
907 if (mode
& OF_DELETE
)
909 if (unlink( full_name
.long_name
) == -1) goto not_found
;
910 TRACE(file
, "(%s): OF_DELETE return = OK\n", name
);
914 hFileRet
= FILE_CreateFile( full_name
.long_name
, access
, sharing
,
915 NULL
, OPEN_EXISTING
, 0, -1 );
916 if (hFileRet
== HFILE_ERROR
) goto not_found
;
918 GetFileTime( hFileRet
, NULL
, NULL
, &filetime
);
919 FileTimeToDosDateTime( &filetime
, &filedatetime
[0], &filedatetime
[1] );
920 if ((mode
& OF_VERIFY
) && (mode
& OF_REOPEN
))
922 if (memcmp( ofs
->reserved
, filedatetime
, sizeof(ofs
->reserved
) ))
924 CloseHandle( hFileRet
);
925 WARN(file
, "(%s): OF_VERIFY failed\n", name
);
926 /* FIXME: what error here? */
927 SetLastError( ERROR_FILE_NOT_FOUND
);
931 memcpy( ofs
->reserved
, filedatetime
, sizeof(ofs
->reserved
) );
933 success
: /* We get here if the open was successful */
934 TRACE(file
, "(%s): OK, return = %d\n", name
, hFileRet
);
937 if (mode
& OF_EXIST
) /* Return the handle, but close it first */
938 CloseHandle( hFileRet
);
942 hFileRet
= FILE_AllocDosHandle( hFileRet
);
943 if (hFileRet
== HFILE_ERROR16
) goto error
;
944 if (mode
& OF_EXIST
) /* Return the handle, but close it first */
945 _lclose16( hFileRet
);
949 not_found
: /* We get here if the file does not exist */
950 WARN(file
, "'%s' not found\n", name
);
951 SetLastError( ERROR_FILE_NOT_FOUND
);
954 error
: /* We get here if there was an error opening the file */
955 ofs
->nErrCode
= GetLastError();
956 WARN(file
, "(%s): return = HFILE_ERROR error= %d\n",
957 name
,ofs
->nErrCode
);
962 /***********************************************************************
963 * OpenFile16 (KERNEL.74)
965 HFILE16 WINAPI
OpenFile16( LPCSTR name
, OFSTRUCT
*ofs
, UINT16 mode
)
967 return FILE_DoOpenFile( name
, ofs
, mode
, FALSE
);
971 /***********************************************************************
972 * OpenFile32 (KERNEL32.396)
974 HFILE WINAPI
OpenFile( LPCSTR name
, OFSTRUCT
*ofs
, UINT mode
)
976 return FILE_DoOpenFile( name
, ofs
, mode
, TRUE
);
980 /***********************************************************************
981 * FILE_InitProcessDosHandles
983 * Allocates the default DOS handles for a process. Called either by
984 * AllocDosHandle below or by the DOSVM stuff.
986 BOOL
FILE_InitProcessDosHandles( void ) {
989 if (!(ptr
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
,
990 sizeof(*ptr
) * DOS_TABLE_SIZE
)))
992 PROCESS_Current()->dos_handles
= ptr
;
993 ptr
[0] = GetStdHandle(STD_INPUT_HANDLE
);
994 ptr
[1] = GetStdHandle(STD_OUTPUT_HANDLE
);
995 ptr
[2] = GetStdHandle(STD_ERROR_HANDLE
);
996 ptr
[3] = GetStdHandle(STD_ERROR_HANDLE
);
997 ptr
[4] = GetStdHandle(STD_ERROR_HANDLE
);
1001 /***********************************************************************
1002 * FILE_AllocDosHandle
1004 * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
1005 * longer valid after this function (even on failure).
1007 HFILE16
FILE_AllocDosHandle( HANDLE handle
)
1010 HANDLE
*ptr
= PROCESS_Current()->dos_handles
;
1012 if (!handle
|| (handle
== INVALID_HANDLE_VALUE
))
1013 return INVALID_HANDLE_VALUE16
;
1016 if (!FILE_InitProcessDosHandles())
1018 ptr
= PROCESS_Current()->dos_handles
;
1021 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++, ptr
++)
1025 TRACE( file
, "Got %d for h32 %d\n", i
, handle
);
1029 CloseHandle( handle
);
1030 SetLastError( ERROR_TOO_MANY_OPEN_FILES
);
1031 return INVALID_HANDLE_VALUE16
;
1035 /***********************************************************************
1038 * Return the Win32 handle for a DOS handle.
1040 HANDLE
FILE_GetHandle( HFILE16 hfile
)
1042 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1043 if ((hfile
>= DOS_TABLE_SIZE
) || !table
|| !table
[hfile
])
1045 SetLastError( ERROR_INVALID_HANDLE
);
1046 return INVALID_HANDLE_VALUE
;
1048 return table
[hfile
];
1052 /***********************************************************************
1055 * dup2() function for DOS handles.
1057 HFILE16
FILE_Dup2( HFILE16 hFile1
, HFILE16 hFile2
)
1059 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1062 if ((hFile1
>= DOS_TABLE_SIZE
) || (hFile2
>= DOS_TABLE_SIZE
) ||
1063 !table
|| !table
[hFile1
])
1065 SetLastError( ERROR_INVALID_HANDLE
);
1066 return HFILE_ERROR16
;
1070 FIXME( file
, "stdio handle closed, need proper conversion\n" );
1071 SetLastError( ERROR_INVALID_HANDLE
);
1072 return HFILE_ERROR16
;
1074 if (!DuplicateHandle( GetCurrentProcess(), table
[hFile1
],
1075 GetCurrentProcess(), &new_handle
,
1076 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1077 return HFILE_ERROR16
;
1078 if (table
[hFile2
]) CloseHandle( table
[hFile2
] );
1079 table
[hFile2
] = new_handle
;
1084 /***********************************************************************
1085 * _lclose16 (KERNEL.81)
1087 HFILE16 WINAPI
_lclose16( HFILE16 hFile
)
1089 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1093 FIXME( file
, "stdio handle closed, need proper conversion\n" );
1094 SetLastError( ERROR_INVALID_HANDLE
);
1095 return HFILE_ERROR16
;
1097 if ((hFile
>= DOS_TABLE_SIZE
) || !table
|| !table
[hFile
])
1099 SetLastError( ERROR_INVALID_HANDLE
);
1100 return HFILE_ERROR16
;
1102 TRACE( file
, "%d (handle32=%d)\n", hFile
, table
[hFile
] );
1103 CloseHandle( table
[hFile
] );
1109 /***********************************************************************
1110 * _lclose32 (KERNEL32.592)
1112 HFILE WINAPI
_lclose( HFILE hFile
)
1114 TRACE(file
, "handle %d\n", hFile
);
1115 return CloseHandle( hFile
) ? 0 : HFILE_ERROR
;
1119 /***********************************************************************
1120 * ReadFile (KERNEL32.428)
1122 BOOL WINAPI
ReadFile( HANDLE hFile
, LPVOID buffer
, DWORD bytesToRead
,
1123 LPDWORD bytesRead
, LPOVERLAPPED overlapped
)
1125 struct get_read_fd_request req
;
1126 int unix_handle
, result
;
1128 TRACE(file
, "%d %p %ld\n", hFile
, buffer
, bytesToRead
);
1130 if (bytesRead
) *bytesRead
= 0; /* Do this before anything else */
1131 if (!bytesToRead
) return TRUE
;
1134 CLIENT_SendRequest( REQ_GET_READ_FD
, -1, 1, &req
, sizeof(req
) );
1135 CLIENT_WaitReply( NULL
, &unix_handle
, 0 );
1136 if (unix_handle
== -1) return FALSE
;
1137 while ((result
= read( unix_handle
, buffer
, bytesToRead
)) == -1)
1139 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
1140 if ((errno
== EFAULT
) && VIRTUAL_HandleFault( buffer
)) continue;
1144 close( unix_handle
);
1145 if (result
== -1) return FALSE
;
1146 if (bytesRead
) *bytesRead
= result
;
1151 /***********************************************************************
1152 * WriteFile (KERNEL32.578)
1154 BOOL WINAPI
WriteFile( HANDLE hFile
, LPCVOID buffer
, DWORD bytesToWrite
,
1155 LPDWORD bytesWritten
, LPOVERLAPPED overlapped
)
1157 struct get_write_fd_request req
;
1158 int unix_handle
, result
;
1160 TRACE(file
, "%d %p %ld\n", hFile
, buffer
, bytesToWrite
);
1162 if (bytesWritten
) *bytesWritten
= 0; /* Do this before anything else */
1163 if (!bytesToWrite
) return TRUE
;
1166 CLIENT_SendRequest( REQ_GET_WRITE_FD
, -1, 1, &req
, sizeof(req
) );
1167 CLIENT_WaitReply( NULL
, &unix_handle
, 0 );
1168 if (unix_handle
== -1) return FALSE
;
1169 while ((result
= write( unix_handle
, buffer
, bytesToWrite
)) == -1)
1171 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
1172 if ((errno
== EFAULT
) && VIRTUAL_HandleFault( buffer
)) continue;
1176 close( unix_handle
);
1177 if (result
== -1) return FALSE
;
1178 if (bytesWritten
) *bytesWritten
= result
;
1183 /***********************************************************************
1186 LONG WINAPI
WIN16_hread( HFILE16 hFile
, SEGPTR buffer
, LONG count
)
1190 TRACE(file
, "%d %08lx %ld\n",
1191 hFile
, (DWORD
)buffer
, count
);
1193 /* Some programs pass a count larger than the allocated buffer */
1194 maxlen
= GetSelectorLimit16( SELECTOROF(buffer
) ) - OFFSETOF(buffer
) + 1;
1195 if (count
> maxlen
) count
= maxlen
;
1196 return _lread(FILE_GetHandle(hFile
), PTR_SEG_TO_LIN(buffer
), count
);
1200 /***********************************************************************
1203 UINT16 WINAPI
WIN16_lread( HFILE16 hFile
, SEGPTR buffer
, UINT16 count
)
1205 return (UINT16
)WIN16_hread( hFile
, buffer
, (LONG
)count
);
1209 /***********************************************************************
1210 * _lread32 (KERNEL32.596)
1212 UINT WINAPI
_lread( HFILE handle
, LPVOID buffer
, UINT count
)
1215 if (!ReadFile( handle
, buffer
, count
, &result
, NULL
)) return -1;
1220 /***********************************************************************
1221 * _lread16 (KERNEL.82)
1223 UINT16 WINAPI
_lread16( HFILE16 hFile
, LPVOID buffer
, UINT16 count
)
1225 return (UINT16
)_lread(FILE_GetHandle(hFile
), buffer
, (LONG
)count
);
1229 /***********************************************************************
1230 * _lcreat16 (KERNEL.83)
1232 HFILE16 WINAPI
_lcreat16( LPCSTR path
, INT16 attr
)
1234 return FILE_AllocDosHandle( _lcreat( path
, attr
) );
1238 /***********************************************************************
1239 * _lcreat (KERNEL32.593)
1241 HFILE WINAPI
_lcreat( LPCSTR path
, INT attr
)
1243 /* Mask off all flags not explicitly allowed by the doc */
1244 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
1245 TRACE(file
, "%s %02x\n", path
, attr
);
1246 return CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
1247 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1248 CREATE_ALWAYS
, attr
, -1 );
1252 /***********************************************************************
1253 * SetFilePointer (KERNEL32.492)
1255 DWORD WINAPI
SetFilePointer( HFILE hFile
, LONG distance
, LONG
*highword
,
1258 struct set_file_pointer_request req
;
1259 struct set_file_pointer_reply reply
;
1261 if (highword
&& *highword
)
1263 FIXME(file
, "64-bit offsets not supported yet\n");
1264 SetLastError( ERROR_INVALID_PARAMETER
);
1267 TRACE(file
, "handle %d offset %ld origin %ld\n",
1268 hFile
, distance
, method
);
1272 req
.high
= highword
? *highword
: 0;
1273 /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */
1274 req
.whence
= method
;
1275 CLIENT_SendRequest( REQ_SET_FILE_POINTER
, -1, 1, &req
, sizeof(req
) );
1276 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return 0xffffffff;
1278 if (highword
) *highword
= reply
.high
;
1283 /***********************************************************************
1284 * _llseek16 (KERNEL.84)
1287 * Seeking before the start of the file should be allowed for _llseek16,
1288 * but cause subsequent I/O operations to fail (cf. interrupt list)
1291 LONG WINAPI
_llseek16( HFILE16 hFile
, LONG lOffset
, INT16 nOrigin
)
1293 return SetFilePointer( FILE_GetHandle(hFile
), lOffset
, NULL
, nOrigin
);
1297 /***********************************************************************
1298 * _llseek32 (KERNEL32.594)
1300 LONG WINAPI
_llseek( HFILE hFile
, LONG lOffset
, INT nOrigin
)
1302 return SetFilePointer( hFile
, lOffset
, NULL
, nOrigin
);
1306 /***********************************************************************
1307 * _lopen16 (KERNEL.85)
1309 HFILE16 WINAPI
_lopen16( LPCSTR path
, INT16 mode
)
1311 return FILE_AllocDosHandle( _lopen( path
, mode
) );
1315 /***********************************************************************
1316 * _lopen32 (KERNEL32.595)
1318 HFILE WINAPI
_lopen( LPCSTR path
, INT mode
)
1320 DWORD access
, sharing
;
1322 TRACE(file
, "('%s',%04x)\n", path
, mode
);
1323 FILE_ConvertOFMode( mode
, &access
, &sharing
);
1324 return CreateFileA( path
, access
, sharing
, NULL
, OPEN_EXISTING
, 0, -1 );
1328 /***********************************************************************
1329 * _lwrite16 (KERNEL.86)
1331 UINT16 WINAPI
_lwrite16( HFILE16 hFile
, LPCSTR buffer
, UINT16 count
)
1333 return (UINT16
)_hwrite( FILE_GetHandle(hFile
), buffer
, (LONG
)count
);
1336 /***********************************************************************
1337 * _lwrite32 (KERNEL32.761)
1339 UINT WINAPI
_lwrite( HFILE hFile
, LPCSTR buffer
, UINT count
)
1341 return (UINT
)_hwrite( hFile
, buffer
, (LONG
)count
);
1345 /***********************************************************************
1346 * _hread16 (KERNEL.349)
1348 LONG WINAPI
_hread16( HFILE16 hFile
, LPVOID buffer
, LONG count
)
1350 return _lread( FILE_GetHandle(hFile
), buffer
, count
);
1354 /***********************************************************************
1355 * _hread32 (KERNEL32.590)
1357 LONG WINAPI
_hread( HFILE hFile
, LPVOID buffer
, LONG count
)
1359 return _lread( hFile
, buffer
, count
);
1363 /***********************************************************************
1364 * _hwrite16 (KERNEL.350)
1366 LONG WINAPI
_hwrite16( HFILE16 hFile
, LPCSTR buffer
, LONG count
)
1368 return _hwrite( FILE_GetHandle(hFile
), buffer
, count
);
1372 /***********************************************************************
1373 * _hwrite32 (KERNEL32.591)
1375 * experimentation yields that _lwrite:
1376 * o truncates the file at the current position with
1378 * o returns 0 on a 0 length write
1379 * o works with console handles
1382 LONG WINAPI
_hwrite( HFILE handle
, LPCSTR buffer
, LONG count
)
1386 TRACE(file
, "%d %p %ld\n", handle
, buffer
, count
);
1390 /* Expand or truncate at current position */
1391 if (!SetEndOfFile( handle
)) return HFILE_ERROR
;
1394 if (!WriteFile( handle
, buffer
, count
, &result
, NULL
))
1400 /***********************************************************************
1401 * SetHandleCount16 (KERNEL.199)
1403 UINT16 WINAPI
SetHandleCount16( UINT16 count
)
1405 HGLOBAL16 hPDB
= GetCurrentPDB16();
1406 PDB16
*pdb
= (PDB16
*)GlobalLock16( hPDB
);
1407 BYTE
*files
= PTR_SEG_TO_LIN( pdb
->fileHandlesPtr
);
1409 TRACE(file
, "(%d)\n", count
);
1411 if (count
< 20) count
= 20; /* No point in going below 20 */
1412 else if (count
> 254) count
= 254;
1416 if (pdb
->nbFiles
> 20)
1418 memcpy( pdb
->fileHandles
, files
, 20 );
1419 GlobalFree16( pdb
->hFileHandles
);
1420 pdb
->fileHandlesPtr
= (SEGPTR
)MAKELONG( 0x18,
1421 GlobalHandleToSel16( hPDB
) );
1422 pdb
->hFileHandles
= 0;
1426 else /* More than 20, need a new file handles table */
1429 HGLOBAL16 newhandle
= GlobalAlloc16( GMEM_MOVEABLE
, count
);
1432 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1433 return pdb
->nbFiles
;
1435 newfiles
= (BYTE
*)GlobalLock16( newhandle
);
1437 if (count
> pdb
->nbFiles
)
1439 memcpy( newfiles
, files
, pdb
->nbFiles
);
1440 memset( newfiles
+ pdb
->nbFiles
, 0xff, count
- pdb
->nbFiles
);
1442 else memcpy( newfiles
, files
, count
);
1443 if (pdb
->nbFiles
> 20) GlobalFree16( pdb
->hFileHandles
);
1444 pdb
->fileHandlesPtr
= WIN16_GlobalLock16( newhandle
);
1445 pdb
->hFileHandles
= newhandle
;
1446 pdb
->nbFiles
= count
;
1448 return pdb
->nbFiles
;
1452 /*************************************************************************
1453 * SetHandleCount32 (KERNEL32.494)
1455 UINT WINAPI
SetHandleCount( UINT count
)
1457 return MIN( 256, count
);
1461 /***********************************************************************
1462 * FlushFileBuffers (KERNEL32.133)
1464 BOOL WINAPI
FlushFileBuffers( HFILE hFile
)
1466 struct flush_file_request req
;
1469 CLIENT_SendRequest( REQ_FLUSH_FILE
, -1, 1, &req
, sizeof(req
) );
1470 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1474 /**************************************************************************
1475 * SetEndOfFile (KERNEL32.483)
1477 BOOL WINAPI
SetEndOfFile( HFILE hFile
)
1479 struct truncate_file_request req
;
1482 CLIENT_SendRequest( REQ_TRUNCATE_FILE
, -1, 1, &req
, sizeof(req
) );
1483 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1487 /***********************************************************************
1488 * DeleteFile16 (KERNEL.146)
1490 BOOL16 WINAPI
DeleteFile16( LPCSTR path
)
1492 return DeleteFileA( path
);
1496 /***********************************************************************
1497 * DeleteFile32A (KERNEL32.71)
1499 BOOL WINAPI
DeleteFileA( LPCSTR path
)
1501 DOS_FULL_NAME full_name
;
1503 TRACE(file
, "'%s'\n", path
);
1507 ERR(file
, "Empty path passed\n");
1510 if (DOSFS_GetDevice( path
))
1512 WARN(file
, "cannot remove DOS device '%s'!\n", path
);
1513 SetLastError( ERROR_FILE_NOT_FOUND
);
1517 if (!DOSFS_GetFullName( path
, TRUE
, &full_name
)) return FALSE
;
1518 if (unlink( full_name
.long_name
) == -1)
1527 /***********************************************************************
1528 * DeleteFile32W (KERNEL32.72)
1530 BOOL WINAPI
DeleteFileW( LPCWSTR path
)
1532 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, path
);
1533 BOOL ret
= DeleteFileA( xpath
);
1534 HeapFree( GetProcessHeap(), 0, xpath
);
1539 /***********************************************************************
1542 LPVOID
FILE_dommap( int unix_handle
, LPVOID start
,
1543 DWORD size_high
, DWORD size_low
,
1544 DWORD offset_high
, DWORD offset_low
,
1545 int prot
, int flags
)
1551 if (size_high
|| offset_high
)
1552 FIXME(file
, "offsets larger than 4Gb not supported\n");
1554 if (unix_handle
== -1)
1559 static int fdzero
= -1;
1563 if ((fdzero
= open( "/dev/zero", O_RDONLY
)) == -1)
1565 perror( "/dev/zero: open" );
1570 #endif /* MAP_ANON */
1571 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
1573 flags
&= ~MAP_SHARED
;
1576 flags
|= MAP_PRIVATE
;
1579 else fd
= unix_handle
;
1581 if ((ret
= mmap( start
, size_low
, prot
,
1582 flags
, fd
, offset_low
)) != (LPVOID
)-1)
1585 /* mmap() failed; if this is because the file offset is not */
1586 /* page-aligned (EINVAL), or because the underlying filesystem */
1587 /* does not support mmap() (ENOEXEC), we do it by hand. */
1589 if (unix_handle
== -1) return ret
;
1590 if ((errno
!= ENOEXEC
) && (errno
!= EINVAL
)) return ret
;
1591 if (prot
& PROT_WRITE
)
1593 /* We cannot fake shared write mappings */
1595 if (flags
& MAP_SHARED
) return ret
;
1598 if (!(flags
& MAP_PRIVATE
)) return ret
;
1601 /* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
1602 /* Reserve the memory with an anonymous mmap */
1603 ret
= FILE_dommap( -1, start
, size_high
, size_low
, 0, 0,
1604 PROT_READ
| PROT_WRITE
, flags
);
1605 if (ret
== (LPVOID
)-1) return ret
;
1606 /* Now read in the file */
1607 if ((pos
= lseek( fd
, offset_low
, SEEK_SET
)) == -1)
1609 FILE_munmap( ret
, size_high
, size_low
);
1612 read( fd
, ret
, size_low
);
1613 lseek( fd
, pos
, SEEK_SET
); /* Restore the file pointer */
1614 mprotect( ret
, size_low
, prot
); /* Set the right protection */
1619 /***********************************************************************
1622 int FILE_munmap( LPVOID start
, DWORD size_high
, DWORD size_low
)
1625 FIXME(file
, "offsets larger than 4Gb not supported\n");
1626 return munmap( start
, size_low
);
1630 /***********************************************************************
1631 * GetFileType (KERNEL32.222)
1633 DWORD WINAPI
GetFileType( HFILE hFile
)
1635 struct get_file_info_request req
;
1636 struct get_file_info_reply reply
;
1639 CLIENT_SendRequest( REQ_GET_FILE_INFO
, -1, 1, &req
, sizeof(req
) );
1640 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
))
1641 return FILE_TYPE_UNKNOWN
;
1646 /**************************************************************************
1647 * MoveFileEx32A (KERNEL32.???)
1649 BOOL WINAPI
MoveFileExA( LPCSTR fn1
, LPCSTR fn2
, DWORD flag
)
1651 DOS_FULL_NAME full_name1
, full_name2
;
1652 int mode
=0; /* mode == 1: use copy */
1654 TRACE(file
, "(%s,%s,%04lx)\n", fn1
, fn2
, flag
);
1656 if (!DOSFS_GetFullName( fn1
, TRUE
, &full_name1
)) return FALSE
;
1657 if (fn2
) { /* !fn2 means delete fn1 */
1658 if (!DOSFS_GetFullName( fn2
, FALSE
, &full_name2
)) return FALSE
;
1659 /* Source name and target path are valid */
1660 if ( full_name1
.drive
!= full_name2
.drive
)
1662 /* use copy, if allowed */
1663 if (!(flag
& MOVEFILE_COPY_ALLOWED
)) {
1664 /* FIXME: Use right error code */
1665 SetLastError( ERROR_FILE_EXISTS
);
1670 if (DOSFS_GetFullName( fn2
, TRUE
, &full_name2
))
1671 /* target exists, check if we may overwrite */
1672 if (!(flag
& MOVEFILE_REPLACE_EXISTING
)) {
1673 /* FIXME: Use right error code */
1674 SetLastError( ERROR_ACCESS_DENIED
);
1678 else /* fn2 == NULL means delete source */
1679 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
) {
1680 if (flag
& MOVEFILE_COPY_ALLOWED
) {
1681 WARN(file
, "Illegal flag\n");
1682 SetLastError( ERROR_GEN_FAILURE
);
1685 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1686 Perhaps we should queue these command and execute it
1687 when exiting... What about using on_exit(2)
1689 FIXME(file
, "Please delete file '%s' when Wine has finished\n",
1690 full_name1
.long_name
);
1693 else if (unlink( full_name1
.long_name
) == -1)
1698 else return TRUE
; /* successfully deleted */
1700 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
) {
1701 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1702 Perhaps we should queue these command and execute it
1703 when exiting... What about using on_exit(2)
1705 FIXME(file
,"Please move existing file '%s' to file '%s'"
1706 "when Wine has finished\n",
1707 full_name1
.long_name
, full_name2
.long_name
);
1711 if (!mode
) /* move the file */
1712 if (rename( full_name1
.long_name
, full_name2
.long_name
) == -1)
1718 else /* copy File */
1719 return CopyFileA(fn1
, fn2
, (!(flag
& MOVEFILE_REPLACE_EXISTING
)));
1723 /**************************************************************************
1724 * MoveFileEx32W (KERNEL32.???)
1726 BOOL WINAPI
MoveFileExW( LPCWSTR fn1
, LPCWSTR fn2
, DWORD flag
)
1728 LPSTR afn1
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn1
);
1729 LPSTR afn2
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn2
);
1730 BOOL res
= MoveFileExA( afn1
, afn2
, flag
);
1731 HeapFree( GetProcessHeap(), 0, afn1
);
1732 HeapFree( GetProcessHeap(), 0, afn2
);
1737 /**************************************************************************
1738 * MoveFile32A (KERNEL32.387)
1740 * Move file or directory
1742 BOOL WINAPI
MoveFileA( LPCSTR fn1
, LPCSTR fn2
)
1744 DOS_FULL_NAME full_name1
, full_name2
;
1747 TRACE(file
, "(%s,%s)\n", fn1
, fn2
);
1749 if (!DOSFS_GetFullName( fn1
, TRUE
, &full_name1
)) return FALSE
;
1750 if (DOSFS_GetFullName( fn2
, TRUE
, &full_name2
))
1751 /* The new name must not already exist */
1753 if (!DOSFS_GetFullName( fn2
, FALSE
, &full_name2
)) return FALSE
;
1755 if (full_name1
.drive
== full_name2
.drive
) /* move */
1756 if (rename( full_name1
.long_name
, full_name2
.long_name
) == -1)
1763 if (stat( full_name1
.long_name
, &fstat
))
1765 WARN(file
, "Invalid source file %s\n",
1766 full_name1
.long_name
);
1770 if (S_ISDIR(fstat
.st_mode
)) {
1771 /* No Move for directories across file systems */
1772 /* FIXME: Use right error code */
1773 SetLastError( ERROR_GEN_FAILURE
);
1777 return CopyFileA(fn1
, fn2
, TRUE
); /*fail, if exist */
1782 /**************************************************************************
1783 * MoveFile32W (KERNEL32.390)
1785 BOOL WINAPI
MoveFileW( LPCWSTR fn1
, LPCWSTR fn2
)
1787 LPSTR afn1
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn1
);
1788 LPSTR afn2
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn2
);
1789 BOOL res
= MoveFileA( afn1
, afn2
);
1790 HeapFree( GetProcessHeap(), 0, afn1
);
1791 HeapFree( GetProcessHeap(), 0, afn2
);
1796 /**************************************************************************
1797 * CopyFile32A (KERNEL32.36)
1799 BOOL WINAPI
CopyFileA( LPCSTR source
, LPCSTR dest
, BOOL fail_if_exists
)
1802 BY_HANDLE_FILE_INFORMATION info
;
1808 if ((h1
= _lopen( source
, OF_READ
)) == HFILE_ERROR
) return FALSE
;
1809 if (!GetFileInformationByHandle( h1
, &info
))
1814 mode
= (info
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
) ? 0444 : 0666;
1815 if ((h2
= CreateFileA( dest
, GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1816 fail_if_exists
? CREATE_NEW
: CREATE_ALWAYS
,
1817 info
.dwFileAttributes
, h1
)) == HFILE_ERROR
)
1822 while ((count
= _lread( h1
, buffer
, sizeof(buffer
) )) > 0)
1827 INT res
= _lwrite( h2
, p
, count
);
1828 if (res
<= 0) goto done
;
1841 /**************************************************************************
1842 * CopyFile32W (KERNEL32.37)
1844 BOOL WINAPI
CopyFileW( LPCWSTR source
, LPCWSTR dest
, BOOL fail_if_exists
)
1846 LPSTR sourceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, source
);
1847 LPSTR destA
= HEAP_strdupWtoA( GetProcessHeap(), 0, dest
);
1848 BOOL ret
= CopyFileA( sourceA
, destA
, fail_if_exists
);
1849 HeapFree( GetProcessHeap(), 0, sourceA
);
1850 HeapFree( GetProcessHeap(), 0, destA
);
1855 /**************************************************************************
1856 * CopyFileEx32A (KERNEL32.858)
1858 * This implementation ignores most of the extra parameters passed-in into
1859 * the "ex" version of the method and calls the CopyFile method.
1860 * It will have to be fixed eventually.
1862 BOOL WINAPI
CopyFileExA(LPCSTR sourceFilename
,
1863 LPCSTR destFilename
,
1864 LPPROGRESS_ROUTINE progressRoutine
,
1866 LPBOOL cancelFlagPointer
,
1869 BOOL failIfExists
= FALSE
;
1872 * Interpret the only flag that CopyFile can interpret.
1874 if ( (copyFlags
& COPY_FILE_FAIL_IF_EXISTS
) != 0)
1876 failIfExists
= TRUE
;
1879 return CopyFileA(sourceFilename
, destFilename
, failIfExists
);
1882 /**************************************************************************
1883 * CopyFileEx32W (KERNEL32.859)
1885 BOOL WINAPI
CopyFileExW(LPCWSTR sourceFilename
,
1886 LPCWSTR destFilename
,
1887 LPPROGRESS_ROUTINE progressRoutine
,
1889 LPBOOL cancelFlagPointer
,
1892 LPSTR sourceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, sourceFilename
);
1893 LPSTR destA
= HEAP_strdupWtoA( GetProcessHeap(), 0, destFilename
);
1895 BOOL ret
= CopyFileExA(sourceA
,
1902 HeapFree( GetProcessHeap(), 0, sourceA
);
1903 HeapFree( GetProcessHeap(), 0, destA
);
1909 /***********************************************************************
1910 * SetFileTime (KERNEL32.650)
1912 BOOL WINAPI
SetFileTime( HFILE hFile
,
1913 const FILETIME
*lpCreationTime
,
1914 const FILETIME
*lpLastAccessTime
,
1915 const FILETIME
*lpLastWriteTime
)
1917 struct set_file_time_request req
;
1920 if (lpLastAccessTime
)
1921 req
.access_time
= DOSFS_FileTimeToUnixTime(lpLastAccessTime
, NULL
);
1923 req
.access_time
= 0; /* FIXME */
1924 if (lpLastWriteTime
)
1925 req
.write_time
= DOSFS_FileTimeToUnixTime(lpLastWriteTime
, NULL
);
1927 req
.write_time
= 0; /* FIXME */
1929 CLIENT_SendRequest( REQ_SET_FILE_TIME
, -1, 1, &req
, sizeof(req
) );
1930 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1934 /**************************************************************************
1935 * LockFile (KERNEL32.511)
1937 BOOL WINAPI
LockFile( HFILE hFile
, DWORD dwFileOffsetLow
, DWORD dwFileOffsetHigh
,
1938 DWORD nNumberOfBytesToLockLow
, DWORD nNumberOfBytesToLockHigh
)
1940 struct lock_file_request req
;
1943 req
.offset_low
= dwFileOffsetLow
;
1944 req
.offset_high
= dwFileOffsetHigh
;
1945 req
.count_low
= nNumberOfBytesToLockLow
;
1946 req
.count_high
= nNumberOfBytesToLockHigh
;
1947 CLIENT_SendRequest( REQ_LOCK_FILE
, -1, 1, &req
, sizeof(req
) );
1948 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1951 /**************************************************************************
1952 * LockFileEx [KERNEL32.512]
1954 * Locks a byte range within an open file for shared or exclusive access.
1961 * Per Microsoft docs, the third parameter (reserved) must be set to 0.
1963 BOOL WINAPI
LockFileEx( HANDLE hFile
, DWORD flags
, DWORD reserved
,
1964 DWORD nNumberOfBytesToLockLow
, DWORD nNumberOfBytesToLockHigh
,
1965 LPOVERLAPPED pOverlapped
)
1967 FIXME(file
, "hFile=%d,flags=%ld,reserved=%ld,lowbytes=%ld,highbytes=%ld,overlapped=%p: stub.\n",
1968 hFile
, flags
, reserved
, nNumberOfBytesToLockLow
, nNumberOfBytesToLockHigh
,
1971 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1974 ERR(file
, "reserved == %ld: Supposed to be 0??\n", reserved
);
1975 SetLastError(ERROR_INVALID_PARAMETER
);
1982 /**************************************************************************
1983 * UnlockFile (KERNEL32.703)
1985 BOOL WINAPI
UnlockFile( HFILE hFile
, DWORD dwFileOffsetLow
, DWORD dwFileOffsetHigh
,
1986 DWORD nNumberOfBytesToUnlockLow
, DWORD nNumberOfBytesToUnlockHigh
)
1988 struct unlock_file_request req
;
1991 req
.offset_low
= dwFileOffsetLow
;
1992 req
.offset_high
= dwFileOffsetHigh
;
1993 req
.count_low
= nNumberOfBytesToUnlockLow
;
1994 req
.count_high
= nNumberOfBytesToUnlockHigh
;
1995 CLIENT_SendRequest( REQ_UNLOCK_FILE
, -1, 1, &req
, sizeof(req
) );
1996 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
2002 struct DOS_FILE_LOCK
{
2003 struct DOS_FILE_LOCK
* next
;
2007 FILE_OBJECT
* dos_file
;
2008 /* char * unix_name;*/
2011 typedef struct DOS_FILE_LOCK DOS_FILE_LOCK
;
2013 static DOS_FILE_LOCK
*locks
= NULL
;
2014 static void DOS_RemoveFileLocks(FILE_OBJECT
*file
);
2017 /* Locks need to be mirrored because unix file locking is based
2018 * on the pid. Inside of wine there can be multiple WINE processes
2019 * that share the same unix pid.
2020 * Read's and writes should check these locks also - not sure
2021 * how critical that is at this point (FIXME).
2024 static BOOL
DOS_AddLock(FILE_OBJECT
*file
, struct flock
*f
)
2026 DOS_FILE_LOCK
*curr
;
2029 processId
= GetCurrentProcessId();
2031 /* check if lock overlaps a current lock for the same file */
2033 for (curr
= locks
; curr
; curr
= curr
->next
) {
2034 if (strcmp(curr
->unix_name
, file
->unix_name
) == 0) {
2035 if ((f
->l_start
== curr
->base
) && (f
->l_len
== curr
->len
))
2036 return TRUE
;/* region is identic */
2037 if ((f
->l_start
< (curr
->base
+ curr
->len
)) &&
2038 ((f
->l_start
+ f
->l_len
) > curr
->base
)) {
2039 /* region overlaps */
2046 curr
= HeapAlloc( SystemHeap
, 0, sizeof(DOS_FILE_LOCK
) );
2047 curr
->processId
= GetCurrentProcessId();
2048 curr
->base
= f
->l_start
;
2049 curr
->len
= f
->l_len
;
2050 /* curr->unix_name = HEAP_strdupA( SystemHeap, 0, file->unix_name);*/
2052 curr
->dos_file
= file
;
2057 static void DOS_RemoveFileLocks(FILE_OBJECT
*file
)
2060 DOS_FILE_LOCK
**curr
;
2063 processId
= GetCurrentProcessId();
2066 if ((*curr
)->dos_file
== file
) {
2068 *curr
= (*curr
)->next
;
2069 /* HeapFree( SystemHeap, 0, rem->unix_name );*/
2070 HeapFree( SystemHeap
, 0, rem
);
2073 curr
= &(*curr
)->next
;
2077 static BOOL
DOS_RemoveLock(FILE_OBJECT
*file
, struct flock
*f
)
2080 DOS_FILE_LOCK
**curr
;
2083 processId
= GetCurrentProcessId();
2084 for (curr
= &locks
; *curr
; curr
= &(*curr
)->next
) {
2085 if ((*curr
)->processId
== processId
&&
2086 (*curr
)->dos_file
== file
&&
2087 (*curr
)->base
== f
->l_start
&&
2088 (*curr
)->len
== f
->l_len
) {
2089 /* this is the same lock */
2091 *curr
= (*curr
)->next
;
2092 /* HeapFree( SystemHeap, 0, rem->unix_name );*/
2093 HeapFree( SystemHeap
, 0, rem
);
2097 /* no matching lock found */
2102 /**************************************************************************
2103 * LockFile (KERNEL32.511)
2105 BOOL WINAPI
LockFile(
2106 HFILE hFile
,DWORD dwFileOffsetLow
,DWORD dwFileOffsetHigh
,
2107 DWORD nNumberOfBytesToLockLow
,DWORD nNumberOfBytesToLockHigh
)
2112 TRACE(file
, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
2113 hFile
, dwFileOffsetLow
, dwFileOffsetHigh
,
2114 nNumberOfBytesToLockLow
, nNumberOfBytesToLockHigh
);
2116 if (dwFileOffsetHigh
|| nNumberOfBytesToLockHigh
) {
2117 FIXME(file
, "Unimplemented bytes > 32bits\n");
2121 f
.l_start
= dwFileOffsetLow
;
2122 f
.l_len
= nNumberOfBytesToLockLow
;
2123 f
.l_whence
= SEEK_SET
;
2127 if (!(file
= FILE_GetFile(hFile
,0,NULL
))) return FALSE
;
2129 /* shadow locks internally */
2130 if (!DOS_AddLock(file
, &f
)) {
2131 SetLastError( ERROR_LOCK_VIOLATION
);
2135 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
2136 #ifdef USE_UNIX_LOCKS
2137 if (fcntl(file
->unix_handle
, F_SETLK
, &f
) == -1) {
2138 if (errno
== EACCES
|| errno
== EAGAIN
) {
2139 SetLastError( ERROR_LOCK_VIOLATION
);
2144 /* remove our internal copy of the lock */
2145 DOS_RemoveLock(file
, &f
);
2153 /**************************************************************************
2154 * UnlockFile (KERNEL32.703)
2156 BOOL WINAPI
UnlockFile(
2157 HFILE hFile
,DWORD dwFileOffsetLow
,DWORD dwFileOffsetHigh
,
2158 DWORD nNumberOfBytesToUnlockLow
,DWORD nNumberOfBytesToUnlockHigh
)
2163 TRACE(file
, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
2164 hFile
, dwFileOffsetLow
, dwFileOffsetHigh
,
2165 nNumberOfBytesToUnlockLow
, nNumberOfBytesToUnlockHigh
);
2167 if (dwFileOffsetHigh
|| nNumberOfBytesToUnlockHigh
) {
2168 WARN(file
, "Unimplemented bytes > 32bits\n");
2172 f
.l_start
= dwFileOffsetLow
;
2173 f
.l_len
= nNumberOfBytesToUnlockLow
;
2174 f
.l_whence
= SEEK_SET
;
2178 if (!(file
= FILE_GetFile(hFile
,0,NULL
))) return FALSE
;
2180 DOS_RemoveLock(file
, &f
); /* ok if fails - may be another wine */
2182 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
2183 #ifdef USE_UNIX_LOCKS
2184 if (fcntl(file
->unix_handle
, F_SETLK
, &f
) == -1) {
2193 /**************************************************************************
2194 * GetFileAttributesEx32A [KERNEL32.874]
2196 BOOL WINAPI
GetFileAttributesExA(
2197 LPCSTR lpFileName
, GET_FILEEX_INFO_LEVELS fInfoLevelId
,
2198 LPVOID lpFileInformation
)
2200 DOS_FULL_NAME full_name
;
2201 BY_HANDLE_FILE_INFORMATION info
;
2203 if (lpFileName
== NULL
) return FALSE
;
2204 if (lpFileInformation
== NULL
) return FALSE
;
2206 if (fInfoLevelId
== GetFileExInfoStandard
) {
2207 LPWIN32_FILE_ATTRIBUTE_DATA lpFad
=
2208 (LPWIN32_FILE_ATTRIBUTE_DATA
) lpFileInformation
;
2209 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
)) return FALSE
;
2210 if (!FILE_Stat( full_name
.long_name
, &info
)) return FALSE
;
2212 lpFad
->dwFileAttributes
= info
.dwFileAttributes
;
2213 lpFad
->ftCreationTime
= info
.ftCreationTime
;
2214 lpFad
->ftLastAccessTime
= info
.ftLastAccessTime
;
2215 lpFad
->ftLastWriteTime
= info
.ftLastWriteTime
;
2216 lpFad
->nFileSizeHigh
= info
.nFileSizeHigh
;
2217 lpFad
->nFileSizeLow
= info
.nFileSizeLow
;
2220 FIXME (file
, "invalid info level %d!\n", fInfoLevelId
);
2228 /**************************************************************************
2229 * GetFileAttributesEx32W [KERNEL32.875]
2231 BOOL WINAPI
GetFileAttributesExW(
2232 LPCWSTR lpFileName
, GET_FILEEX_INFO_LEVELS fInfoLevelId
,
2233 LPVOID lpFileInformation
)
2235 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
2237 GetFileAttributesExA( nameA
, fInfoLevelId
, lpFileInformation
);
2238 HeapFree( GetProcessHeap(), 0, nameA
);