4 * Copyright 2002, 2003, 2004 Alexandre Julliard
5 * Copyright 2003 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sys/types.h>
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "wine/library.h"
35 #include "ntdll_misc.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(file
);
39 static const WCHAR DeviceRootW
[] = {'\\','\\','.','\\',0};
40 static const WCHAR NTDosPrefixW
[] = {'\\','?','?','\\',0};
41 static const WCHAR UncPfxW
[] = {'U','N','C','\\',0};
44 HANDLE (WINAPI
*pCreateFileW
)( LPCWSTR filename
, DWORD access
, DWORD sharing
,
45 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
46 DWORD attributes
, HANDLE
template );
48 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
50 #define MAX_DOS_DRIVES 26
58 /***********************************************************************
61 * Retrieve device/inode number for all the drives. Helper for find_drive_root.
63 static inline int get_drives_info( struct drive_info info
[MAX_DOS_DRIVES
] )
65 const char *config_dir
= wine_get_config_dir();
70 buffer
= RtlAllocateHeap( GetProcessHeap(), 0, strlen(config_dir
) + sizeof("/dosdevices/a:") );
71 if (!buffer
) return 0;
72 strcpy( buffer
, config_dir
);
73 strcat( buffer
, "/dosdevices/a:" );
74 p
= buffer
+ strlen(buffer
) - 2;
76 for (i
= ret
= 0; i
< MAX_DOS_DRIVES
; i
++)
79 if (!stat( buffer
, &st
))
81 info
[i
].dev
= st
.st_dev
;
82 info
[i
].ino
= st
.st_ino
;
91 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
96 /***********************************************************************
97 * remove_last_component
99 * Remove the last component of the path. Helper for find_drive_root.
101 static inline int remove_last_component( const WCHAR
*path
, int len
)
107 /* find start of the last path component */
109 if (prev
<= 1) break; /* reached root */
110 while (prev
> 1 && !IS_SEPARATOR(path
[prev
- 1])) prev
--;
111 /* does removing it take us up a level? */
112 if (len
- prev
!= 1 || path
[prev
] != '.') /* not '.' */
114 if (len
- prev
== 2 && path
[prev
] == '.' && path
[prev
+1] == '.') /* is it '..'? */
119 /* strip off trailing slashes */
120 while (prev
> 1 && IS_SEPARATOR(path
[prev
- 1])) prev
--;
127 /***********************************************************************
130 * Find a drive for which the root matches the beginning of the given path.
131 * This can be used to translate a Unix path into a drive + DOS path.
132 * Return value is the drive, or -1 on error. On success, ppath is modified
133 * to point to the beginning of the DOS path.
135 static int find_drive_root( LPCWSTR
*ppath
)
137 /* Starting with the full path, check if the device and inode match any of
138 * the wine 'drives'. If not then remove the last path component and try
139 * again. If the last component was a '..' then skip a normal component
140 * since it's a directory that's ascended back out of.
142 int drive
, lenA
, lenW
;
144 const WCHAR
*path
= *ppath
;
146 struct drive_info info
[MAX_DOS_DRIVES
];
148 /* get device and inode of all drives */
149 if (!get_drives_info( info
)) return -1;
151 /* strip off trailing slashes */
152 lenW
= strlenW(path
);
153 while (lenW
> 1 && IS_SEPARATOR(path
[lenW
- 1])) lenW
--;
155 /* convert path to Unix encoding */
156 lenA
= ntdll_wcstoumbs( 0, path
, lenW
, NULL
, 0, NULL
, NULL
);
157 if (!(buffer
= RtlAllocateHeap( GetProcessHeap(), 0, lenA
+ 1 ))) return -1;
158 lenA
= ntdll_wcstoumbs( 0, path
, lenW
, buffer
, lenA
, NULL
, NULL
);
160 for (p
= buffer
; *p
; p
++) if (*p
== '\\') *p
= '/';
164 if (!stat( buffer
, &st
) && S_ISDIR( st
.st_mode
))
167 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
169 if ((info
[drive
].dev
== st
.st_dev
) && (info
[drive
].ino
== st
.st_ino
))
171 if (lenW
== 1) lenW
= 0; /* preserve root slash in returned path */
172 TRACE( "%s -> drive %c:, root=%s, name=%s\n",
173 debugstr_w(path
), 'A' + drive
, debugstr_a(buffer
), debugstr_w(path
+ lenW
));
175 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
180 if (lenW
<= 1) break; /* reached root */
181 lenW
= remove_last_component( path
, lenW
);
183 /* we only need the new length, buffer already contains the converted string */
184 lenA
= ntdll_wcstoumbs( 0, path
, lenW
, NULL
, 0, NULL
, NULL
);
187 RtlFreeHeap( GetProcessHeap(), 0, buffer
);
192 /***********************************************************************
193 * RtlDetermineDosPathNameType_U (NTDLL.@)
195 DOS_PATHNAME_TYPE WINAPI
RtlDetermineDosPathNameType_U( PCWSTR path
)
197 if (IS_SEPARATOR(path
[0]))
199 if (!IS_SEPARATOR(path
[1])) return ABSOLUTE_PATH
; /* "/foo" */
200 if (path
[2] != '.') return UNC_PATH
; /* "//foo" */
201 if (IS_SEPARATOR(path
[3])) return DEVICE_PATH
; /* "//./foo" */
202 if (path
[3]) return UNC_PATH
; /* "//.foo" */
203 return UNC_DOT_PATH
; /* "//." */
207 if (!path
[0] || path
[1] != ':') return RELATIVE_PATH
; /* "foo" */
208 if (IS_SEPARATOR(path
[2])) return ABSOLUTE_DRIVE_PATH
; /* "c:/foo" */
209 return RELATIVE_DRIVE_PATH
; /* "c:foo" */
213 /******************************************************************
214 * RtlDoesFileExists_U
216 * FIXME: should not use CreateFileW
218 BOOLEAN WINAPI
RtlDoesFileExists_U(LPCWSTR file_name
)
220 HANDLE handle
= pCreateFileW( file_name
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
221 NULL
, OPEN_EXISTING
, 0, 0 );
222 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
227 /***********************************************************************
228 * RtlIsDosDeviceName_U (NTDLL.@)
230 * Check if the given DOS path contains a DOS device name.
232 * Returns the length of the device name in the low word and its
233 * position in the high word (both in bytes, not WCHARs), or 0 if no
234 * device name is found.
236 ULONG WINAPI
RtlIsDosDeviceName_U( PCWSTR dos_name
)
238 static const WCHAR consoleW
[] = {'\\','\\','.','\\','C','O','N',0};
239 static const WCHAR auxW
[3] = {'A','U','X'};
240 static const WCHAR comW
[3] = {'C','O','M'};
241 static const WCHAR conW
[3] = {'C','O','N'};
242 static const WCHAR lptW
[3] = {'L','P','T'};
243 static const WCHAR nulW
[3] = {'N','U','L'};
244 static const WCHAR prnW
[3] = {'P','R','N'};
246 const WCHAR
*start
, *end
, *p
;
248 switch(RtlDetermineDosPathNameType_U( dos_name
))
254 if (!strcmpiW( dos_name
, consoleW
))
255 return MAKELONG( sizeof(conW
), 4 * sizeof(WCHAR
) ); /* 4 is length of \\.\ prefix */
261 end
= dos_name
+ strlenW(dos_name
) - 1;
262 if (end
>= dos_name
&& *end
== ':') end
--; /* remove trailing ':' */
264 /* find start of file name */
265 for (start
= end
; start
>= dos_name
; start
--)
267 if (IS_SEPARATOR(start
[0])) break;
268 /* check for ':' but ignore if before extension (for things like NUL:.txt) */
269 if (start
[0] == ':' && start
[1] != '.') break;
273 /* remove extension */
274 if ((p
= strchrW( start
, '.' )))
277 if (end
>= dos_name
&& *end
== ':') end
--; /* remove trailing ':' before extension */
281 /* no extension, remove trailing spaces */
282 while (end
>= dos_name
&& *end
== ' ') end
--;
285 /* now we have a potential device name between start and end, check it */
286 switch(end
- start
+ 1)
289 if (strncmpiW( start
, auxW
, 3 ) &&
290 strncmpiW( start
, conW
, 3 ) &&
291 strncmpiW( start
, nulW
, 3 ) &&
292 strncmpiW( start
, prnW
, 3 )) break;
293 return MAKELONG( 3 * sizeof(WCHAR
), (start
- dos_name
) * sizeof(WCHAR
) );
295 if (strncmpiW( start
, comW
, 3 ) && strncmpiW( start
, lptW
, 3 )) break;
296 if (*end
<= '0' || *end
> '9') break;
297 return MAKELONG( 4 * sizeof(WCHAR
), (start
- dos_name
) * sizeof(WCHAR
) );
298 default: /* can't match anything */
305 /**************************************************************************
306 * RtlDosPathNameToNtPathName_U [NTDLL.@]
308 * dos_path: a DOS path name (fully qualified or not)
309 * ntpath: pointer to a UNICODE_STRING to hold the converted
311 * file_part:will point (in ntpath) to the file part in the path
312 * cd: directory reference (optional)
315 * + fill the cd structure
317 BOOLEAN WINAPI
RtlDosPathNameToNtPathName_U(PCWSTR dos_path
,
318 PUNICODE_STRING ntpath
,
322 static const WCHAR LongFileNamePfxW
[4] = {'\\','\\','?','\\'};
323 ULONG sz
, ptr_sz
, offset
;
324 WCHAR local
[MAX_PATH
];
327 TRACE("(%s,%p,%p,%p)\n",
328 debugstr_w(dos_path
), ntpath
, file_part
, cd
);
332 FIXME("Unsupported parameter\n");
333 memset(cd
, 0, sizeof(*cd
));
336 if (!dos_path
|| !*dos_path
) return FALSE
;
338 if (!memcmp(dos_path
, LongFileNamePfxW
, sizeof(LongFileNamePfxW
)))
340 dos_path
+= sizeof(LongFileNamePfxW
) / sizeof(WCHAR
);
347 ptr_sz
= sizeof(local
);
349 sz
= RtlGetFullPathName_U(dos_path
, ptr_sz
, ptr
, file_part
);
350 if (sz
== 0) return FALSE
;
353 ptr
= RtlAllocateHeap(GetProcessHeap(), 0, sz
);
354 sz
= RtlGetFullPathName_U(dos_path
, sz
, ptr
, file_part
);
357 ntpath
->MaximumLength
= sz
+ (4 /* unc\ */ + 4 /* \??\ */) * sizeof(WCHAR
);
358 ntpath
->Buffer
= RtlAllocateHeap(GetProcessHeap(), 0, ntpath
->MaximumLength
);
361 if (ptr
!= local
) RtlFreeHeap(GetProcessHeap(), 0, ptr
);
365 strcpyW(ntpath
->Buffer
, NTDosPrefixW
);
367 switch (RtlDetermineDosPathNameType_U(ptr
))
369 case UNC_PATH
: /* \\foo */
373 strcatW(ntpath
->Buffer
, UncPfxW
);
376 case DEVICE_PATH
: /* \\.\foo */
379 default: break; /* needed to keep gcc quiet */
382 strcatW(ntpath
->Buffer
, ptr
+ offset
);
383 ntpath
->Length
= strlenW(ntpath
->Buffer
) * sizeof(WCHAR
);
385 if (file_part
&& *file_part
)
386 *file_part
= ntpath
->Buffer
+ ntpath
->Length
/ sizeof(WCHAR
) - strlenW(*file_part
);
388 /* FIXME: cd filling */
390 if (ptr
!= local
) RtlFreeHeap(GetProcessHeap(), 0, ptr
);
394 /******************************************************************
397 * Searchs a file of name 'name' into a ';' separated list of paths
399 * Doesn't seem to search elsewhere than the paths list
400 * Stores the result in buffer (file_part will point to the position
401 * of the file name in the buffer)
403 * - how long shall the paths be ??? (MAX_PATH or larger with \\?\ constructs ???)
405 ULONG WINAPI
RtlDosSearchPath_U(LPCWSTR paths
, LPCWSTR search
, LPCWSTR ext
,
406 ULONG buffer_size
, LPWSTR buffer
,
409 DOS_PATHNAME_TYPE type
= RtlDetermineDosPathNameType_U(search
);
412 if (type
== RELATIVE_PATH
)
414 ULONG allocated
= 0, needed
, filelen
;
417 filelen
= 1 /* for \ */ + strlenW(search
) + 1 /* \0 */;
419 /* Windows only checks for '.' without worrying about path components */
420 if (strchrW( search
, '.' )) ext
= NULL
;
421 if (ext
!= NULL
) filelen
+= strlenW(ext
);
427 for (needed
= 0, ptr
= paths
; *ptr
!= 0 && *ptr
++ != ';'; needed
++);
428 if (needed
+ filelen
> allocated
)
430 if (!name
) name
= RtlAllocateHeap(GetProcessHeap(), 0,
431 (needed
+ filelen
) * sizeof(WCHAR
));
434 WCHAR
*newname
= RtlReAllocateHeap(GetProcessHeap(), 0, name
,
435 (needed
+ filelen
) * sizeof(WCHAR
));
436 if (!newname
) RtlFreeHeap(GetProcessHeap(), 0, name
);
440 allocated
= needed
+ filelen
;
442 memmove(name
, paths
, needed
* sizeof(WCHAR
));
443 /* append '\\' if none is present */
444 if (needed
> 0 && name
[needed
- 1] != '\\') name
[needed
++] = '\\';
445 strcpyW(&name
[needed
], search
);
446 if (ext
) strcatW(&name
[needed
], ext
);
447 if (RtlDoesFileExists_U(name
))
449 len
= RtlGetFullPathName_U(name
, buffer_size
, buffer
, file_part
);
454 RtlFreeHeap(GetProcessHeap(), 0, name
);
456 else if (RtlDoesFileExists_U(search
))
458 len
= RtlGetFullPathName_U(search
, buffer_size
, buffer
, file_part
);
465 /******************************************************************
468 * Helper for RtlGetFullPathName_U.
469 * Get rid of . and .. components in the path.
471 static inline void collapse_path( WCHAR
*path
, UINT mark
)
475 /* convert every / into a \ */
476 for (p
= path
; *p
; p
++) if (*p
== '/') *p
= '\\';
478 /* collapse duplicate backslashes */
479 next
= path
+ max( 1, mark
);
480 for (p
= next
; *p
; p
++) if (*p
!= '\\' || next
[-1] != '\\') *next
++ = *p
;
490 case '\\': /* .\ component */
492 memmove( p
, next
, (strlenW(next
) + 1) * sizeof(WCHAR
) );
494 case 0: /* final . */
495 if (p
> path
+ mark
) p
--;
499 if (p
[2] == '\\') /* ..\ component */
505 while (p
> path
+ mark
&& p
[-1] != '\\') p
--;
507 memmove( p
, next
, (strlenW(next
) + 1) * sizeof(WCHAR
) );
510 else if (!p
[2]) /* final .. */
515 while (p
> path
+ mark
&& p
[-1] != '\\') p
--;
516 if (p
> path
+ mark
) p
--;
524 /* skip to the next component */
525 while (*p
&& *p
!= '\\') p
++;
530 /******************************************************************
531 * get_full_path_helper
533 * Helper for RtlGetFullPathName_U
534 * Note: name and buffer are allowed to point to the same memory spot
536 static ULONG
get_full_path_helper(LPCWSTR name
, LPWSTR buffer
, ULONG size
)
538 ULONG reqsize
= 0, mark
= 0, dep
= 0, deplen
;
539 DOS_PATHNAME_TYPE type
;
540 LPWSTR ins_str
= NULL
;
542 const UNICODE_STRING
* cd
;
547 cd
= &NtCurrentTeb()->Peb
->ProcessParameters
->CurrentDirectoryName
;
549 switch (type
= RtlDetermineDosPathNameType_U(name
))
551 case UNC_PATH
: /* \\foo */
553 while (*ptr
&& !IS_SEPARATOR(*ptr
)) ptr
++; /* share name */
554 while (*ptr
&& IS_SEPARATOR(*ptr
)) ptr
++;
555 while (*ptr
&& !IS_SEPARATOR(*ptr
)) ptr
++; /* dir name */
559 case DEVICE_PATH
: /* \\.\foo */
563 case ABSOLUTE_DRIVE_PATH
: /* c:\foo */
564 reqsize
= sizeof(WCHAR
);
565 tmp
[0] = toupperW(name
[0]);
571 case RELATIVE_DRIVE_PATH
: /* c:foo */
573 if (toupperW(name
[0]) != toupperW(cd
->Buffer
[0]) || cd
->Buffer
[1] != ':')
575 UNICODE_STRING var
, val
;
581 var
.Length
= 3 * sizeof(WCHAR
);
582 var
.MaximumLength
= 4 * sizeof(WCHAR
);
585 val
.MaximumLength
= size
;
586 val
.Buffer
= RtlAllocateHeap(GetProcessHeap(), 0, size
);
588 switch (RtlQueryEnvironmentVariable_U(NULL
, &var
, &val
))
591 /* FIXME: Win2k seems to check that the environment variable actually points
592 * to an existing directory. If not, root of the drive is used
593 * (this seems also to be the only spot in RtlGetFullPathName that the
594 * existence of a part of a path is checked)
597 case STATUS_BUFFER_TOO_SMALL
:
598 reqsize
= val
.Length
+ sizeof(WCHAR
); /* append trailing '\\' */
599 val
.Buffer
[val
.Length
/ sizeof(WCHAR
)] = '\\';
600 ins_str
= val
.Buffer
;
602 case STATUS_VARIABLE_NOT_FOUND
:
603 reqsize
= 3 * sizeof(WCHAR
);
610 ERR("Unsupported status code\n");
618 case RELATIVE_PATH
: /* foo */
619 reqsize
= cd
->Length
;
620 ins_str
= cd
->Buffer
;
621 if (cd
->Buffer
[1] != ':')
623 ptr
= strchrW(cd
->Buffer
+ 2, '\\');
624 if (ptr
) ptr
= strchrW(ptr
+ 1, '\\');
625 if (!ptr
) ptr
= cd
->Buffer
+ strlenW(cd
->Buffer
);
626 mark
= ptr
- cd
->Buffer
;
631 case ABSOLUTE_PATH
: /* \xxx */
632 if (name
[0] == '/') /* may be a Unix path */
634 const WCHAR
*ptr
= name
;
635 int drive
= find_drive_root( &ptr
);
638 reqsize
= 3 * sizeof(WCHAR
);
639 tmp
[0] = 'A' + drive
;
648 if (cd
->Buffer
[1] == ':')
650 reqsize
= 2 * sizeof(WCHAR
);
651 tmp
[0] = cd
->Buffer
[0];
658 ptr
= strchrW(cd
->Buffer
+ 2, '\\');
659 if (ptr
) ptr
= strchrW(ptr
+ 1, '\\');
660 if (!ptr
) ptr
= cd
->Buffer
+ strlenW(cd
->Buffer
);
661 reqsize
= (ptr
- cd
->Buffer
) * sizeof(WCHAR
);
662 mark
= reqsize
/ sizeof(WCHAR
);
663 ins_str
= cd
->Buffer
;
667 case UNC_DOT_PATH
: /* \\. */
668 reqsize
= 4 * sizeof(WCHAR
);
683 deplen
= strlenW(name
+ dep
) * sizeof(WCHAR
);
684 if (reqsize
+ deplen
+ sizeof(WCHAR
) > size
)
686 /* not enough space, return need size (including terminating '\0') */
687 reqsize
+= deplen
+ sizeof(WCHAR
);
691 memmove(buffer
+ reqsize
/ sizeof(WCHAR
), name
+ dep
, deplen
+ sizeof(WCHAR
));
692 if (reqsize
) memcpy(buffer
, ins_str
, reqsize
);
695 if (ins_str
&& ins_str
!= tmp
&& ins_str
!= cd
->Buffer
)
696 RtlFreeHeap(GetProcessHeap(), 0, ins_str
);
698 collapse_path( buffer
, mark
);
699 reqsize
= strlenW(buffer
) * sizeof(WCHAR
);
706 /******************************************************************
707 * RtlGetFullPathName_U (NTDLL.@)
709 * Returns the number of bytes written to buffer (not including the
710 * terminating NULL) if the function succeeds, or the required number of bytes
711 * (including the terminating NULL) if the buffer is too small.
713 * file_part will point to the filename part inside buffer (except if we use
714 * DOS device name, in which case file_in_buf is NULL)
717 DWORD WINAPI
RtlGetFullPathName_U(const WCHAR
* name
, ULONG size
, WCHAR
* buffer
,
724 TRACE("(%s %lu %p %p)\n", debugstr_w(name
), size
, buffer
, file_part
);
726 if (!name
|| !*name
) return 0;
728 if (file_part
) *file_part
= NULL
;
730 /* check for DOS device name */
731 dosdev
= RtlIsDosDeviceName_U(name
);
734 DWORD offset
= HIWORD(dosdev
) / sizeof(WCHAR
); /* get it in WCHARs, not bytes */
735 DWORD sz
= LOWORD(dosdev
); /* in bytes */
737 if (8 + sz
+ 2 > size
) return sz
+ 10;
738 strcpyW(buffer
, DeviceRootW
);
739 memmove(buffer
+ 4, name
+ offset
, sz
);
740 buffer
[4 + sz
/ sizeof(WCHAR
)] = '\0';
741 /* file_part isn't set in this case */
745 reqsize
= get_full_path_helper(name
, buffer
, size
);
748 LPWSTR tmp
= RtlAllocateHeap(GetProcessHeap(), 0, reqsize
);
749 reqsize
= get_full_path_helper(name
, tmp
, reqsize
);
750 if (reqsize
> size
) /* it may have worked the second time */
752 RtlFreeHeap(GetProcessHeap(), 0, tmp
);
753 return reqsize
+ sizeof(WCHAR
);
755 memcpy( buffer
, tmp
, reqsize
+ sizeof(WCHAR
) );
756 RtlFreeHeap(GetProcessHeap(), 0, tmp
);
760 if (file_part
&& (ptr
= strrchrW(buffer
, '\\')) != NULL
&& ptr
>= buffer
+ 2 && *++ptr
)
765 /*************************************************************************
766 * RtlGetLongestNtPathLength [NTDLL.@]
768 * Get the longest allowed path length
774 * The longest allowed path length (277 characters under Win2k).
776 DWORD WINAPI
RtlGetLongestNtPathLength(void)
781 /******************************************************************
782 * RtlIsNameLegalDOS8Dot3 (NTDLL.@)
784 * Returns TRUE iff unicode is a valid DOS (8+3) name.
785 * If the name is valid, oem gets filled with the corresponding OEM string
786 * spaces is set to TRUE if unicode contains spaces
788 BOOLEAN WINAPI
RtlIsNameLegalDOS8Dot3( const UNICODE_STRING
*unicode
,
789 OEM_STRING
*oem
, BOOLEAN
*spaces
)
791 static const char* illegal
= "*?<>|\"+=,;[]:/\\\345";
796 BOOLEAN got_space
= FALSE
;
800 oem_str
.Length
= sizeof(buffer
);
801 oem_str
.MaximumLength
= sizeof(buffer
);
802 oem_str
.Buffer
= buffer
;
805 if (RtlUpcaseUnicodeStringToCountedOemString( oem
, unicode
, FALSE
) != STATUS_SUCCESS
)
808 if (oem
->Length
> 12) return FALSE
;
810 /* a starting . is invalid, except for . and .. */
811 if (oem
->Buffer
[0] == '.')
813 if (oem
->Length
!= 1 && (oem
->Length
!= 2 || oem
->Buffer
[1] != '.')) return FALSE
;
814 if (spaces
) *spaces
= FALSE
;
818 for (i
= 0; i
< oem
->Length
; i
++)
820 switch (oem
->Buffer
[i
])
823 /* leading/trailing spaces not allowed */
824 if (!i
|| i
== oem
->Length
-1 || oem
->Buffer
[i
+1] == '.') return FALSE
;
828 if (dot
!= -1) return FALSE
;
832 if (strchr(illegal
, oem
->Buffer
[i
])) return FALSE
;
836 /* check file part is shorter than 8, extension shorter than 3
837 * dot cannot be last in string
841 if (oem
->Length
> 8) return FALSE
;
845 if (dot
> 8 || (oem
->Length
- dot
> 4) || dot
== oem
->Length
- 1) return FALSE
;
847 if (spaces
) *spaces
= got_space
;
851 /******************************************************************
852 * RtlGetCurrentDirectory_U (NTDLL.@)
855 NTSTATUS WINAPI
RtlGetCurrentDirectory_U(ULONG buflen
, LPWSTR buf
)
860 TRACE("(%lu %p)\n", buflen
, buf
);
864 us
= &NtCurrentTeb()->Peb
->ProcessParameters
->CurrentDirectoryName
;
865 len
= us
->Length
/ sizeof(WCHAR
);
866 if (us
->Buffer
[len
- 1] == '\\' && us
->Buffer
[len
- 2] != ':')
869 if (buflen
/ sizeof(WCHAR
) > len
)
871 memcpy(buf
, us
->Buffer
, len
* sizeof(WCHAR
));
881 return len
* sizeof(WCHAR
);
884 /******************************************************************
885 * RtlSetCurrentDirectory_U (NTDLL.@)
888 NTSTATUS WINAPI
RtlSetCurrentDirectory_U(const UNICODE_STRING
* dir
)
890 UNICODE_STRING
* curdir
;
891 NTSTATUS nts
= STATUS_SUCCESS
;
895 TRACE("(%s)\n", debugstr_w(dir
->Buffer
));
899 curdir
= &NtCurrentTeb()->Peb
->ProcessParameters
->CurrentDirectoryName
;
900 size
= curdir
->MaximumLength
;
902 buf
= RtlAllocateHeap(GetProcessHeap(), 0, size
);
905 nts
= STATUS_NO_MEMORY
;
909 size
= RtlGetFullPathName_U(dir
->Buffer
, size
, buf
, 0);
912 nts
= STATUS_OBJECT_NAME_INVALID
;
916 switch (RtlDetermineDosPathNameType_U(buf
))
918 case ABSOLUTE_DRIVE_PATH
:
922 FIXME("Don't support those cases yes\n");
923 nts
= STATUS_NOT_IMPLEMENTED
;
927 /* FIXME: should check that the directory actually exists,
928 * and fill CurrentDirectoryHandle accordingly
931 /* append trailing \ if missing */
932 if (buf
[size
/ sizeof(WCHAR
) - 1] != '\\')
934 buf
[size
/ sizeof(WCHAR
)] = '\\';
935 buf
[size
/ sizeof(WCHAR
) + 1] = '\0';
936 size
+= sizeof(WCHAR
);
939 memmove(curdir
->Buffer
, buf
, size
+ sizeof(WCHAR
));
940 curdir
->Length
= size
;
943 if (curdir
->Buffer
[1] == ':')
949 var
[1] = curdir
->Buffer
[0];
952 env
.Length
= 3 * sizeof(WCHAR
);
953 env
.MaximumLength
= 4 * sizeof(WCHAR
);
956 RtlSetEnvironmentVariable(NULL
, &env
, curdir
);
961 if (buf
) RtlFreeHeap(GetProcessHeap(), 0, buf
);