Fixed a couple of bugs in RtlDosSearchPath_U and RtlGetFullPathName_U.
[wine/wine64.git] / dlls / ntdll / path.c
blobc17f3f91166d997abdff86a8d5b15a58262636b4
1 /*
2 * Ntdll path functions
4 * Copyright 2002, 2003 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
22 #include "config.h"
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
32 #include "ntdll_misc.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(file);
36 static const WCHAR DeviceRootW[] = {'\\','\\','.','\\',0};
37 static const WCHAR NTDosPrefixW[] = {'\\','?','?','\\',0};
38 static const WCHAR UncPfxW[] = {'U','N','C','\\',0};
40 #define IS_SEPARATOR(ch) ((ch) == '\\' || (ch) == '/')
42 /***********************************************************************
43 * RtlDetermineDosPathNameType_U (NTDLL.@)
45 DOS_PATHNAME_TYPE WINAPI RtlDetermineDosPathNameType_U( PCWSTR path )
47 if (IS_SEPARATOR(path[0]))
49 if (!IS_SEPARATOR(path[1])) return ABSOLUTE_PATH; /* "/foo" */
50 if (path[2] != '.') return UNC_PATH; /* "//foo" */
51 if (IS_SEPARATOR(path[3])) return DEVICE_PATH; /* "//./foo" */
52 if (path[3]) return UNC_PATH; /* "//.foo" */
53 return UNC_DOT_PATH; /* "//." */
55 else
57 if (!path[0] || path[1] != ':') return RELATIVE_PATH; /* "foo" */
58 if (IS_SEPARATOR(path[2])) return ABSOLUTE_DRIVE_PATH; /* "c:/foo" */
59 return RELATIVE_DRIVE_PATH; /* "c:foo" */
63 /******************************************************************
64 * RtlDoesFileExists_U
66 * FIXME: should not use CreateFileW
68 BOOLEAN WINAPI RtlDoesFileExists_U(LPCWSTR file_name)
70 HANDLE handle = CreateFileW( file_name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
71 NULL, OPEN_EXISTING, 0, 0 );
72 if (handle == INVALID_HANDLE_VALUE) return FALSE;
73 NtClose( handle );
74 return TRUE;
77 /***********************************************************************
78 * RtlIsDosDeviceName_U (NTDLL.@)
80 * Check if the given DOS path contains a DOS device name.
82 * Returns the length of the device name in the low word and its
83 * position in the high word (both in bytes, not WCHARs), or 0 if no
84 * device name is found.
86 ULONG WINAPI RtlIsDosDeviceName_U( PCWSTR dos_name )
88 static const WCHAR consoleW[] = {'\\','\\','.','\\','C','O','N',0};
89 static const WCHAR auxW[3] = {'A','U','X'};
90 static const WCHAR comW[3] = {'C','O','M'};
91 static const WCHAR conW[3] = {'C','O','N'};
92 static const WCHAR lptW[3] = {'L','P','T'};
93 static const WCHAR nulW[3] = {'N','U','L'};
94 static const WCHAR prnW[3] = {'P','R','N'};
96 const WCHAR *start, *end, *p;
98 switch(RtlDetermineDosPathNameType_U( dos_name ))
100 case INVALID_PATH:
101 case UNC_PATH:
102 return 0;
103 case DEVICE_PATH:
104 if (!strcmpiW( dos_name, consoleW ))
105 return MAKELONG( sizeof(conW), 4 * sizeof(WCHAR) ); /* 4 is length of \\.\ prefix */
106 return 0;
107 default:
108 break;
111 end = dos_name + strlenW(dos_name) - 1;
112 if (end >= dos_name && *end == ':') end--; /* remove trailing ':' */
114 /* find start of file name */
115 for (start = end; start >= dos_name; start--)
117 if (IS_SEPARATOR(start[0])) break;
118 /* check for ':' but ignore if before extension (for things like NUL:.txt) */
119 if (start[0] == ':' && start[1] != '.') break;
121 start++;
123 /* remove extension */
124 if ((p = strchrW( start, '.' )))
126 end = p - 1;
127 if (end >= dos_name && *end == ':') end--; /* remove trailing ':' before extension */
129 else
131 /* no extension, remove trailing spaces */
132 while (end >= dos_name && *end == ' ') end--;
135 /* now we have a potential device name between start and end, check it */
136 switch(end - start + 1)
138 case 3:
139 if (strncmpiW( start, auxW, 3 ) &&
140 strncmpiW( start, conW, 3 ) &&
141 strncmpiW( start, nulW, 3 ) &&
142 strncmpiW( start, prnW, 3 )) break;
143 return MAKELONG( 3 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
144 case 4:
145 if (strncmpiW( start, comW, 3 ) && strncmpiW( start, lptW, 3 )) break;
146 if (*end <= '0' || *end > '9') break;
147 return MAKELONG( 4 * sizeof(WCHAR), (start - dos_name) * sizeof(WCHAR) );
148 default: /* can't match anything */
149 break;
151 return 0;
155 /**************************************************************************
156 * RtlDosPathNameToNtPathName_U [NTDLL.@]
158 * dos_path: a DOS path name (fully qualified or not)
159 * ntpath: pointer to a UNICODE_STRING to hold the converted
160 * path name
161 * file_part:will point (in ntpath) to the file part in the path
162 * cd: directory reference (optional)
164 * FIXME:
165 * + fill the cd structure
167 BOOLEAN WINAPI RtlDosPathNameToNtPathName_U(PWSTR dos_path,
168 PUNICODE_STRING ntpath,
169 PWSTR* file_part,
170 CURDIR* cd)
172 static const WCHAR LongFileNamePfxW[4] = {'\\','\\','?','\\'};
173 ULONG sz, ptr_sz, offset;
174 WCHAR local[MAX_PATH];
175 LPWSTR ptr;
177 TRACE("(%s,%p,%p,%p)\n",
178 debugstr_w(dos_path), ntpath, file_part, cd);
180 if (cd)
182 FIXME("Unsupported parameter\n");
183 memset(cd, 0, sizeof(*cd));
186 if (!dos_path || !*dos_path) return FALSE;
188 if (!memcmp(dos_path, LongFileNamePfxW, sizeof(LongFileNamePfxW)))
190 dos_path += sizeof(LongFileNamePfxW) / sizeof(WCHAR);
191 ptr = NULL;
192 ptr_sz = 0;
194 else
196 ptr = local;
197 ptr_sz = sizeof(local);
199 sz = RtlGetFullPathName_U(dos_path, ptr_sz, ptr, file_part);
200 if (sz == 0) return FALSE;
201 if (sz > ptr_sz)
203 ptr = RtlAllocateHeap(ntdll_get_process_heap(), 0, sz);
204 sz = RtlGetFullPathName_U(dos_path, sz, ptr, file_part);
207 ntpath->MaximumLength = sz + (4 /* unc\ */ + 4 /* \??\ */) * sizeof(WCHAR);
208 ntpath->Buffer = RtlAllocateHeap(ntdll_get_process_heap(), 0, ntpath->MaximumLength);
209 if (!ntpath->Buffer)
211 if (ptr != local) RtlFreeHeap(ntdll_get_process_heap(), 0, ptr);
212 return FALSE;
215 strcpyW(ntpath->Buffer, NTDosPrefixW);
216 offset = 0;
217 switch (RtlDetermineDosPathNameType_U(ptr))
219 case UNC_PATH: /* \\foo */
220 if (ptr[2] != '?')
222 offset = 2;
223 strcatW(ntpath->Buffer, UncPfxW);
225 break;
226 case DEVICE_PATH: /* \\.\foo */
227 offset = 4;
228 break;
229 default: break; /* needed to keep gcc quiet */
232 strcatW(ntpath->Buffer, ptr + offset);
233 ntpath->Length = strlenW(ntpath->Buffer) * sizeof(WCHAR);
235 if (file_part && *file_part)
236 *file_part = ntpath->Buffer + ntpath->Length / sizeof(WCHAR) - strlenW(*file_part);
238 /* FIXME: cd filling */
240 if (ptr != local) RtlFreeHeap(ntdll_get_process_heap(), 0, ptr);
241 return TRUE;
244 /******************************************************************
245 * RtlDosSearchPath_U
247 * Searchs a file of name 'name' into a ';' separated list of paths
248 * (stored in paths)
249 * Doesn't seem to search elsewhere than the paths list
250 * Stores the result in buffer (file_part will point to the position
251 * of the file name in the buffer)
252 * FIXME:
253 * - how long shall the paths be ??? (MAX_PATH or larger with \\?\ constructs ???)
255 ULONG WINAPI RtlDosSearchPath_U(LPCWSTR paths, LPCWSTR search, LPCWSTR ext,
256 ULONG buffer_size, LPWSTR buffer,
257 LPWSTR* file_part)
259 DOS_PATHNAME_TYPE type = RtlDetermineDosPathNameType_U(search);
260 ULONG len = 0;
262 if (type == RELATIVE_PATH)
264 ULONG allocated = 0, needed, filelen;
265 WCHAR *p, *name = NULL;
267 filelen = 1 /* for \ */ + strlenW(search) + 1 /* \0 */;
269 p = strrchrW( search, '.' );
270 if (p && !strchrW( p, '\\' ) && !strchrW( p, '/')) ext = NULL;
271 if (ext != NULL) filelen += strlenW(ext);
273 while (*paths)
275 LPCWSTR ptr;
277 for (needed = 0, ptr = paths; *ptr != 0 && *ptr++ != ';'; needed++);
278 if (needed + filelen > allocated)
280 name = (WCHAR*)RtlReAllocateHeap(ntdll_get_process_heap(), 0,
281 name, (needed + filelen) * sizeof(WCHAR));
282 if (!name) return 0;
283 allocated = needed + filelen;
285 memmove(name, paths, needed * sizeof(WCHAR));
286 /* append '\\' if none is present */
287 if (needed > 0 && name[needed - 1] != '\\') name[needed++] = '\\';
288 strcpyW(&name[needed], search);
289 if (ext) strcatW(&name[needed], ext);
290 if (RtlDoesFileExists_U(name))
292 len = RtlGetFullPathName_U(name, buffer_size, buffer, file_part);
293 break;
295 paths = ptr;
297 RtlFreeHeap(ntdll_get_process_heap(), 0, name);
299 else if (RtlDoesFileExists_U(search))
301 len = RtlGetFullPathName_U(search, buffer_size, buffer, file_part);
304 return len;
307 /******************************************************************
308 * get_full_path_helper
310 * Helper for RtlGetFullPathName_U
312 static ULONG get_full_path_helper(LPCWSTR name, LPWSTR buffer, ULONG size)
314 ULONG reqsize, mark = 0;
315 DOS_PATHNAME_TYPE type;
316 LPWSTR ptr;
317 UNICODE_STRING* cd;
319 reqsize = sizeof(WCHAR); /* '\0' at the end */
321 RtlAcquirePebLock();
322 cd = &ntdll_get_process_pmts()->CurrentDirectoryName;
324 switch (type = RtlDetermineDosPathNameType_U(name))
326 case UNC_PATH: /* \\foo */
327 case DEVICE_PATH: /* \\.\foo */
328 if (reqsize <= size) buffer[0] = '\0';
329 break;
331 case ABSOLUTE_DRIVE_PATH: /* c:\foo */
332 reqsize += sizeof(WCHAR);
333 if (reqsize <= size)
335 buffer[0] = toupperW(name[0]);
336 buffer[1] = '\0';
338 name++;
339 break;
341 case RELATIVE_DRIVE_PATH: /* c:foo */
342 if (toupperW(name[0]) != toupperW(cd->Buffer[0]) || cd->Buffer[1] != ':')
344 WCHAR drive[4];
345 UNICODE_STRING var, val;
347 drive[0] = '=';
348 drive[1] = name[0];
349 drive[2] = ':';
350 drive[3] = '\0';
351 var.Length = 6;
352 var.MaximumLength = 8;
353 var.Buffer = drive;
354 val.Length = 0;
355 val.MaximumLength = size;
356 val.Buffer = buffer;
358 name += 2;
360 switch (RtlQueryEnvironmentVariable_U(NULL, &var, &val))
362 case STATUS_SUCCESS:
363 /* FIXME: Win2k seems to check that the environment variable actually points
364 * to an existing directory. If not, root of the drive is used
365 * (this seems also to be the only spot in RtlGetFullPathName that the
366 * existence of a part of a path is checked)
368 /* fall thru */
369 case STATUS_BUFFER_TOO_SMALL:
370 reqsize += val.Length;
371 /* append trailing \\ */
372 reqsize += sizeof(WCHAR);
373 if (reqsize <= size)
375 buffer[reqsize / sizeof(WCHAR) - 2] = '\\';
376 buffer[reqsize / sizeof(WCHAR) - 1] = '\0';
378 break;
379 case STATUS_VARIABLE_NOT_FOUND:
380 reqsize += 3 * sizeof(WCHAR);
381 if (reqsize <= size)
383 buffer[0] = drive[1];
384 buffer[1] = ':';
385 buffer[2] = '\\';
386 buffer[3] = '\0';
388 break;
389 default:
390 ERR("Unsupported status code\n");
391 break;
393 break;
395 name += 2;
396 /* fall through */
398 case RELATIVE_PATH: /* foo */
399 reqsize += cd->Length;
400 if (reqsize <= size) strcpyW(buffer, cd->Buffer);
401 if (cd->Buffer[1] != ':')
403 ptr = strchrW(cd->Buffer + 2, '\\');
404 if (ptr) ptr = strchrW(ptr + 1, '\\');
405 if (!ptr) ptr = cd->Buffer + strlenW(cd->Buffer);
406 mark = ptr - cd->Buffer;
408 break;
410 case ABSOLUTE_PATH: /* \xxx */
411 if (cd->Buffer[1] == ':')
413 reqsize += 2 * sizeof(WCHAR);
414 if (reqsize <= size)
416 buffer[0] = cd->Buffer[0];
417 buffer[1] = ':';
418 buffer[2] = '\0';
421 else
423 unsigned len;
425 ptr = strchrW(cd->Buffer + 2, '\\');
426 if (ptr) ptr = strchrW(ptr + 1, '\\');
427 if (!ptr) ptr = cd->Buffer + strlenW(cd->Buffer);
428 len = (ptr - cd->Buffer) * sizeof(WCHAR);
429 reqsize += len;
430 mark = len / sizeof(WCHAR);
431 if (reqsize <= size)
433 memcpy(buffer, cd->Buffer, len);
434 buffer[len / sizeof(WCHAR)] = '\0';
436 else
437 buffer[0] = '\0';
439 break;
441 case UNC_DOT_PATH: /* \\. */
442 reqsize += 4 * sizeof(WCHAR);
443 name += 3;
444 if (reqsize <= size)
446 buffer[0] = '\\';
447 buffer[1] = '\\';
448 buffer[2] = '.';
449 buffer[3] = '\\';
450 buffer[4] = '\0';
452 break;
454 case INVALID_PATH:
455 reqsize = 0;
456 goto done;
459 reqsize += strlenW(name) * sizeof(WCHAR);
460 if (reqsize > size) goto done;
462 strcatW(buffer, name);
464 /* convert every / into a \ */
465 for (ptr = buffer; ptr < buffer + size / sizeof(WCHAR); ptr++)
466 if (*ptr == '/') *ptr = '\\';
468 reqsize -= sizeof(WCHAR); /* don't count trailing \0 */
470 /* mark is non NULL for UNC names, so start path collapsing after server & share name
471 * otherwise, it's a fully qualified DOS name, so start after the drive designation
473 for (ptr = buffer + (mark ? mark : 2); ptr < buffer + reqsize / sizeof(WCHAR); )
475 WCHAR* p = strchrW(ptr, '\\');
476 if (!p) break;
478 p++;
479 if (p[0] == '.')
481 switch (p[1])
483 case '.':
484 switch (p[2])
486 case '\\':
488 WCHAR* prev = p - 2;
489 while (prev >= buffer + mark && *prev != '\\') prev--;
490 /* either collapse \foo\.. into \ or \.. into \ */
491 if (prev < buffer + mark) prev = p - 1;
492 reqsize -= (p + 2 - prev) * sizeof(WCHAR);
493 memmove(prev, p + 2, buffer + reqsize - prev + sizeof(WCHAR));
495 break;
496 case '\0':
497 reqsize -= 2 * sizeof(WCHAR);
498 *p = 0;
499 break;
501 break;
502 case '\\':
503 reqsize -= 2 * sizeof(WCHAR);
504 memmove(ptr + 2, ptr, buffer + reqsize - ptr + sizeof(WCHAR));
505 break;
508 ptr = p;
511 done:
512 RtlReleasePebLock();
513 return reqsize;
516 /******************************************************************
517 * RtlGetFullPathName_U (NTDLL.@)
519 * Returns the number of bytes written to buffer (not including the
520 * terminating NULL) if the function succeeds, or the required number of bytes
521 * (including the terminating NULL) if the buffer is to small.
523 * file_part will point to the filename part inside buffer (except if we use
524 * DOS device name, in which case file_in_buf is NULL)
527 DWORD WINAPI RtlGetFullPathName_U(const WCHAR* name, ULONG size, WCHAR* buffer,
528 WCHAR** file_part)
530 DWORD dosdev;
531 DWORD reqsize;
533 TRACE("(%s %lu %p %p)\n", debugstr_w(name), size, buffer, file_part);
535 if (!name || !*name) return 0;
537 if (file_part) *file_part = NULL;
539 /* check for DOS device name */
540 dosdev = RtlIsDosDeviceName_U(name);
541 if (dosdev)
543 DWORD offset = HIWORD(dosdev) / sizeof(WCHAR); /* get it in WCHARs, not bytes */
544 DWORD sz = LOWORD(dosdev); /* in bytes */
546 if (8 + sz + 2 > size) return sz + 10;
547 strcpyW(buffer, DeviceRootW);
548 memmove(buffer + 4, name + offset, sz);
549 buffer[4 + sz / sizeof(WCHAR)] = '\0';
550 /* file_part isn't set in this case */
551 return sz + 8;
554 reqsize = get_full_path_helper(name, buffer, size);
555 if (reqsize > size)
557 LPWSTR tmp = RtlAllocateHeap(ntdll_get_process_heap(), 0, reqsize);
558 reqsize = get_full_path_helper(name, tmp, reqsize) + sizeof(WCHAR);
559 RtlFreeHeap(ntdll_get_process_heap(), 0, tmp);
561 else
563 WCHAR* ptr;
564 /* find file part */
565 if (file_part && (ptr = strrchrW(buffer, '\\')) != NULL && ptr >= buffer + 2 && *++ptr)
566 *file_part = ptr;
568 return reqsize;
571 /*************************************************************************
572 * RtlGetLongestNtPathLength [NTDLL.@]
574 * Get the longest allowed path length
576 * PARAMS
577 * None.
579 * RETURNS
580 * The longest allowed path length (277 characters under Win2k).
582 DWORD WINAPI RtlGetLongestNtPathLength(void)
584 return 277;
587 /******************************************************************
588 * RtlIsNameLegalDOS8Dot3 (NTDLL.@)
590 * Returns TRUE iff unicode is a valid DOS (8+3) name.
591 * If the name is valid, oem gets filled with the corresponding OEM string
592 * spaces is set to TRUE if unicode contains spaces
594 BOOLEAN WINAPI RtlIsNameLegalDOS8Dot3( const UNICODE_STRING *unicode,
595 OEM_STRING *oem, BOOLEAN *spaces )
597 int dot = -1;
598 unsigned int i;
599 char buffer[12];
600 OEM_STRING oem_str;
601 BOOLEAN got_space = FALSE;
603 if (!oem)
605 oem_str.Length = sizeof(buffer);
606 oem_str.MaximumLength = sizeof(buffer);
607 oem_str.Buffer = buffer;
608 oem = &oem_str;
610 if (RtlUpcaseUnicodeStringToCountedOemString( oem, unicode, FALSE ) != STATUS_SUCCESS)
611 return FALSE;
613 if (oem->Length > 12) return FALSE;
615 /* a starting . is invalid, except for . and .. */
616 if (oem->Buffer[0] == '.')
618 if (oem->Length != 1 && (oem->Length != 2 || oem->Buffer[1] != '.')) return FALSE;
619 if (spaces) *spaces = FALSE;
620 return TRUE;
623 for (i = 0; i < oem->Length; i++)
625 switch (oem->Buffer[i])
627 case ' ':
628 /* leading/trailing spaces not allowed */
629 if (!i || i == oem->Length-1 || oem->Buffer[i+1] == '.') return FALSE;
630 got_space = TRUE;
631 break;
632 case '.':
633 if (dot != -1) return FALSE;
634 dot = i;
635 break;
636 default:
637 /* FIXME: check for invalid chars */
638 break;
641 /* check file part is shorter than 8, extension shorter than 3
642 * dot cannot be last in string
644 if (dot == -1)
646 if (oem->Length > 8) return FALSE;
648 else
650 if (dot > 8 || (oem->Length - dot > 4) || dot == oem->Length - 1) return FALSE;
652 if (spaces) *spaces = got_space;
653 return TRUE;
656 /******************************************************************
657 * RtlGetCurrentDirectory_U (NTDLL.@)
660 NTSTATUS WINAPI RtlGetCurrentDirectory_U(ULONG buflen, LPWSTR buf)
662 UNICODE_STRING* us;
663 ULONG len;
665 TRACE("(%lu %p)\n", buflen, buf);
667 RtlAcquirePebLock();
669 us = &ntdll_get_process_pmts()->CurrentDirectoryName;
670 len = us->Length / sizeof(WCHAR);
671 if (us->Buffer[len - 1] == '\\' && us->Buffer[len - 2] != ':')
672 len--;
674 if (buflen / sizeof(WCHAR) > len)
676 memcpy(buf, us->Buffer, len * sizeof(WCHAR));
677 buf[len] = '\0';
679 else
681 len++;
684 RtlReleasePebLock();
686 return len * sizeof(WCHAR);
689 /******************************************************************
690 * RtlSetCurrentDirectory_U (NTDLL.@)
693 NTSTATUS WINAPI RtlSetCurrentDirectory_U(const UNICODE_STRING* dir)
695 UNICODE_STRING* curdir;
696 NTSTATUS nts = STATUS_SUCCESS;
697 ULONG size;
698 PWSTR buf = NULL;
700 TRACE("(%s)\n", debugstr_w(dir->Buffer));
702 RtlAcquirePebLock();
704 curdir = &ntdll_get_process_pmts()->CurrentDirectoryName;
705 size = curdir->MaximumLength;
707 buf = RtlAllocateHeap(ntdll_get_process_heap(), 0, size);
708 if (buf == NULL)
710 nts = STATUS_NO_MEMORY;
711 goto out;
714 size = RtlGetFullPathName_U(dir->Buffer, size, buf, 0);
715 if (!size)
717 nts = STATUS_OBJECT_NAME_INVALID;
718 goto out;
721 switch (RtlDetermineDosPathNameType_U(buf))
723 case ABSOLUTE_DRIVE_PATH:
724 case UNC_PATH:
725 break;
726 default:
727 FIXME("Don't support those cases yes\n");
728 nts = STATUS_NOT_IMPLEMENTED;
729 goto out;
732 /* FIXME: should check that the directory actually exists,
733 * and fill CurrentDirectoryHandle accordingly
736 /* append trailing \ if missing */
737 if (buf[size / sizeof(WCHAR) - 1] != '\\')
739 buf[size / sizeof(WCHAR)] = '\\';
740 buf[size / sizeof(WCHAR) + 1] = '\0';
741 size += sizeof(WCHAR);
744 memmove(curdir->Buffer, buf, size + sizeof(WCHAR));
745 curdir->Length = size;
747 #if 0
748 if (curdir->Buffer[1] == ':')
750 UNICODE_STRING env;
751 WCHAR var[4];
753 var[0] = '=';
754 var[1] = curdir->Buffer[0];
755 var[2] = ':';
756 var[3] = 0;
757 env.Length = 3 * sizeof(WCHAR);
758 env.MaximumLength = 4 * sizeof(WCHAR);
759 env.Buffer = var;
761 RtlSetEnvironmentVariable(NULL, &env, curdir);
763 #endif
765 out:
766 if (buf) RtlFreeHeap(ntdll_get_process_heap(), 0, buf);
768 RtlReleasePebLock();
770 return nts;