2 * DOS file system functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
10 #include <sys/types.h>
14 #ifdef HAVE_SYS_ERRNO_H
15 #include <sys/errno.h>
21 #include <sys/ioctl.h>
29 #include "wine/unicode.h"
30 #include "wine/winbase16.h"
37 #include "wine/server.h"
39 #include "debugtools.h"
41 DEFAULT_DEBUG_CHANNEL(dosfs
);
42 DECLARE_DEBUG_CHANNEL(file
);
44 /* Define the VFAT ioctl to get both short and long file names */
45 /* FIXME: is it possible to get this to work on other systems? */
47 /* We want the real kernel dirent structure, not the libc one */
52 unsigned short d_reclen
;
56 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, KERNEL_DIRENT [2] )
59 #undef VFAT_IOCTL_READDIR_BOTH /* just in case... */
62 /* Chars we don't want to see in DOS file names */
63 #define INVALID_DOS_CHARS "*?<>|\"+=,;[] \345"
65 static const DOS_DEVICE DOSFS_Devices
[] =
66 /* name, device flags (see Int 21/AX=0x4400) */
80 { "SCSIMGR$", 0xc0c0 },
84 #define GET_DRIVE(path) \
85 (((path)[1] == ':') ? FILE_toupper((path)[0]) - 'A' : DOSFS_CurDrive)
87 /* Directory info for DOSFS_ReadDir */
91 #ifdef VFAT_IOCTL_READDIR_BOTH
94 KERNEL_DIRENT dirent
[2];
98 /* Info structure for FindFirstFile handle */
111 static WINE_EXCEPTION_FILTER(page_fault
)
113 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
114 return EXCEPTION_EXECUTE_HANDLER
;
115 return EXCEPTION_CONTINUE_SEARCH
;
119 /***********************************************************************
122 * Return 1 if Unix file 'name' is also a valid MS-DOS name
123 * (i.e. contains only valid DOS chars, lower-case only, fits in 8.3 format).
124 * File name can be terminated by '\0', '\\' or '/'.
126 static int DOSFS_ValidDOSName( const char *name
, int ignore_case
)
128 static const char invalid_chars
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" INVALID_DOS_CHARS
;
129 const char *p
= name
;
130 const char *invalid
= ignore_case
? (invalid_chars
+ 26) : invalid_chars
;
135 /* Check for "." and ".." */
138 /* All other names beginning with '.' are invalid */
139 return (IS_END_OF_NAME(*p
));
141 while (!IS_END_OF_NAME(*p
))
143 if (strchr( invalid
, *p
)) return 0; /* Invalid char */
144 if (*p
== '.') break; /* Start of the extension */
145 if (++len
> 8) return 0; /* Name too long */
148 if (*p
!= '.') return 1; /* End of name */
150 if (IS_END_OF_NAME(*p
)) return 0; /* Empty extension not allowed */
152 while (!IS_END_OF_NAME(*p
))
154 if (strchr( invalid
, *p
)) return 0; /* Invalid char */
155 if (*p
== '.') return 0; /* Second extension not allowed */
156 if (++len
> 3) return 0; /* Extension too long */
163 /***********************************************************************
164 * DOSFS_ToDosFCBFormat
166 * Convert a file name to DOS FCB format (8+3 chars, padded with blanks),
167 * expanding wild cards and converting to upper-case in the process.
168 * File name can be terminated by '\0', '\\' or '/'.
169 * Return FALSE if the name is not a valid DOS name.
170 * 'buffer' must be at least 12 characters long.
172 BOOL
DOSFS_ToDosFCBFormat( LPCSTR name
, LPSTR buffer
)
174 static const char invalid_chars
[] = INVALID_DOS_CHARS
;
175 const char *p
= name
;
178 /* Check for "." and ".." */
182 strcpy( buffer
, ". " );
188 return (!*p
|| (*p
== '/') || (*p
== '\\'));
191 for (i
= 0; i
< 8; i
++)
208 if (strchr( invalid_chars
, *p
)) return FALSE
;
209 buffer
[i
] = FILE_toupper(*p
);
217 /* Skip all chars after wildcard up to first dot */
218 while (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) p
++;
222 /* Check if name too long */
223 if (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) return FALSE
;
225 if (*p
== '.') p
++; /* Skip dot */
227 for (i
= 8; i
< 11; i
++)
237 return FALSE
; /* Second extension not allowed */
245 if (strchr( invalid_chars
, *p
)) return FALSE
;
246 buffer
[i
] = FILE_toupper(*p
);
253 /* at most 3 character of the extension are processed
254 * is something behind this ?
256 while (*p
== '*' || *p
== ' ') p
++; /* skip wildcards and spaces */
257 return IS_END_OF_NAME(*p
);
261 /***********************************************************************
262 * DOSFS_ToDosDTAFormat
264 * Convert a file name from FCB to DTA format (name.ext, null-terminated)
265 * converting to upper-case in the process.
266 * File name can be terminated by '\0', '\\' or '/'.
267 * 'buffer' must be at least 13 characters long.
269 static void DOSFS_ToDosDTAFormat( LPCSTR name
, LPSTR buffer
)
273 memcpy( buffer
, name
, 8 );
275 while ((p
> buffer
) && (p
[-1] == ' ')) p
--;
277 memcpy( p
, name
+ 8, 3 );
279 while (p
[-1] == ' ') p
--;
280 if (p
[-1] == '.') p
--;
285 /***********************************************************************
288 * Check a DOS file name against a mask (both in FCB format).
290 static int DOSFS_MatchShort( const char *mask
, const char *name
)
293 for (i
= 11; i
> 0; i
--, mask
++, name
++)
294 if ((*mask
!= '?') && (*mask
!= *name
)) return 0;
299 /***********************************************************************
302 * Check a long file name against a mask.
304 * Tests (done in W95 DOS shell - case insensitive):
305 * *.txt test1.test.txt *
307 * *.t??????.t* test1.ta.tornado.txt *
308 * *tornado* test1.ta.tornado.txt *
309 * t*t test1.ta.tornado.txt *
311 * ?est??? test1.txt -
312 * *test1.txt* test1.txt *
313 * h?l?o*t.dat hellothisisatest.dat *
315 static int DOSFS_MatchLong( const char *mask
, const char *name
,
318 const char *lastjoker
= NULL
;
319 const char *next_to_retry
= NULL
;
321 if (!strcmp( mask
, "*.*" )) return 1;
322 while (*name
&& *mask
)
327 while (*mask
== '*') mask
++; /* Skip consecutive '*' */
329 if (!*mask
) return 1; /* end of mask is all '*', so match */
331 /* skip to the next match after the joker(s) */
332 if (case_sensitive
) while (*name
&& (*name
!= *mask
)) name
++;
333 else while (*name
&& (FILE_toupper(*name
) != FILE_toupper(*mask
))) name
++;
336 next_to_retry
= name
;
338 else if (*mask
!= '?')
343 if (*mask
!= *name
) mismatch
= 1;
347 if (FILE_toupper(*mask
) != FILE_toupper(*name
)) mismatch
= 1;
361 else /* mismatch ! */
363 if (lastjoker
) /* we had an '*', so we can try unlimitedly */
367 /* this scan sequence was a mismatch, so restart
368 * 1 char after the first char we checked last time */
370 name
= next_to_retry
;
373 return 0; /* bad luck */
382 while ((*mask
== '.') || (*mask
== '*'))
383 mask
++; /* Ignore trailing '.' or '*' in mask */
384 return (!*name
&& !*mask
);
388 /***********************************************************************
391 static DOS_DIR
*DOSFS_OpenDir( LPCSTR path
)
393 DOS_DIR
*dir
= HeapAlloc( GetProcessHeap(), 0, sizeof(*dir
) );
396 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
400 /* Treat empty path as root directory. This simplifies path split into
401 directory and mask in several other places */
402 if (!*path
) path
= "/";
404 #ifdef VFAT_IOCTL_READDIR_BOTH
406 /* Check if the VFAT ioctl is supported on this directory */
408 if ((dir
->fd
= open( path
, O_RDONLY
)) != -1)
410 if (ioctl( dir
->fd
, VFAT_IOCTL_READDIR_BOTH
, (long)dir
->dirent
) == -1)
417 /* Set the file pointer back at the start of the directory */
418 lseek( dir
->fd
, 0, SEEK_SET
);
423 #endif /* VFAT_IOCTL_READDIR_BOTH */
425 /* Now use the standard opendir/readdir interface */
427 if (!(dir
->dir
= opendir( path
)))
429 HeapFree( GetProcessHeap(), 0, dir
);
436 /***********************************************************************
439 static void DOSFS_CloseDir( DOS_DIR
*dir
)
441 #ifdef VFAT_IOCTL_READDIR_BOTH
442 if (dir
->fd
!= -1) close( dir
->fd
);
443 #endif /* VFAT_IOCTL_READDIR_BOTH */
444 if (dir
->dir
) closedir( dir
->dir
);
445 HeapFree( GetProcessHeap(), 0, dir
);
449 /***********************************************************************
452 static BOOL
DOSFS_ReadDir( DOS_DIR
*dir
, LPCSTR
*long_name
,
455 struct dirent
*dirent
;
457 #ifdef VFAT_IOCTL_READDIR_BOTH
460 if (ioctl( dir
->fd
, VFAT_IOCTL_READDIR_BOTH
, (long)dir
->dirent
) != -1) {
461 if (!dir
->dirent
[0].d_reclen
) return FALSE
;
462 if (!DOSFS_ToDosFCBFormat( dir
->dirent
[0].d_name
, dir
->short_name
))
463 dir
->short_name
[0] = '\0';
464 *short_name
= dir
->short_name
;
465 if (dir
->dirent
[1].d_name
[0]) *long_name
= dir
->dirent
[1].d_name
;
466 else *long_name
= dir
->dirent
[0].d_name
;
470 #endif /* VFAT_IOCTL_READDIR_BOTH */
472 if (!(dirent
= readdir( dir
->dir
))) return FALSE
;
473 *long_name
= dirent
->d_name
;
479 /***********************************************************************
482 * Transform a Unix file name into a hashed DOS name. If the name is a valid
483 * DOS name, it is converted to upper-case; otherwise it is replaced by a
484 * hashed version that fits in 8.3 format.
485 * File name can be terminated by '\0', '\\' or '/'.
486 * 'buffer' must be at least 13 characters long.
488 static void DOSFS_Hash( LPCSTR name
, LPSTR buffer
, BOOL dir_format
,
491 static const char invalid_chars
[] = INVALID_DOS_CHARS
"~.";
492 static const char hash_chars
[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
499 if (dir_format
) strcpy( buffer
, " " );
501 if (DOSFS_ValidDOSName( name
, ignore_case
))
503 /* Check for '.' and '..' */
507 if (!dir_format
) buffer
[1] = buffer
[2] = '\0';
508 if (name
[1] == '.') buffer
[1] = '.';
512 /* Simply copy the name, converting to uppercase */
514 for (dst
= buffer
; !IS_END_OF_NAME(*name
) && (*name
!= '.'); name
++)
515 *dst
++ = FILE_toupper(*name
);
518 if (dir_format
) dst
= buffer
+ 8;
520 for (name
++; !IS_END_OF_NAME(*name
); name
++)
521 *dst
++ = FILE_toupper(*name
);
523 if (!dir_format
) *dst
= '\0';
527 /* Compute the hash code of the file name */
528 /* If you know something about hash functions, feel free to */
529 /* insert a better algorithm here... */
532 for (p
= name
, hash
= 0xbeef; !IS_END_OF_NAME(p
[1]); p
++)
533 hash
= (hash
<<3) ^ (hash
>>5) ^ FILE_tolower(*p
) ^ (FILE_tolower(p
[1]) << 8);
534 hash
= (hash
<<3) ^ (hash
>>5) ^ FILE_tolower(*p
); /* Last character*/
538 for (p
= name
, hash
= 0xbeef; !IS_END_OF_NAME(p
[1]); p
++)
539 hash
= (hash
<< 3) ^ (hash
>> 5) ^ *p
^ (p
[1] << 8);
540 hash
= (hash
<< 3) ^ (hash
>> 5) ^ *p
; /* Last character */
543 /* Find last dot for start of the extension */
544 for (p
= name
+1, ext
= NULL
; !IS_END_OF_NAME(*p
); p
++)
545 if (*p
== '.') ext
= p
;
546 if (ext
&& IS_END_OF_NAME(ext
[1]))
547 ext
= NULL
; /* Empty extension ignored */
549 /* Copy first 4 chars, replacing invalid chars with '_' */
550 for (i
= 4, p
= name
, dst
= buffer
; i
> 0; i
--, p
++)
552 if (IS_END_OF_NAME(*p
) || (p
== ext
)) break;
553 *dst
++ = strchr( invalid_chars
, *p
) ? '_' : FILE_toupper(*p
);
555 /* Pad to 5 chars with '~' */
556 while (i
-- >= 0) *dst
++ = '~';
558 /* Insert hash code converted to 3 ASCII chars */
559 *dst
++ = hash_chars
[(hash
>> 10) & 0x1f];
560 *dst
++ = hash_chars
[(hash
>> 5) & 0x1f];
561 *dst
++ = hash_chars
[hash
& 0x1f];
563 /* Copy the first 3 chars of the extension (if any) */
566 if (!dir_format
) *dst
++ = '.';
567 for (i
= 3, ext
++; (i
> 0) && !IS_END_OF_NAME(*ext
); i
--, ext
++)
568 *dst
++ = strchr( invalid_chars
, *ext
) ? '_' : FILE_toupper(*ext
);
570 if (!dir_format
) *dst
= '\0';
574 /***********************************************************************
577 * Find the Unix file name in a given directory that corresponds to
578 * a file name (either in Unix or DOS format).
579 * File name can be terminated by '\0', '\\' or '/'.
580 * Return TRUE if OK, FALSE if no file name matches.
582 * 'long_buf' must be at least 'long_len' characters long. If the long name
583 * turns out to be larger than that, the function returns FALSE.
584 * 'short_buf' must be at least 13 characters long.
586 BOOL
DOSFS_FindUnixName( LPCSTR path
, LPCSTR name
, LPSTR long_buf
,
587 INT long_len
, LPSTR short_buf
, BOOL ignore_case
)
590 LPCSTR long_name
, short_name
;
591 char dos_name
[12], tmp_buf
[13];
594 const char *p
= strchr( name
, '/' );
595 int len
= p
? (int)(p
- name
) : strlen(name
);
596 if ((p
= strchr( name
, '\\' ))) len
= min( (int)(p
- name
), len
);
597 /* Ignore trailing dots and spaces */
598 while (len
> 1 && (name
[len
-1] == '.' || name
[len
-1] == ' ')) len
--;
599 if (long_len
< len
+ 1) return FALSE
;
601 TRACE("%s,%s\n", path
, name
);
603 if (!DOSFS_ToDosFCBFormat( name
, dos_name
)) dos_name
[0] = '\0';
605 if (!(dir
= DOSFS_OpenDir( path
)))
607 WARN("(%s,%s): can't open dir: %s\n",
608 path
, name
, strerror(errno
) );
612 while ((ret
= DOSFS_ReadDir( dir
, &long_name
, &short_name
)))
614 /* Check against Unix name */
615 if (len
== strlen(long_name
))
619 if (!strncmp( long_name
, name
, len
)) break;
623 if (!FILE_strncasecmp( long_name
, name
, len
)) break;
628 /* Check against hashed DOS name */
631 DOSFS_Hash( long_name
, tmp_buf
, TRUE
, ignore_case
);
632 short_name
= tmp_buf
;
634 if (!strcmp( dos_name
, short_name
)) break;
639 if (long_buf
) strcpy( long_buf
, long_name
);
643 DOSFS_ToDosDTAFormat( short_name
, short_buf
);
645 DOSFS_Hash( long_name
, short_buf
, FALSE
, ignore_case
);
647 TRACE("(%s,%s) -> %s (%s)\n",
648 path
, name
, long_name
, short_buf
? short_buf
: "***");
651 WARN("'%s' not found in '%s'\n", name
, path
);
652 DOSFS_CloseDir( dir
);
657 /***********************************************************************
660 * Check if a DOS file name represents a DOS device and return the device.
662 const DOS_DEVICE
*DOSFS_GetDevice( const char *name
)
667 if (!name
) return NULL
; /* if FILE_DupUnixHandle was used */
668 if (name
[0] && (name
[1] == ':')) name
+= 2;
669 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
670 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
671 for (i
= 0; i
< sizeof(DOSFS_Devices
)/sizeof(DOSFS_Devices
[0]); i
++)
673 const char *dev
= DOSFS_Devices
[i
].name
;
674 if (!FILE_strncasecmp( dev
, name
, strlen(dev
) ))
676 p
= name
+ strlen( dev
);
677 if (!*p
|| (*p
== '.') || (*p
== ':')) return &DOSFS_Devices
[i
];
684 /***********************************************************************
685 * DOSFS_GetDeviceByHandle
687 const DOS_DEVICE
*DOSFS_GetDeviceByHandle( HFILE hFile
)
689 const DOS_DEVICE
*ret
= NULL
;
690 SERVER_START_REQ( get_file_info
)
693 if (!SERVER_CALL() && (req
->type
== FILE_TYPE_UNKNOWN
))
695 if ((req
->attr
>= 0) &&
696 (req
->attr
< sizeof(DOSFS_Devices
)/sizeof(DOSFS_Devices
[0])))
697 ret
= &DOSFS_Devices
[req
->attr
];
705 /**************************************************************************
706 * DOSFS_CreateCommPort
708 static HANDLE
DOSFS_CreateCommPort(LPCSTR name
, DWORD access
)
714 TRACE("%s %lx\n", name
, access
);
716 PROFILE_GetWineIniString("serialports",name
,"",devname
,sizeof devname
);
720 TRACE("opening %s as %s\n", devname
, name
);
722 len
= strlen(devname
);
723 SERVER_START_VAR_REQ( create_serial
, len
)
725 req
->access
= access
;
726 req
->inherit
= 0; /*FIXME*/
727 req
->sharing
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
728 memcpy( server_data_ptr(req
), devname
, len
);
736 ERR("Couldn't open %s ! (check permissions)\n",devname
);
738 TRACE("return %08X\n", ret
);
742 /***********************************************************************
745 * Open a DOS device. This might not map 1:1 into the UNIX device concept.
746 * Returns 0 on failure.
748 HANDLE
DOSFS_OpenDevice( const char *name
, DWORD access
)
754 if (name
[0] && (name
[1] == ':')) name
+= 2;
755 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
756 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
757 for (i
= 0; i
< sizeof(DOSFS_Devices
)/sizeof(DOSFS_Devices
[0]); i
++)
759 const char *dev
= DOSFS_Devices
[i
].name
;
760 if (!FILE_strncasecmp( dev
, name
, strlen(dev
) ))
762 p
= name
+ strlen( dev
);
763 if (!*p
|| (*p
== '.') || (*p
== ':')) {
765 if (!strcmp(DOSFS_Devices
[i
].name
,"NUL"))
766 return FILE_CreateFile( "/dev/null", access
,
767 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
768 OPEN_EXISTING
, 0, 0, TRUE
);
769 if (!strcmp(DOSFS_Devices
[i
].name
,"CON")) {
771 switch (access
& (GENERIC_READ
|GENERIC_WRITE
)) {
773 to_dup
= GetStdHandle( STD_INPUT_HANDLE
);
776 to_dup
= GetStdHandle( STD_OUTPUT_HANDLE
);
779 FIXME("can't open CON read/write\n");
782 if (!DuplicateHandle( GetCurrentProcess(), to_dup
, GetCurrentProcess(),
783 &handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
787 if (!strcmp(DOSFS_Devices
[i
].name
,"SCSIMGR$") ||
788 !strcmp(DOSFS_Devices
[i
].name
,"HPSCAN"))
790 return FILE_CreateDevice( i
, access
, NULL
);
793 if( (handle
=DOSFS_CreateCommPort(DOSFS_Devices
[i
].name
,access
)) )
795 FIXME("device open %s not supported (yet)\n",DOSFS_Devices
[i
].name
);
804 /***********************************************************************
807 * Get the drive specified by a given path name (DOS or Unix format).
809 static int DOSFS_GetPathDrive( const char **name
)
812 const char *p
= *name
;
814 if (*p
&& (p
[1] == ':'))
816 drive
= FILE_toupper(*p
) - 'A';
819 else if (*p
== '/') /* Absolute Unix path? */
821 if ((drive
= DRIVE_FindDriveRoot( name
)) == -1)
823 MESSAGE("Warning: %s not accessible from a DOS drive\n", *name
);
824 /* Assume it really was a DOS name */
825 drive
= DRIVE_GetCurrentDrive();
828 else drive
= DRIVE_GetCurrentDrive();
830 if (!DRIVE_IsValid(drive
))
832 SetLastError( ERROR_INVALID_DRIVE
);
839 /***********************************************************************
842 * Convert a file name (DOS or mixed DOS/Unix format) to a valid
843 * Unix name / short DOS name pair.
844 * Return FALSE if one of the path components does not exist. The last path
845 * component is only checked if 'check_last' is non-zero.
846 * The buffers pointed to by 'long_buf' and 'short_buf' must be
847 * at least MAX_PATHNAME_LEN long.
849 BOOL
DOSFS_GetFullName( LPCSTR name
, BOOL check_last
, DOS_FULL_NAME
*full
)
853 char *p_l
, *p_s
, *root
;
855 TRACE("%s (last=%d)\n", name
, check_last
);
857 if ((!*name
) || (*name
=='\n'))
858 { /* error code for Win98 */
859 SetLastError(ERROR_BAD_PATHNAME
);
863 if ((full
->drive
= DOSFS_GetPathDrive( &name
)) == -1) return FALSE
;
864 flags
= DRIVE_GetFlags( full
->drive
);
866 lstrcpynA( full
->long_name
, DRIVE_GetRoot( full
->drive
),
867 sizeof(full
->long_name
) );
868 if (full
->long_name
[1]) root
= full
->long_name
+ strlen(full
->long_name
);
869 else root
= full
->long_name
; /* root directory */
871 strcpy( full
->short_name
, "A:\\" );
872 full
->short_name
[0] += full
->drive
;
874 if ((*name
== '\\') || (*name
== '/')) /* Absolute path */
876 while ((*name
== '\\') || (*name
== '/')) name
++;
878 else /* Relative path */
880 lstrcpynA( root
+ 1, DRIVE_GetUnixCwd( full
->drive
),
881 sizeof(full
->long_name
) - (root
- full
->long_name
) - 1 );
882 if (root
[1]) *root
= '/';
883 lstrcpynA( full
->short_name
+ 3, DRIVE_GetDosCwd( full
->drive
),
884 sizeof(full
->short_name
) - 3 );
887 p_l
= full
->long_name
[1] ? full
->long_name
+ strlen(full
->long_name
)
889 p_s
= full
->short_name
[3] ? full
->short_name
+ strlen(full
->short_name
)
890 : full
->short_name
+ 2;
893 while (*name
&& found
)
895 /* Check for '.' and '..' */
899 if (IS_END_OF_NAME(name
[1]))
902 while ((*name
== '\\') || (*name
== '/')) name
++;
905 else if ((name
[1] == '.') && IS_END_OF_NAME(name
[2]))
908 while ((*name
== '\\') || (*name
== '/')) name
++;
909 while ((p_l
> root
) && (*p_l
!= '/')) p_l
--;
910 while ((p_s
> full
->short_name
+ 2) && (*p_s
!= '\\')) p_s
--;
911 *p_l
= *p_s
= '\0'; /* Remove trailing separator */
916 /* Make sure buffers are large enough */
918 if ((p_s
>= full
->short_name
+ sizeof(full
->short_name
) - 14) ||
919 (p_l
>= full
->long_name
+ sizeof(full
->long_name
) - 1))
921 SetLastError( ERROR_PATH_NOT_FOUND
);
925 /* Get the long and short name matching the file name */
927 if ((found
= DOSFS_FindUnixName( full
->long_name
, name
, p_l
+ 1,
928 sizeof(full
->long_name
) - (p_l
- full
->long_name
) - 1,
929 p_s
+ 1, !(flags
& DRIVE_CASE_SENSITIVE
) )))
935 while (!IS_END_OF_NAME(*name
)) name
++;
937 else if (!check_last
)
941 while (!IS_END_OF_NAME(*name
) &&
942 (p_s
< full
->short_name
+ sizeof(full
->short_name
) - 1) &&
943 (p_l
< full
->long_name
+ sizeof(full
->long_name
) - 1))
945 *p_s
++ = FILE_tolower(*name
);
946 /* If the drive is case-sensitive we want to create new */
947 /* files in lower-case otherwise we can't reopen them */
948 /* under the same short name. */
949 if (flags
& DRIVE_CASE_SENSITIVE
) *p_l
++ = FILE_tolower(*name
);
953 /* Ignore trailing dots and spaces */
954 while(p_l
[-1] == '.' || p_l
[-1] == ' ') {
960 while ((*name
== '\\') || (*name
== '/')) name
++;
967 SetLastError( ERROR_FILE_NOT_FOUND
);
970 if (*name
) /* Not last */
972 SetLastError( ERROR_PATH_NOT_FOUND
);
976 if (!full
->long_name
[0]) strcpy( full
->long_name
, "/" );
977 if (!full
->short_name
[2]) strcpy( full
->short_name
+ 2, "\\" );
978 TRACE("returning %s = %s\n", full
->long_name
, full
->short_name
);
983 /***********************************************************************
984 * GetShortPathNameA (KERNEL32.@)
988 * longpath=NULL: LastError=ERROR_INVALID_PARAMETER, ret=0
989 * *longpath="" or invalid: LastError=ERROR_BAD_PATHNAME, ret=0
991 * more observations ( with NT 3.51 (WinDD) ):
992 * longpath <= 8.3 -> just copy longpath to shortpath
994 * a) file does not exist -> return 0, LastError = ERROR_FILE_NOT_FOUND
995 * b) file does exist -> set the short filename.
996 * - trailing slashes are reproduced in the short name, even if the
997 * file is not a directory
998 * - the absolute/relative path of the short name is reproduced like found
1000 * - longpath and shortpath may have the same adress
1001 * Peter Ganten, 1999
1003 DWORD WINAPI
GetShortPathNameA( LPCSTR longpath
, LPSTR shortpath
,
1006 DOS_FULL_NAME full_name
;
1008 DWORD sp
= 0, lp
= 0;
1012 TRACE("%s\n", debugstr_a(longpath
));
1015 SetLastError(ERROR_INVALID_PARAMETER
);
1019 SetLastError(ERROR_BAD_PATHNAME
);
1023 if ( ( tmpshortpath
= HeapAlloc ( GetProcessHeap(), 0, MAX_PATHNAME_LEN
) ) == NULL
) {
1024 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
1028 /* check for drive letter */
1029 if ( longpath
[1] == ':' ) {
1030 tmpshortpath
[0] = longpath
[0];
1031 tmpshortpath
[1] = ':';
1035 if ( ( drive
= DOSFS_GetPathDrive ( &longpath
)) == -1 ) return 0;
1036 flags
= DRIVE_GetFlags ( drive
);
1038 while ( longpath
[lp
] ) {
1040 /* check for path delimiters and reproduce them */
1041 if ( longpath
[lp
] == '\\' || longpath
[lp
] == '/' ) {
1042 if (!sp
|| tmpshortpath
[sp
-1]!= '\\')
1044 /* strip double "\\" */
1045 tmpshortpath
[sp
] = '\\';
1048 tmpshortpath
[sp
]=0;/*terminate string*/
1053 tmplen
= strcspn ( longpath
+ lp
, "\\/" );
1054 lstrcpynA ( tmpshortpath
+sp
, longpath
+ lp
, tmplen
+1 );
1056 /* Check, if the current element is a valid dos name */
1057 if ( DOSFS_ValidDOSName ( longpath
+ lp
, !(flags
& DRIVE_CASE_SENSITIVE
) ) ) {
1063 /* Check if the file exists and use the existing file name */
1064 if ( DOSFS_GetFullName ( tmpshortpath
, TRUE
, &full_name
) ) {
1065 strcpy( tmpshortpath
+sp
, strrchr ( full_name
.short_name
, '\\' ) + 1 );
1066 sp
+= strlen ( tmpshortpath
+sp
);
1071 TRACE("not found!\n" );
1072 SetLastError ( ERROR_FILE_NOT_FOUND
);
1075 tmpshortpath
[sp
] = 0;
1077 lstrcpynA ( shortpath
, tmpshortpath
, shortlen
);
1078 TRACE("returning %s\n", debugstr_a(shortpath
) );
1079 tmplen
= strlen ( tmpshortpath
);
1080 HeapFree ( GetProcessHeap(), 0, tmpshortpath
);
1086 /***********************************************************************
1087 * GetShortPathNameW (KERNEL32.@)
1089 DWORD WINAPI
GetShortPathNameW( LPCWSTR longpath
, LPWSTR shortpath
,
1092 LPSTR longpathA
, shortpathA
;
1095 longpathA
= HEAP_strdupWtoA( GetProcessHeap(), 0, longpath
);
1096 shortpathA
= HeapAlloc ( GetProcessHeap(), 0, shortlen
);
1098 ret
= GetShortPathNameA ( longpathA
, shortpathA
, shortlen
);
1099 if (shortlen
> 0 && !MultiByteToWideChar( CP_ACP
, 0, shortpathA
, -1, shortpath
, shortlen
))
1100 shortpath
[shortlen
-1] = 0;
1101 HeapFree( GetProcessHeap(), 0, longpathA
);
1102 HeapFree( GetProcessHeap(), 0, shortpathA
);
1108 /***********************************************************************
1109 * GetLongPathNameA (KERNEL32.@)
1111 DWORD WINAPI
GetLongPathNameA( LPCSTR shortpath
, LPSTR longpath
,
1114 DOS_FULL_NAME full_name
;
1115 char *p
, *r
, *ll
, *ss
;
1117 if (!DOSFS_GetFullName( shortpath
, TRUE
, &full_name
)) return 0;
1118 lstrcpynA( longpath
, full_name
.short_name
, longlen
);
1120 /* Do some hackery to get the long filename. */
1123 ss
=longpath
+strlen(longpath
);
1124 ll
=full_name
.long_name
+strlen(full_name
.long_name
);
1126 while (ss
>=longpath
)
1128 /* FIXME: aren't we more paranoid, than needed? */
1129 while ((ss
[0]=='\\') && (ss
>=longpath
)) ss
--;
1131 while ((ss
[0]!='\\') && (ss
>=longpath
)) ss
--;
1134 /* FIXME: aren't we more paranoid, than needed? */
1135 while ((ll
[0]=='/') && (ll
>=full_name
.long_name
)) ll
--;
1136 while ((ll
[0]!='/') && (ll
>=full_name
.long_name
)) ll
--;
1137 if (ll
<full_name
.long_name
)
1139 ERR("Bad longname! (ss=%s ll=%s)\n This should never happen !\n"
1146 /* FIXME: fix for names like "C:\\" (ie. with more '\'s) */
1150 if ((p
-longpath
)>0) longlen
-= (p
-longpath
);
1151 lstrcpynA( p
, ll
, longlen
);
1153 /* Now, change all '/' to '\' */
1154 for (r
=p
; r
<(p
+longlen
); r
++ )
1155 if (r
[0]=='/') r
[0]='\\';
1156 return strlen(longpath
) - strlen(p
) + longlen
;
1160 return strlen(longpath
);
1164 /***********************************************************************
1165 * GetLongPathNameW (KERNEL32.@)
1167 DWORD WINAPI
GetLongPathNameW( LPCWSTR shortpath
, LPWSTR longpath
,
1170 DOS_FULL_NAME full_name
;
1172 LPSTR shortpathA
= HEAP_strdupWtoA( GetProcessHeap(), 0, shortpath
);
1174 /* FIXME: is it correct to always return a fully qualified short path? */
1175 if (DOSFS_GetFullName( shortpathA
, TRUE
, &full_name
))
1177 ret
= strlen( full_name
.short_name
);
1178 if (longlen
> 0 && !MultiByteToWideChar( CP_ACP
, 0, full_name
.long_name
, -1,
1179 longpath
, longlen
))
1180 longpath
[longlen
-1] = 0;
1182 HeapFree( GetProcessHeap(), 0, shortpathA
);
1187 /***********************************************************************
1188 * DOSFS_DoGetFullPathName
1190 * Implementation of GetFullPathNameA/W.
1192 * bon@elektron 000331:
1193 * A test for GetFullPathName with many pathological cases
1194 * now gives identical output for Wine and OSR2
1196 static DWORD
DOSFS_DoGetFullPathName( LPCSTR name
, DWORD len
, LPSTR result
,
1200 DOS_FULL_NAME full_name
;
1203 char drivecur
[]="c:.";
1205 int namelen
,drive
=0;
1207 if ((strlen(name
) >1)&& (name
[1]==':'))
1208 /*drive letter given */
1210 driveletter
= name
[0];
1212 if ((strlen(name
) >2)&& (name
[1]==':') &&
1213 ((name
[2]=='\\') || (name
[2]=='/')))
1214 /*absolute path given */
1216 lstrcpynA(full_name
.short_name
,name
,MAX_PATHNAME_LEN
);
1217 drive
= (int)FILE_toupper(name
[0]) - 'A';
1222 drivecur
[0]=driveletter
;
1224 strcpy(drivecur
,".");
1225 if (!DOSFS_GetFullName( drivecur
, FALSE
, &full_name
))
1227 FIXME("internal: error getting drive/path\n");
1230 /* find path that drive letter substitutes*/
1231 drive
= (int)FILE_toupper(full_name
.short_name
[0]) -0x41;
1232 root
= DRIVE_GetRoot(drive
);
1235 FIXME("internal: error getting DOS Drive Root\n");
1238 if (!strcmp(root
,"/"))
1240 /* we have just the last / and we need it. */
1241 p
= full_name
.long_name
;
1245 p
= full_name
.long_name
+strlen(root
);
1247 /* append long name (= unix name) to drive */
1248 lstrcpynA(full_name
.short_name
+2,p
,MAX_PATHNAME_LEN
-3);
1249 /* append name to treat */
1250 namelen
= strlen(full_name
.short_name
);
1253 p
+= +2; /* skip drive name when appending */
1254 if (namelen
+2 + strlen(p
) > MAX_PATHNAME_LEN
)
1256 FIXME("internal error: buffer too small\n");
1259 full_name
.short_name
[namelen
++] ='\\';
1260 full_name
.short_name
[namelen
] = 0;
1261 lstrcpynA(full_name
.short_name
+namelen
,p
,MAX_PATHNAME_LEN
-namelen
);
1263 /* reverse all slashes */
1264 for (p
=full_name
.short_name
;
1265 p
< full_name
.short_name
+strlen(full_name
.short_name
);
1271 /* Use memmove, as areas overlap*/
1273 while ((p
= strstr(full_name
.short_name
,"\\..\\")))
1275 if (p
> full_name
.short_name
+2)
1278 q
= strrchr(full_name
.short_name
,'\\');
1279 memmove(q
+1,p
+4,strlen(p
+4)+1);
1283 memmove(full_name
.short_name
+3,p
+4,strlen(p
+4)+1);
1286 if ((full_name
.short_name
[2]=='.')&&(full_name
.short_name
[3]=='.'))
1288 /* This case istn't treated yet : c:..\test */
1289 memmove(full_name
.short_name
+2,full_name
.short_name
+4,
1290 strlen(full_name
.short_name
+4)+1);
1293 while ((p
= strstr(full_name
.short_name
,"\\.\\")))
1296 memmove(p
+1,p
+3,strlen(p
+3)+1);
1298 if (!(DRIVE_GetFlags(drive
) & DRIVE_CASE_PRESERVING
))
1299 for (p
= full_name
.short_name
; *p
; p
++) *p
= FILE_toupper(*p
);
1300 namelen
=strlen(full_name
.short_name
);
1301 if (!strcmp(full_name
.short_name
+namelen
-3,"\\.."))
1303 /* one more starnge case: "c:\test\test1\.."
1305 *(full_name
.short_name
+namelen
-3)=0;
1306 q
= strrchr(full_name
.short_name
,'\\');
1309 if (full_name
.short_name
[namelen
-1]=='.')
1310 full_name
.short_name
[(namelen
--)-1] =0;
1312 if (full_name
.short_name
[namelen
-1]=='\\')
1313 full_name
.short_name
[(namelen
--)-1] =0;
1314 TRACE("got %s\n",full_name
.short_name
);
1316 /* If the lpBuffer buffer is too small, the return value is the
1317 size of the buffer, in characters, required to hold the path
1318 plus the terminating \0 (tested against win95osr, bon 001118)
1320 ret
= strlen(full_name
.short_name
);
1323 /* don't touch anything when the buffer is not large enough */
1324 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1330 MultiByteToWideChar( CP_ACP
, 0, full_name
.short_name
, -1, (LPWSTR
)result
, len
);
1332 lstrcpynA( result
, full_name
.short_name
, len
);
1335 TRACE("returning '%s'\n", full_name
.short_name
);
1340 /***********************************************************************
1341 * GetFullPathNameA (KERNEL32.@)
1343 * if the path closed with '\', *lastpart is 0
1345 DWORD WINAPI
GetFullPathNameA( LPCSTR name
, DWORD len
, LPSTR buffer
,
1348 DWORD ret
= DOSFS_DoGetFullPathName( name
, len
, buffer
, FALSE
);
1349 if (ret
&& (ret
<=len
) && buffer
&& lastpart
)
1351 LPSTR p
= buffer
+ strlen(buffer
);
1355 while ((p
> buffer
+ 2) && (*p
!= '\\')) p
--;
1358 else *lastpart
= NULL
;
1364 /***********************************************************************
1365 * GetFullPathNameW (KERNEL32.@)
1367 DWORD WINAPI
GetFullPathNameW( LPCWSTR name
, DWORD len
, LPWSTR buffer
,
1370 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
1371 DWORD ret
= DOSFS_DoGetFullPathName( nameA
, len
, (LPSTR
)buffer
, TRUE
);
1372 HeapFree( GetProcessHeap(), 0, nameA
);
1373 if (ret
&& (ret
<=len
) && buffer
&& lastpart
)
1375 LPWSTR p
= buffer
+ strlenW(buffer
);
1376 if (*p
!= (WCHAR
)'\\')
1378 while ((p
> buffer
+ 2) && (*p
!= (WCHAR
)'\\')) p
--;
1381 else *lastpart
= NULL
;
1387 /***********************************************************************
1388 * wine_get_unix_file_name (KERNEL32.@) Not a Windows API
1390 * Return the full Unix file name for a given path.
1392 BOOL WINAPI
wine_get_unix_file_name( LPCSTR dos
, LPSTR buffer
, DWORD len
)
1396 if ((ret
= DOSFS_GetFullName( dos
, FALSE
, &path
))) lstrcpynA( buffer
, path
.long_name
, len
);
1401 /***********************************************************************
1404 static int DOSFS_FindNextEx( FIND_FIRST_INFO
*info
, WIN32_FIND_DATAA
*entry
)
1406 DWORD attr
= info
->attr
| FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
| FILE_ATTRIBUTE_SYMLINK
;
1407 UINT flags
= DRIVE_GetFlags( info
->drive
);
1408 char *p
, buffer
[MAX_PATHNAME_LEN
];
1409 const char *drive_path
;
1411 LPCSTR long_name
, short_name
;
1412 BY_HANDLE_FILE_INFORMATION fileinfo
;
1415 if ((info
->attr
& ~(FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
)) == FA_LABEL
)
1417 if (info
->cur_pos
) return 0;
1418 entry
->dwFileAttributes
= FILE_ATTRIBUTE_LABEL
;
1419 RtlSecondsSince1970ToTime( (time_t)0, &entry
->ftCreationTime
);
1420 RtlSecondsSince1970ToTime( (time_t)0, &entry
->ftLastAccessTime
);
1421 RtlSecondsSince1970ToTime( (time_t)0, &entry
->ftLastWriteTime
);
1422 entry
->nFileSizeHigh
= 0;
1423 entry
->nFileSizeLow
= 0;
1424 entry
->dwReserved0
= 0;
1425 entry
->dwReserved1
= 0;
1426 DOSFS_ToDosDTAFormat( DRIVE_GetLabel( info
->drive
), entry
->cFileName
);
1427 strcpy( entry
->cAlternateFileName
, entry
->cFileName
);
1429 TRACE("returning %s (%s) as label\n",
1430 entry
->cFileName
, entry
->cAlternateFileName
);
1434 drive_path
= info
->path
+ strlen(DRIVE_GetRoot( info
->drive
));
1435 while ((*drive_path
== '/') || (*drive_path
== '\\')) drive_path
++;
1436 drive_root
= !*drive_path
;
1438 lstrcpynA( buffer
, info
->path
, sizeof(buffer
) - 1 );
1439 strcat( buffer
, "/" );
1440 p
= buffer
+ strlen(buffer
);
1442 while (DOSFS_ReadDir( info
->dir
, &long_name
, &short_name
))
1446 /* Don't return '.' and '..' in the root of the drive */
1447 if (drive_root
&& (long_name
[0] == '.') &&
1448 (!long_name
[1] || ((long_name
[1] == '.') && !long_name
[2])))
1451 /* Check the long mask */
1453 if (info
->long_mask
)
1455 if (!DOSFS_MatchLong( info
->long_mask
, long_name
,
1456 flags
& DRIVE_CASE_SENSITIVE
)) continue;
1459 /* Check the short mask */
1461 if (info
->short_mask
)
1465 DOSFS_Hash( long_name
, dos_name
, TRUE
,
1466 !(flags
& DRIVE_CASE_SENSITIVE
) );
1467 short_name
= dos_name
;
1469 if (!DOSFS_MatchShort( info
->short_mask
, short_name
)) continue;
1472 /* Check the file attributes */
1474 lstrcpynA( p
, long_name
, sizeof(buffer
) - (int)(p
- buffer
) );
1475 if (!FILE_Stat( buffer
, &fileinfo
))
1477 WARN("can't stat %s\n", buffer
);
1480 if ((fileinfo
.dwFileAttributes
& FILE_ATTRIBUTE_SYMLINK
) &&
1481 (fileinfo
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
1483 static int show_dir_symlinks
= -1;
1484 if (show_dir_symlinks
== -1)
1485 show_dir_symlinks
= PROFILE_GetWineIniBool("wine", "ShowDirSymlinks", 0);
1486 if (!show_dir_symlinks
) continue;
1489 if (fileinfo
.dwFileAttributes
& ~attr
) continue;
1491 /* We now have a matching entry; fill the result and return */
1493 entry
->dwFileAttributes
= fileinfo
.dwFileAttributes
;
1494 entry
->ftCreationTime
= fileinfo
.ftCreationTime
;
1495 entry
->ftLastAccessTime
= fileinfo
.ftLastAccessTime
;
1496 entry
->ftLastWriteTime
= fileinfo
.ftLastWriteTime
;
1497 entry
->nFileSizeHigh
= fileinfo
.nFileSizeHigh
;
1498 entry
->nFileSizeLow
= fileinfo
.nFileSizeLow
;
1501 DOSFS_ToDosDTAFormat( short_name
, entry
->cAlternateFileName
);
1503 DOSFS_Hash( long_name
, entry
->cAlternateFileName
, FALSE
,
1504 !(flags
& DRIVE_CASE_SENSITIVE
) );
1506 lstrcpynA( entry
->cFileName
, long_name
, sizeof(entry
->cFileName
) );
1507 if (!(flags
& DRIVE_CASE_PRESERVING
)) _strlwr( entry
->cFileName
);
1508 TRACE("returning %s (%s) %02lx %ld\n",
1509 entry
->cFileName
, entry
->cAlternateFileName
,
1510 entry
->dwFileAttributes
, entry
->nFileSizeLow
);
1513 return 0; /* End of directory */
1516 /***********************************************************************
1519 * Find the next matching file. Return the number of entries read to find
1520 * the matching one, or 0 if no more entries.
1521 * 'short_mask' is the 8.3 mask (in FCB format), 'long_mask' is the long
1522 * file name mask. Either or both can be NULL.
1524 * NOTE: This is supposed to be only called by the int21 emulation
1525 * routines. Thus, we should own the Win16Mutex anyway.
1526 * Nevertheless, we explicitly enter it to ensure the static
1527 * directory cache is protected.
1529 int DOSFS_FindNext( const char *path
, const char *short_mask
,
1530 const char *long_mask
, int drive
, BYTE attr
,
1531 int skip
, WIN32_FIND_DATAA
*entry
)
1533 static FIND_FIRST_INFO info
;
1534 LPCSTR short_name
, long_name
;
1539 /* Check the cached directory */
1540 if (!(info
.dir
&& info
.path
== path
&& info
.short_mask
== short_mask
1541 && info
.long_mask
== long_mask
&& info
.drive
== drive
1542 && info
.attr
== attr
&& info
.cur_pos
<= skip
))
1544 /* Not in the cache, open it anew */
1545 if (info
.dir
) DOSFS_CloseDir( info
.dir
);
1547 info
.path
= (LPSTR
)path
;
1548 info
.long_mask
= (LPSTR
)long_mask
;
1549 info
.short_mask
= (LPSTR
)short_mask
;
1553 info
.dir
= DOSFS_OpenDir( info
.path
);
1556 /* Skip to desired position */
1557 while (info
.cur_pos
< skip
)
1558 if (info
.dir
&& DOSFS_ReadDir( info
.dir
, &long_name
, &short_name
))
1563 if (info
.dir
&& info
.cur_pos
== skip
&& DOSFS_FindNextEx( &info
, entry
))
1564 count
= info
.cur_pos
- skip
;
1570 if (info
.dir
) DOSFS_CloseDir( info
.dir
);
1571 memset( &info
, '\0', sizeof(info
) );
1579 /*************************************************************************
1580 * FindFirstFileExA (KERNEL32.@)
1582 HANDLE WINAPI
FindFirstFileExA(
1584 FINDEX_INFO_LEVELS fInfoLevelId
,
1585 LPVOID lpFindFileData
,
1586 FINDEX_SEARCH_OPS fSearchOp
,
1587 LPVOID lpSearchFilter
,
1588 DWORD dwAdditionalFlags
)
1590 DOS_FULL_NAME full_name
;
1592 FIND_FIRST_INFO
*info
;
1594 if ((fSearchOp
!= FindExSearchNameMatch
) || (dwAdditionalFlags
!= 0))
1596 FIXME("options not implemented 0x%08x 0x%08lx\n", fSearchOp
, dwAdditionalFlags
);
1597 return INVALID_HANDLE_VALUE
;
1600 switch(fInfoLevelId
)
1602 case FindExInfoStandard
:
1604 WIN32_FIND_DATAA
* data
= (WIN32_FIND_DATAA
*) lpFindFileData
;
1605 data
->dwReserved0
= data
->dwReserved1
= 0x0;
1606 if (!lpFileName
) return 0;
1607 if (!DOSFS_GetFullName( lpFileName
, FALSE
, &full_name
)) break;
1608 if (!(handle
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(FIND_FIRST_INFO
)))) break;
1609 info
= (FIND_FIRST_INFO
*)GlobalLock( handle
);
1610 info
->path
= HeapAlloc( GetProcessHeap(), 0, strlen(full_name
.long_name
)+1 );
1611 strcpy( info
->path
, full_name
.long_name
);
1612 info
->long_mask
= strrchr( info
->path
, '/' );
1613 *(info
->long_mask
++) = '\0';
1614 info
->short_mask
= NULL
;
1616 if (lpFileName
[0] && (lpFileName
[1] == ':'))
1617 info
->drive
= FILE_toupper(*lpFileName
) - 'A';
1618 else info
->drive
= DRIVE_GetCurrentDrive();
1621 info
->dir
= DOSFS_OpenDir( info
->path
);
1623 GlobalUnlock( handle
);
1624 if (!FindNextFileA( handle
, data
))
1626 FindClose( handle
);
1627 SetLastError( ERROR_NO_MORE_FILES
);
1634 FIXME("fInfoLevelId 0x%08x not implemented\n", fInfoLevelId
);
1636 return INVALID_HANDLE_VALUE
;
1639 /*************************************************************************
1640 * FindFirstFileA (KERNEL32.@)
1642 HANDLE WINAPI
FindFirstFileA(
1644 WIN32_FIND_DATAA
*lpFindData
)
1646 return FindFirstFileExA(lpFileName
, FindExInfoStandard
, lpFindData
,
1647 FindExSearchNameMatch
, NULL
, 0);
1650 /*************************************************************************
1651 * FindFirstFileExW (KERNEL32.@)
1653 HANDLE WINAPI
FindFirstFileExW(
1655 FINDEX_INFO_LEVELS fInfoLevelId
,
1656 LPVOID lpFindFileData
,
1657 FINDEX_SEARCH_OPS fSearchOp
,
1658 LPVOID lpSearchFilter
,
1659 DWORD dwAdditionalFlags
)
1662 WIN32_FIND_DATAA dataA
;
1663 LPVOID _lpFindFileData
;
1666 switch(fInfoLevelId
)
1668 case FindExInfoStandard
:
1670 _lpFindFileData
= &dataA
;
1674 FIXME("fInfoLevelId 0x%08x not implemented\n", fInfoLevelId
);
1675 return INVALID_HANDLE_VALUE
;
1678 pathA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
1679 handle
= FindFirstFileExA(pathA
, fInfoLevelId
, _lpFindFileData
, fSearchOp
, lpSearchFilter
, dwAdditionalFlags
);
1680 HeapFree( GetProcessHeap(), 0, pathA
);
1681 if (handle
== INVALID_HANDLE_VALUE
) return handle
;
1683 switch(fInfoLevelId
)
1685 case FindExInfoStandard
:
1687 WIN32_FIND_DATAW
*dataW
= (WIN32_FIND_DATAW
*) lpFindFileData
;
1688 dataW
->dwFileAttributes
= dataA
.dwFileAttributes
;
1689 dataW
->ftCreationTime
= dataA
.ftCreationTime
;
1690 dataW
->ftLastAccessTime
= dataA
.ftLastAccessTime
;
1691 dataW
->ftLastWriteTime
= dataA
.ftLastWriteTime
;
1692 dataW
->nFileSizeHigh
= dataA
.nFileSizeHigh
;
1693 dataW
->nFileSizeLow
= dataA
.nFileSizeLow
;
1694 MultiByteToWideChar( CP_ACP
, 0, dataA
.cFileName
, -1,
1695 dataW
->cFileName
, sizeof(dataW
->cFileName
)/sizeof(WCHAR
) );
1696 MultiByteToWideChar( CP_ACP
, 0, dataA
.cAlternateFileName
, -1,
1697 dataW
->cAlternateFileName
,
1698 sizeof(dataW
->cAlternateFileName
)/sizeof(WCHAR
) );
1702 FIXME("fInfoLevelId 0x%08x not implemented\n", fInfoLevelId
);
1703 return INVALID_HANDLE_VALUE
;
1708 /*************************************************************************
1709 * FindFirstFileW (KERNEL32.@)
1711 HANDLE WINAPI
FindFirstFileW( LPCWSTR lpFileName
, WIN32_FIND_DATAW
*lpFindData
)
1713 return FindFirstFileExW(lpFileName
, FindExInfoStandard
, lpFindData
,
1714 FindExSearchNameMatch
, NULL
, 0);
1717 /*************************************************************************
1718 * FindNextFileA (KERNEL32.@)
1720 BOOL WINAPI
FindNextFileA( HANDLE handle
, WIN32_FIND_DATAA
*data
)
1722 FIND_FIRST_INFO
*info
;
1724 if ((handle
== INVALID_HANDLE_VALUE
) ||
1725 !(info
= (FIND_FIRST_INFO
*)GlobalLock( handle
)))
1727 SetLastError( ERROR_INVALID_HANDLE
);
1730 GlobalUnlock( handle
);
1731 if (!info
->path
|| !info
->dir
)
1733 SetLastError( ERROR_NO_MORE_FILES
);
1736 if (!DOSFS_FindNextEx( info
, data
))
1738 DOSFS_CloseDir( info
->dir
); info
->dir
= NULL
;
1739 HeapFree( GetProcessHeap(), 0, info
->path
);
1740 info
->path
= info
->long_mask
= NULL
;
1741 SetLastError( ERROR_NO_MORE_FILES
);
1748 /*************************************************************************
1749 * FindNextFileW (KERNEL32.@)
1751 BOOL WINAPI
FindNextFileW( HANDLE handle
, WIN32_FIND_DATAW
*data
)
1753 WIN32_FIND_DATAA dataA
;
1754 if (!FindNextFileA( handle
, &dataA
)) return FALSE
;
1755 data
->dwFileAttributes
= dataA
.dwFileAttributes
;
1756 data
->ftCreationTime
= dataA
.ftCreationTime
;
1757 data
->ftLastAccessTime
= dataA
.ftLastAccessTime
;
1758 data
->ftLastWriteTime
= dataA
.ftLastWriteTime
;
1759 data
->nFileSizeHigh
= dataA
.nFileSizeHigh
;
1760 data
->nFileSizeLow
= dataA
.nFileSizeLow
;
1761 MultiByteToWideChar( CP_ACP
, 0, dataA
.cFileName
, -1,
1762 data
->cFileName
, sizeof(data
->cFileName
)/sizeof(WCHAR
) );
1763 MultiByteToWideChar( CP_ACP
, 0, dataA
.cAlternateFileName
, -1,
1764 data
->cAlternateFileName
,
1765 sizeof(data
->cAlternateFileName
)/sizeof(WCHAR
) );
1769 /*************************************************************************
1770 * FindClose (KERNEL32.@)
1772 BOOL WINAPI
FindClose( HANDLE handle
)
1774 FIND_FIRST_INFO
*info
;
1776 if ((handle
== INVALID_HANDLE_VALUE
) ||
1777 !(info
= (FIND_FIRST_INFO
*)GlobalLock( handle
)))
1779 SetLastError( ERROR_INVALID_HANDLE
);
1784 if (info
->dir
) DOSFS_CloseDir( info
->dir
);
1785 if (info
->path
) HeapFree( GetProcessHeap(), 0, info
->path
);
1787 __EXCEPT(page_fault
)
1789 WARN("Illegal handle %x\n", handle
);
1790 SetLastError( ERROR_INVALID_HANDLE
);
1794 GlobalUnlock( handle
);
1795 GlobalFree( handle
);
1799 /***********************************************************************
1800 * DOSFS_UnixTimeToFileTime
1802 * Convert a Unix time to FILETIME format.
1803 * The FILETIME structure is a 64-bit value representing the number of
1804 * 100-nanosecond intervals since January 1, 1601, 0:00.
1805 * 'remainder' is the nonnegative number of 100-ns intervals
1806 * corresponding to the time fraction smaller than 1 second that
1807 * couldn't be stored in the time_t value.
1809 void DOSFS_UnixTimeToFileTime( time_t unix_time
, FILETIME
*filetime
,
1815 The time difference between 1 January 1601, 00:00:00 and
1816 1 January 1970, 00:00:00 is 369 years, plus the leap years
1817 from 1604 to 1968, excluding 1700, 1800, 1900.
1818 This makes (1968 - 1600) / 4 - 3 = 89 leap days, and a total
1821 Any day in that period had 24 * 60 * 60 = 86400 seconds.
1823 The time difference is 134774 * 86400 * 10000000, which can be written
1825 27111902 * 2^32 + 3577643008
1826 413 * 2^48 + 45534 * 2^32 + 54590 * 2^16 + 32768
1828 If you find that these constants are buggy, please change them in all
1829 instances in both conversion functions.
1832 There are two versions, one of them uses long long variables and
1833 is presumably faster but not ISO C. The other one uses standard C
1834 data types and operations but relies on the assumption that negative
1835 numbers are stored as 2's complement (-1 is 0xffff....). If this
1836 assumption is violated, dates before 1970 will not convert correctly.
1837 This should however work on any reasonable architecture where WINE
1842 Take care not to remove the casts. I have tested these functions
1843 (in both versions) for a lot of numbers. I would be interested in
1844 results on other compilers than GCC.
1846 The operations have been designed to account for the possibility
1847 of 64-bit time_t in future UNICES. Even the versions without
1848 internal long long numbers will work if time_t only is 64 bit.
1849 A 32-bit shift, which was necessary for that operation, turned out
1850 not to work correctly in GCC, besides giving the warning. So I
1851 used a double 16-bit shift instead. Numbers are in the ISO version
1852 represented by three limbs, the most significant with 32 bit, the
1853 other two with 16 bit each.
1855 As the modulo-operator % is not well-defined for negative numbers,
1856 negative divisors have been avoided in DOSFS_FileTimeToUnixTime.
1858 There might be quicker ways to do this in C. Certainly so in
1861 Claus Fischer, fischer@iue.tuwien.ac.at
1864 #if SIZEOF_LONG_LONG >= 8
1865 # define USE_LONG_LONG 1
1867 # define USE_LONG_LONG 0
1870 #if USE_LONG_LONG /* gcc supports long long type */
1872 long long int t
= unix_time
;
1874 t
+= 116444736000000000LL;
1876 filetime
->dwLowDateTime
= (UINT
)t
;
1877 filetime
->dwHighDateTime
= (UINT
)(t
>> 32);
1879 #else /* ISO version */
1881 UINT a0
; /* 16 bit, low bits */
1882 UINT a1
; /* 16 bit, medium bits */
1883 UINT a2
; /* 32 bit, high bits */
1885 /* Copy the unix time to a2/a1/a0 */
1886 a0
= unix_time
& 0xffff;
1887 a1
= (unix_time
>> 16) & 0xffff;
1888 /* This is obsolete if unix_time is only 32 bits, but it does not hurt.
1889 Do not replace this by >> 32, it gives a compiler warning and it does
1891 a2
= (unix_time
>= 0 ? (unix_time
>> 16) >> 16 :
1892 ~((~unix_time
>> 16) >> 16));
1894 /* Multiply a by 10000000 (a = a2/a1/a0)
1895 Split the factor into 10000 * 1000 which are both less than 0xffff. */
1897 a1
= a1
* 10000 + (a0
>> 16);
1898 a2
= a2
* 10000 + (a1
>> 16);
1903 a1
= a1
* 1000 + (a0
>> 16);
1904 a2
= a2
* 1000 + (a1
>> 16);
1908 /* Add the time difference and the remainder */
1909 a0
+= 32768 + (remainder
& 0xffff);
1910 a1
+= 54590 + (remainder
>> 16 ) + (a0
>> 16);
1911 a2
+= 27111902 + (a1
>> 16);
1916 filetime
->dwLowDateTime
= (a1
<< 16) + a0
;
1917 filetime
->dwHighDateTime
= a2
;
1922 /***********************************************************************
1923 * DOSFS_FileTimeToUnixTime
1925 * Convert a FILETIME format to Unix time.
1926 * If not NULL, 'remainder' contains the fractional part of the filetime,
1927 * in the range of [0..9999999] (even if time_t is negative).
1929 time_t DOSFS_FileTimeToUnixTime( const FILETIME
*filetime
, DWORD
*remainder
)
1931 /* Read the comment in the function DOSFS_UnixTimeToFileTime. */
1934 long long int t
= filetime
->dwHighDateTime
;
1936 t
+= (UINT
)filetime
->dwLowDateTime
;
1937 t
-= 116444736000000000LL;
1940 if (remainder
) *remainder
= 9999999 - (-t
- 1) % 10000000;
1941 return -1 - ((-t
- 1) / 10000000);
1945 if (remainder
) *remainder
= t
% 10000000;
1946 return t
/ 10000000;
1949 #else /* ISO version */
1951 UINT a0
; /* 16 bit, low bits */
1952 UINT a1
; /* 16 bit, medium bits */
1953 UINT a2
; /* 32 bit, high bits */
1954 UINT r
; /* remainder of division */
1955 unsigned int carry
; /* carry bit for subtraction */
1956 int negative
; /* whether a represents a negative value */
1958 /* Copy the time values to a2/a1/a0 */
1959 a2
= (UINT
)filetime
->dwHighDateTime
;
1960 a1
= ((UINT
)filetime
->dwLowDateTime
) >> 16;
1961 a0
= ((UINT
)filetime
->dwLowDateTime
) & 0xffff;
1963 /* Subtract the time difference */
1964 if (a0
>= 32768 ) a0
-= 32768 , carry
= 0;
1965 else a0
+= (1 << 16) - 32768 , carry
= 1;
1967 if (a1
>= 54590 + carry
) a1
-= 54590 + carry
, carry
= 0;
1968 else a1
+= (1 << 16) - 54590 - carry
, carry
= 1;
1970 a2
-= 27111902 + carry
;
1972 /* If a is negative, replace a by (-1-a) */
1973 negative
= (a2
>= ((UINT
)1) << 31);
1976 /* Set a to -a - 1 (a is a2/a1/a0) */
1982 /* Divide a by 10000000 (a = a2/a1/a0), put the rest into r.
1983 Split the divisor into 10000 * 1000 which are both less than 0xffff. */
1984 a1
+= (a2
% 10000) << 16;
1986 a0
+= (a1
% 10000) << 16;
1991 a1
+= (a2
% 1000) << 16;
1993 a0
+= (a1
% 1000) << 16;
1995 r
+= (a0
% 1000) * 10000;
1998 /* If a was negative, replace a by (-1-a) and r by (9999999 - r) */
2001 /* Set a to -a - 1 (a is a2/a1/a0) */
2009 if (remainder
) *remainder
= r
;
2011 /* Do not replace this by << 32, it gives a compiler warning and it does
2013 return ((((time_t)a2
) << 16) << 16) + (a1
<< 16) + a0
;
2018 /***********************************************************************
2019 * MulDiv (KERNEL32.@)
2021 * Result of multiplication and division
2022 * -1: Overflow occurred or Divisor was 0
2029 #if SIZEOF_LONG_LONG >= 8
2032 if (!nDivisor
) return -1;
2034 /* We want to deal with a positive divisor to simplify the logic. */
2037 nMultiplicand
= - nMultiplicand
;
2038 nDivisor
= -nDivisor
;
2041 /* If the result is positive, we "add" to round. else, we subtract to round. */
2042 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
2043 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
2044 ret
= (((long long)nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
2046 ret
= (((long long)nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;
2048 if ((ret
> 2147483647) || (ret
< -2147483647)) return -1;
2051 if (!nDivisor
) return -1;
2053 /* We want to deal with a positive divisor to simplify the logic. */
2056 nMultiplicand
= - nMultiplicand
;
2057 nDivisor
= -nDivisor
;
2060 /* If the result is positive, we "add" to round. else, we subtract to round. */
2061 if ( ( (nMultiplicand
< 0) && (nMultiplier
< 0) ) ||
2062 ( (nMultiplicand
>= 0) && (nMultiplier
>= 0) ) )
2063 return ((nMultiplicand
* nMultiplier
) + (nDivisor
/2)) / nDivisor
;
2065 return ((nMultiplicand
* nMultiplier
) - (nDivisor
/2)) / nDivisor
;
2071 /***********************************************************************
2072 * DosDateTimeToFileTime (KERNEL32.@)
2074 BOOL WINAPI
DosDateTimeToFileTime( WORD fatdate
, WORD fattime
, LPFILETIME ft
)
2078 newtm
.tm_sec
= (fattime
& 0x1f) * 2;
2079 newtm
.tm_min
= (fattime
>> 5) & 0x3f;
2080 newtm
.tm_hour
= (fattime
>> 11);
2081 newtm
.tm_mday
= (fatdate
& 0x1f);
2082 newtm
.tm_mon
= ((fatdate
>> 5) & 0x0f) - 1;
2083 newtm
.tm_year
= (fatdate
>> 9) + 80;
2084 RtlSecondsSince1970ToTime( mktime( &newtm
), ft
);
2089 /***********************************************************************
2090 * FileTimeToDosDateTime (KERNEL32.@)
2092 BOOL WINAPI
FileTimeToDosDateTime( const FILETIME
*ft
, LPWORD fatdate
,
2095 time_t unixtime
= DOSFS_FileTimeToUnixTime( ft
, NULL
);
2096 struct tm
*tm
= localtime( &unixtime
);
2098 *fattime
= (tm
->tm_hour
<< 11) + (tm
->tm_min
<< 5) + (tm
->tm_sec
/ 2);
2100 *fatdate
= ((tm
->tm_year
- 80) << 9) + ((tm
->tm_mon
+ 1) << 5)
2106 /***********************************************************************
2107 * LocalFileTimeToFileTime (KERNEL32.@)
2109 BOOL WINAPI
LocalFileTimeToFileTime( const FILETIME
*localft
,
2115 /* convert from local to UTC. Perhaps not correct. FIXME */
2116 time_t unixtime
= DOSFS_FileTimeToUnixTime( localft
, &remainder
);
2117 xtm
= gmtime( &unixtime
);
2118 DOSFS_UnixTimeToFileTime( mktime(xtm
), utcft
, remainder
);
2123 /***********************************************************************
2124 * FileTimeToLocalFileTime (KERNEL32.@)
2126 BOOL WINAPI
FileTimeToLocalFileTime( const FILETIME
*utcft
,
2127 LPFILETIME localft
)
2130 /* convert from UTC to local. Perhaps not correct. FIXME */
2131 time_t unixtime
= DOSFS_FileTimeToUnixTime( utcft
, &remainder
);
2133 struct tm
*xtm
= localtime( &unixtime
);
2136 localtime
= timegm(xtm
);
2137 DOSFS_UnixTimeToFileTime( localtime
, localft
, remainder
);
2140 struct tm
*xtm
,*gtm
;
2143 xtm
= localtime( &unixtime
);
2144 gtm
= gmtime( &unixtime
);
2145 time1
= mktime(xtm
);
2146 time2
= mktime(gtm
);
2147 DOSFS_UnixTimeToFileTime( 2*time1
-time2
, localft
, remainder
);
2153 /***********************************************************************
2154 * FileTimeToSystemTime (KERNEL32.@)
2156 BOOL WINAPI
FileTimeToSystemTime( const FILETIME
*ft
, LPSYSTEMTIME syst
)
2160 time_t xtime
= DOSFS_FileTimeToUnixTime( ft
, &remainder
);
2161 xtm
= gmtime(&xtime
);
2162 syst
->wYear
= xtm
->tm_year
+1900;
2163 syst
->wMonth
= xtm
->tm_mon
+ 1;
2164 syst
->wDayOfWeek
= xtm
->tm_wday
;
2165 syst
->wDay
= xtm
->tm_mday
;
2166 syst
->wHour
= xtm
->tm_hour
;
2167 syst
->wMinute
= xtm
->tm_min
;
2168 syst
->wSecond
= xtm
->tm_sec
;
2169 syst
->wMilliseconds
= remainder
/ 10000;
2173 /***********************************************************************
2174 * QueryDosDeviceA (KERNEL32.@)
2176 * returns array of strings terminated by \0, terminated by \0
2178 DWORD WINAPI
QueryDosDeviceA(LPCSTR devname
,LPSTR target
,DWORD bufsize
)
2183 TRACE("(%s,...)\n", devname
? devname
: "<null>");
2185 /* return known MSDOS devices */
2186 static const char devices
[24] = "CON\0COM1\0COM2\0LPT1\0NUL\0\0";
2187 memcpy( target
, devices
, min(bufsize
,sizeof(devices
)) );
2188 return min(bufsize
,sizeof(devices
));
2190 /* In theory all that are possible and have been defined.
2191 * Now just those below, since mirc uses it to check for special files.
2193 * (It is more complex, and supports netmounted stuff, and \\.\ stuff,
2194 * but currently we just ignore that.)
2196 #define CHECK(x) (strstr(devname,#x)==devname)
2197 if (CHECK(con
) || CHECK(com
) || CHECK(lpt
) || CHECK(nul
)) {
2198 strcpy(buffer
,"\\DEV\\");
2199 strcat(buffer
,devname
);
2200 if ((s
=strchr(buffer
,':'))) *s
='\0';
2201 lstrcpynA(target
,buffer
,bufsize
);
2202 return strlen(buffer
)+1;
2204 if (strchr(devname
,':') || devname
[0]=='\\') {
2205 /* This might be a DOS device we do not handle yet ... */
2206 FIXME("(%s) not detected as DOS device!\n",devname
);
2208 SetLastError(ERROR_DEV_NOT_EXIST
);
2215 /***********************************************************************
2216 * QueryDosDeviceW (KERNEL32.@)
2218 * returns array of strings terminated by \0, terminated by \0
2220 DWORD WINAPI
QueryDosDeviceW(LPCWSTR devname
,LPWSTR target
,DWORD bufsize
)
2222 LPSTR devnameA
= devname
?HEAP_strdupWtoA(GetProcessHeap(),0,devname
):NULL
;
2223 LPSTR targetA
= (LPSTR
)HeapAlloc(GetProcessHeap(),0,bufsize
);
2224 DWORD ret
= QueryDosDeviceA(devnameA
,targetA
,bufsize
);
2226 ret
= MultiByteToWideChar( CP_ACP
, 0, targetA
, ret
, target
, bufsize
);
2227 if (devnameA
) HeapFree(GetProcessHeap(),0,devnameA
);
2228 if (targetA
) HeapFree(GetProcessHeap(),0,targetA
);
2233 /***********************************************************************
2234 * SystemTimeToFileTime (KERNEL32.@)
2236 BOOL WINAPI
SystemTimeToFileTime( const SYSTEMTIME
*syst
, LPFILETIME ft
)
2242 struct tm xtm
,*local_tm
,*utc_tm
;
2243 time_t localtim
,utctime
;
2246 xtm
.tm_year
= syst
->wYear
-1900;
2247 xtm
.tm_mon
= syst
->wMonth
- 1;
2248 xtm
.tm_wday
= syst
->wDayOfWeek
;
2249 xtm
.tm_mday
= syst
->wDay
;
2250 xtm
.tm_hour
= syst
->wHour
;
2251 xtm
.tm_min
= syst
->wMinute
;
2252 xtm
.tm_sec
= syst
->wSecond
; /* this is UTC */
2255 utctime
= timegm(&xtm
);
2256 DOSFS_UnixTimeToFileTime( utctime
, ft
,
2257 syst
->wMilliseconds
* 10000 );
2259 localtim
= mktime(&xtm
); /* now we've got local time */
2260 local_tm
= localtime(&localtim
);
2261 utc_tm
= gmtime(&localtim
);
2262 utctime
= mktime(utc_tm
);
2263 DOSFS_UnixTimeToFileTime( 2*localtim
-utctime
, ft
,
2264 syst
->wMilliseconds
* 10000 );
2269 /***********************************************************************
2270 * DefineDosDeviceA (KERNEL32.@)
2272 BOOL WINAPI
DefineDosDeviceA(DWORD flags
,LPCSTR devname
,LPCSTR targetpath
) {
2273 FIXME("(0x%08lx,%s,%s),stub!\n",flags
,devname
,targetpath
);
2274 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
2279 --- 16 bit functions ---
2282 /*************************************************************************
2283 * FindFirstFile (KERNEL.413)
2285 HANDLE16 WINAPI
FindFirstFile16( LPCSTR path
, WIN32_FIND_DATAA
*data
)
2287 DOS_FULL_NAME full_name
;
2289 FIND_FIRST_INFO
*info
;
2291 data
->dwReserved0
= data
->dwReserved1
= 0x0;
2292 if (!path
) return 0;
2293 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
2294 return INVALID_HANDLE_VALUE16
;
2295 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
, sizeof(FIND_FIRST_INFO
) )))
2296 return INVALID_HANDLE_VALUE16
;
2297 info
= (FIND_FIRST_INFO
*)GlobalLock16( handle
);
2298 info
->path
= HeapAlloc( GetProcessHeap(), 0, strlen(full_name
.long_name
)+1 );
2299 strcpy( info
->path
, full_name
.long_name
);
2300 info
->long_mask
= strrchr( info
->path
, '/' );
2301 if (info
->long_mask
)
2302 *(info
->long_mask
++) = '\0';
2303 info
->short_mask
= NULL
;
2305 if (path
[0] && (path
[1] == ':')) info
->drive
= FILE_toupper(*path
) - 'A';
2306 else info
->drive
= DRIVE_GetCurrentDrive();
2309 info
->dir
= DOSFS_OpenDir( info
->path
);
2311 GlobalUnlock16( handle
);
2312 if (!FindNextFile16( handle
, data
))
2314 FindClose16( handle
);
2315 SetLastError( ERROR_NO_MORE_FILES
);
2316 return INVALID_HANDLE_VALUE16
;
2321 /*************************************************************************
2322 * FindNextFile (KERNEL.414)
2324 BOOL16 WINAPI
FindNextFile16( HANDLE16 handle
, WIN32_FIND_DATAA
*data
)
2326 FIND_FIRST_INFO
*info
;
2328 if ((handle
== INVALID_HANDLE_VALUE16
) ||
2329 !(info
= (FIND_FIRST_INFO
*)GlobalLock16( handle
)))
2331 SetLastError( ERROR_INVALID_HANDLE
);
2334 GlobalUnlock16( handle
);
2335 if (!info
->path
|| !info
->dir
)
2337 SetLastError( ERROR_NO_MORE_FILES
);
2340 if (!DOSFS_FindNextEx( info
, data
))
2342 DOSFS_CloseDir( info
->dir
); info
->dir
= NULL
;
2343 HeapFree( GetProcessHeap(), 0, info
->path
);
2344 info
->path
= info
->long_mask
= NULL
;
2345 SetLastError( ERROR_NO_MORE_FILES
);
2351 /*************************************************************************
2352 * FindClose (KERNEL.415)
2354 BOOL16 WINAPI
FindClose16( HANDLE16 handle
)
2356 FIND_FIRST_INFO
*info
;
2358 if ((handle
== INVALID_HANDLE_VALUE16
) ||
2359 !(info
= (FIND_FIRST_INFO
*)GlobalLock16( handle
)))
2361 SetLastError( ERROR_INVALID_HANDLE
);
2364 if (info
->dir
) DOSFS_CloseDir( info
->dir
);
2365 if (info
->path
) HeapFree( GetProcessHeap(), 0, info
->path
);
2366 GlobalUnlock16( handle
);
2367 GlobalFree16( handle
);