2 * msvcrt.dll drive/directory functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
32 #include "wine/unicode.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
38 /* INTERNAL: Translate WIN32_FIND_DATAA to finddata_t */
39 static void msvcrt_fttofd( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata_t* ft)
43 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
46 ft->attrib = fd->dwFileAttributes;
48 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
50 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
52 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
54 ft->size = fd->nFileSizeLow;
55 strcpy(ft->name, fd->cFileName);
58 /* INTERNAL: Translate WIN32_FIND_DATAA to finddata32_t */
59 static void msvcrt_fttofd32( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata32_t* ft)
63 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
66 ft->attrib = fd->dwFileAttributes;
68 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
70 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
72 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
74 ft->size = fd->nFileSizeLow;
75 strcpy(ft->name, fd->cFileName);
78 /* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata_t */
79 static void msvcrt_wfttofd( const WIN32_FIND_DATAW *fd, struct MSVCRT__wfinddata_t* ft)
83 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
86 ft->attrib = fd->dwFileAttributes;
88 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
90 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
92 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
94 ft->size = fd->nFileSizeLow;
95 strcpyW(ft->name, fd->cFileName);
98 /* INTERNAL: Translate WIN32_FIND_DATAA to finddatai64_t */
99 static void msvcrt_fttofdi64( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddatai64_t* ft)
103 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
106 ft->attrib = fd->dwFileAttributes;
108 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
109 ft->time_create = dw;
110 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
111 ft->time_access = dw;
112 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
114 ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
115 strcpy(ft->name, fd->cFileName);
118 /* INTERNAL: Translate WIN32_FIND_DATAA to finddata64_t */
119 static void msvcrt_fttofd64( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata64_t* ft)
123 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
126 ft->attrib = fd->dwFileAttributes;
128 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
129 ft->time_create = dw;
130 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
131 ft->time_access = dw;
132 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
134 ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
135 strcpy(ft->name, fd->cFileName);
138 /* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata64_t */
139 static void msvcrt_wfttofd64( const WIN32_FIND_DATAW *fd, struct MSVCRT__wfinddata64_t* ft)
143 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
146 ft->attrib = fd->dwFileAttributes;
148 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
149 ft->time_create = dw;
150 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
151 ft->time_access = dw;
152 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
154 ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
155 strcpyW(ft->name, fd->cFileName);
158 /* INTERNAL: Translate WIN32_FIND_DATAA to finddata64i32_t */
159 static void msvcrt_fttofd64i32( const WIN32_FIND_DATAA *fd, struct MSVCRT__finddata64i32_t* ft)
163 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
166 ft->attrib = fd->dwFileAttributes;
168 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
169 ft->time_create = dw;
170 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
171 ft->time_access = dw;
172 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
174 ft->size = fd->nFileSizeLow;
175 strcpy(ft->name, fd->cFileName);
178 /* INTERNAL: Translate WIN32_FIND_DATAW to wfinddatai64_t */
179 static void msvcrt_wfttofdi64( const WIN32_FIND_DATAW *fd, struct MSVCRT__wfinddatai64_t* ft)
183 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
186 ft->attrib = fd->dwFileAttributes;
188 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
189 ft->time_create = dw;
190 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
191 ft->time_access = dw;
192 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
194 ft->size = ((__int64)fd->nFileSizeHigh) << 32 | fd->nFileSizeLow;
195 strcpyW(ft->name, fd->cFileName);
198 /* INTERNAL: Translate WIN32_FIND_DATAW to wfinddata64i32_t */
199 static void msvcrt_wfttofd64i32( const WIN32_FIND_DATAW *fd, struct MSVCRT__wfinddata64i32_t* ft)
203 if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
206 ft->attrib = fd->dwFileAttributes;
208 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftCreationTime, &dw );
209 ft->time_create = dw;
210 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
211 ft->time_access = dw;
212 RtlTimeToSecondsSince1970( (const LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
214 ft->size = fd->nFileSizeLow;
215 strcpyW(ft->name, fd->cFileName);
218 /*********************************************************************
221 * Change the current working directory.
224 * newdir [I] Directory to change to
227 * Success: 0. The current working directory is set to newdir.
228 * Failure: -1. errno indicates the error.
231 * See SetCurrentDirectoryA.
233 int CDECL MSVCRT__chdir(const char * newdir)
235 if (!SetCurrentDirectoryA(newdir))
237 msvcrt_set_errno(newdir?GetLastError():0);
243 /*********************************************************************
246 * Unicode version of _chdir.
248 int CDECL MSVCRT__wchdir(const MSVCRT_wchar_t * newdir)
250 if (!SetCurrentDirectoryW(newdir))
252 msvcrt_set_errno(newdir?GetLastError():0);
258 /*********************************************************************
259 * _chdrive (MSVCRT.@)
261 * Change the current drive.
264 * newdrive [I] Drive number to change to (1 = 'A', 2 = 'B', ...)
267 * Success: 0. The current drive is set to newdrive.
268 * Failure: -1. errno indicates the error.
271 * See SetCurrentDirectoryA.
273 int CDECL MSVCRT__chdrive(int newdrive)
275 WCHAR buffer[] = {'A', ':', 0};
277 buffer[0] += newdrive - 1;
278 if (!SetCurrentDirectoryW( buffer ))
280 msvcrt_set_errno(GetLastError());
282 *MSVCRT__errno() = MSVCRT_EACCES;
288 /*********************************************************************
289 * _findclose (MSVCRT.@)
291 * Close a handle returned by _findfirst().
294 * hand [I] Handle to close
297 * Success: 0. All resources associated with hand are freed.
298 * Failure: -1. errno indicates the error.
303 int CDECL MSVCRT__findclose(MSVCRT_intptr_t hand)
305 TRACE(":handle %ld\n",hand);
306 if (!FindClose((HANDLE)hand))
308 msvcrt_set_errno(GetLastError());
314 /*********************************************************************
315 * _findfirst (MSVCRT.@)
317 * Open a handle for iterating through a directory.
320 * fspec [I] File specification of files to iterate.
321 * ft [O] Information for the first file found.
324 * Success: A handle suitable for passing to _findnext() and _findclose().
325 * ft is populated with the details of the found file.
326 * Failure: -1. errno indicates the error.
329 * See FindFirstFileA.
331 MSVCRT_intptr_t CDECL MSVCRT__findfirst(const char * fspec, struct MSVCRT__finddata_t* ft)
333 WIN32_FIND_DATAA find_data;
336 hfind = FindFirstFileA(fspec, &find_data);
337 if (hfind == INVALID_HANDLE_VALUE)
339 msvcrt_set_errno(GetLastError());
342 msvcrt_fttofd(&find_data,ft);
343 TRACE(":got handle %p\n",hfind);
344 return (MSVCRT_intptr_t)hfind;
347 /*********************************************************************
348 * _findfirst32 (MSVCRT.@)
350 MSVCRT_intptr_t CDECL MSVCRT__findfirst32(const char * fspec, struct MSVCRT__finddata32_t* ft)
352 WIN32_FIND_DATAA find_data;
355 hfind = FindFirstFileA(fspec, &find_data);
356 if (hfind == INVALID_HANDLE_VALUE)
358 msvcrt_set_errno(GetLastError());
361 msvcrt_fttofd32(&find_data, ft);
362 TRACE(":got handle %p\n", hfind);
363 return (MSVCRT_intptr_t)hfind;
366 /*********************************************************************
367 * _wfindfirst (MSVCRT.@)
369 * Unicode version of _findfirst.
371 MSVCRT_intptr_t CDECL MSVCRT__wfindfirst(const MSVCRT_wchar_t * fspec, struct MSVCRT__wfinddata_t* ft)
373 WIN32_FIND_DATAW find_data;
376 hfind = FindFirstFileW(fspec, &find_data);
377 if (hfind == INVALID_HANDLE_VALUE)
379 msvcrt_set_errno(GetLastError());
382 msvcrt_wfttofd(&find_data,ft);
383 TRACE(":got handle %p\n",hfind);
384 return (MSVCRT_intptr_t)hfind;
387 /*********************************************************************
388 * _findfirsti64 (MSVCRT.@)
390 * 64-bit version of _findfirst.
392 MSVCRT_intptr_t CDECL MSVCRT__findfirsti64(const char * fspec, struct MSVCRT__finddatai64_t* ft)
394 WIN32_FIND_DATAA find_data;
397 hfind = FindFirstFileA(fspec, &find_data);
398 if (hfind == INVALID_HANDLE_VALUE)
400 msvcrt_set_errno(GetLastError());
403 msvcrt_fttofdi64(&find_data,ft);
404 TRACE(":got handle %p\n",hfind);
405 return (MSVCRT_intptr_t)hfind;
408 /*********************************************************************
409 * _findfirst64 (MSVCRT.@)
411 * 64-bit version of _findfirst.
413 MSVCRT_intptr_t CDECL MSVCRT__findfirst64(const char * fspec, struct MSVCRT__finddata64_t* ft)
415 WIN32_FIND_DATAA find_data;
418 hfind = FindFirstFileA(fspec, &find_data);
419 if (hfind == INVALID_HANDLE_VALUE)
421 msvcrt_set_errno(GetLastError());
424 msvcrt_fttofd64(&find_data,ft);
425 TRACE(":got handle %p\n",hfind);
426 return (MSVCRT_intptr_t)hfind;
429 /*********************************************************************
430 * _wfindfirst64 (MSVCRT.@)
432 * Unicode version of _findfirst64.
434 MSVCRT_intptr_t CDECL MSVCRT__wfindfirst64(const MSVCRT_wchar_t * fspec, struct MSVCRT__wfinddata64_t* ft)
436 WIN32_FIND_DATAW find_data;
439 hfind = FindFirstFileW(fspec, &find_data);
440 if (hfind == INVALID_HANDLE_VALUE)
442 msvcrt_set_errno(GetLastError());
445 msvcrt_wfttofd64(&find_data,ft);
446 TRACE(":got handle %p\n",hfind);
447 return (MSVCRT_intptr_t)hfind;
450 /*********************************************************************
451 * _findfirst64i32 (MSVCRT.@)
453 * 64-bit/32-bit version of _findfirst.
455 MSVCRT_intptr_t CDECL MSVCRT__findfirst64i32(const char * fspec, struct MSVCRT__finddata64i32_t* ft)
457 WIN32_FIND_DATAA find_data;
460 hfind = FindFirstFileA(fspec, &find_data);
461 if (hfind == INVALID_HANDLE_VALUE)
463 msvcrt_set_errno(GetLastError());
466 msvcrt_fttofd64i32(&find_data,ft);
467 TRACE(":got handle %p\n",hfind);
468 return (MSVCRT_intptr_t)hfind;
471 /*********************************************************************
472 * _wfindfirst64i32 (MSVCRT.@)
474 * Unicode version of _findfirst64i32.
476 MSVCRT_intptr_t CDECL MSVCRT__wfindfirst64i32(const MSVCRT_wchar_t * fspec, struct MSVCRT__wfinddata64i32_t* ft)
478 WIN32_FIND_DATAW find_data;
481 hfind = FindFirstFileW(fspec, &find_data);
482 if (hfind == INVALID_HANDLE_VALUE)
484 msvcrt_set_errno(GetLastError());
487 msvcrt_wfttofd64i32(&find_data,ft);
488 TRACE(":got handle %p\n",hfind);
489 return (MSVCRT_intptr_t)hfind;
492 /*********************************************************************
493 * _wfindfirsti64 (MSVCRT.@)
495 * Unicode version of _findfirsti64.
497 MSVCRT_intptr_t CDECL MSVCRT__wfindfirsti64(const MSVCRT_wchar_t * fspec, struct MSVCRT__wfinddatai64_t* ft)
499 WIN32_FIND_DATAW find_data;
502 hfind = FindFirstFileW(fspec, &find_data);
503 if (hfind == INVALID_HANDLE_VALUE)
505 msvcrt_set_errno(GetLastError());
508 msvcrt_wfttofdi64(&find_data,ft);
509 TRACE(":got handle %p\n",hfind);
510 return (MSVCRT_intptr_t)hfind;
513 /*********************************************************************
514 * _findnext (MSVCRT.@)
516 * Find the next file from a file search handle.
519 * hand [I] Handle to the search returned from _findfirst().
520 * ft [O] Information for the file found.
523 * Success: 0. ft is populated with the details of the found file.
524 * Failure: -1. errno indicates the error.
529 int CDECL MSVCRT__findnext(MSVCRT_intptr_t hand, struct MSVCRT__finddata_t * ft)
531 WIN32_FIND_DATAA find_data;
533 if (!FindNextFileA((HANDLE)hand, &find_data))
535 *MSVCRT__errno() = MSVCRT_ENOENT;
539 msvcrt_fttofd(&find_data,ft);
543 /*********************************************************************
544 * _findnext32 (MSVCRT.@)
546 int CDECL MSVCRT__findnext32(MSVCRT_intptr_t hand, struct MSVCRT__finddata32_t * ft)
548 WIN32_FIND_DATAA find_data;
550 if (!FindNextFileA((HANDLE)hand, &find_data))
552 *MSVCRT__errno() = MSVCRT_ENOENT;
556 msvcrt_fttofd32(&find_data, ft);
560 /*********************************************************************
561 * _wfindnext (MSVCRT.@)
563 * Unicode version of _findnext.
565 int CDECL MSVCRT__wfindnext(MSVCRT_intptr_t hand, struct MSVCRT__wfinddata_t * ft)
567 WIN32_FIND_DATAW find_data;
569 if (!FindNextFileW((HANDLE)hand, &find_data))
571 *MSVCRT__errno() = MSVCRT_ENOENT;
575 msvcrt_wfttofd(&find_data,ft);
579 /*********************************************************************
580 * _findnexti64 (MSVCRT.@)
582 * 64-bit version of _findnext.
584 int CDECL MSVCRT__findnexti64(MSVCRT_intptr_t hand, struct MSVCRT__finddatai64_t * ft)
586 WIN32_FIND_DATAA find_data;
588 if (!FindNextFileA((HANDLE)hand, &find_data))
590 *MSVCRT__errno() = MSVCRT_ENOENT;
594 msvcrt_fttofdi64(&find_data,ft);
598 /*********************************************************************
599 * _findnext64 (MSVCRT.@)
601 * 64-bit version of _findnext.
603 int CDECL MSVCRT__findnext64(MSVCRT_intptr_t hand, struct MSVCRT__finddata64_t * ft)
605 WIN32_FIND_DATAA find_data;
607 if (!FindNextFileA((HANDLE)hand, &find_data))
609 *MSVCRT__errno() = MSVCRT_ENOENT;
613 msvcrt_fttofd64(&find_data,ft);
617 /*********************************************************************
618 * _wfindnext64 (MSVCRT.@)
620 * Unicode version of _wfindnext64.
622 int CDECL MSVCRT__wfindnext64(MSVCRT_intptr_t hand, struct MSVCRT__wfinddata64_t * ft)
624 WIN32_FIND_DATAW find_data;
626 if (!FindNextFileW((HANDLE)hand, &find_data))
628 *MSVCRT__errno() = MSVCRT_ENOENT;
632 msvcrt_wfttofd64(&find_data,ft);
636 /*********************************************************************
637 * _findnext64i32 (MSVCRT.@)
639 * 64-bit/32-bit version of _findnext.
641 int CDECL MSVCRT__findnext64i32(MSVCRT_intptr_t hand, struct MSVCRT__finddata64i32_t * ft)
643 WIN32_FIND_DATAA find_data;
645 if (!FindNextFileA((HANDLE)hand, &find_data))
647 *MSVCRT__errno() = MSVCRT_ENOENT;
651 msvcrt_fttofd64i32(&find_data,ft);
655 /*********************************************************************
656 * _wfindnexti64 (MSVCRT.@)
658 * Unicode version of _findnexti64.
660 int CDECL MSVCRT__wfindnexti64(MSVCRT_intptr_t hand, struct MSVCRT__wfinddatai64_t * ft)
662 WIN32_FIND_DATAW find_data;
664 if (!FindNextFileW((HANDLE)hand, &find_data))
666 *MSVCRT__errno() = MSVCRT_ENOENT;
670 msvcrt_wfttofdi64(&find_data,ft);
674 /*********************************************************************
675 * _wfindnext64i32 (MSVCRT.@)
677 * Unicode version of _findnext64i32.
679 int CDECL MSVCRT__wfindnext64i32(MSVCRT_intptr_t hand, struct MSVCRT__wfinddata64i32_t * ft)
681 WIN32_FIND_DATAW find_data;
683 if (!FindNextFileW((HANDLE)hand, &find_data))
685 *MSVCRT__errno() = MSVCRT_ENOENT;
689 msvcrt_wfttofd64i32(&find_data,ft);
693 /*********************************************************************
696 * Get the current working directory.
699 * buf [O] Destination for current working directory.
700 * size [I] Size of buf in characters
703 * Success: If buf is NULL, returns an allocated string containing the path.
704 * Otherwise populates buf with the path and returns it.
705 * Failure: NULL. errno indicates the error.
707 char* CDECL MSVCRT__getcwd(char * buf, int size)
710 int dir_len = GetCurrentDirectoryA(MAX_PATH,dir);
713 return NULL; /* FIXME: Real return value untested */
717 if (size <= dir_len) size = dir_len + 1;
718 if (!(buf = MSVCRT_malloc( size ))) return NULL;
720 else if (dir_len >= size)
722 *MSVCRT__errno() = MSVCRT_ERANGE;
723 return NULL; /* buf too small */
729 /*********************************************************************
730 * _wgetcwd (MSVCRT.@)
732 * Unicode version of _getcwd.
734 MSVCRT_wchar_t* CDECL MSVCRT__wgetcwd(MSVCRT_wchar_t * buf, int size)
736 MSVCRT_wchar_t dir[MAX_PATH];
737 int dir_len = GetCurrentDirectoryW(MAX_PATH,dir);
740 return NULL; /* FIXME: Real return value untested */
744 if (size <= dir_len) size = dir_len + 1;
745 if (!(buf = MSVCRT_malloc( size * sizeof(WCHAR) ))) return NULL;
749 *MSVCRT__errno() = MSVCRT_ERANGE;
750 return NULL; /* buf too small */
756 /*********************************************************************
757 * _getdrive (MSVCRT.@)
759 * Get the current drive number.
765 * Success: The drive letter number from 1 to 26 ("A:" to "Z:").
768 int CDECL MSVCRT__getdrive(void)
770 WCHAR buffer[MAX_PATH];
771 if (GetCurrentDirectoryW( MAX_PATH, buffer ) &&
772 buffer[0] >= 'A' && buffer[0] <= 'z' && buffer[1] == ':')
773 return toupperW(buffer[0]) - 'A' + 1;
777 /*********************************************************************
778 * _getdcwd (MSVCRT.@)
780 * Get the current working directory on a given disk.
783 * drive [I] Drive letter to get the current working directory from.
784 * buf [O] Destination for the current working directory.
785 * size [I] Length of drive in characters.
788 * Success: If drive is NULL, returns an allocated string containing the path.
789 * Otherwise populates drive with the path and returns it.
790 * Failure: NULL. errno indicates the error.
792 char* CDECL MSVCRT__getdcwd(int drive, char * buf, int size)
796 TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
798 if (!drive || drive == MSVCRT__getdrive())
799 return MSVCRT__getcwd(buf,size); /* current */
803 char drivespec[] = {'A', ':', 0};
806 drivespec[0] += drive - 1;
807 if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE)
809 *MSVCRT__errno() = MSVCRT_EACCES;
813 dir_len = GetFullPathNameA(drivespec,MAX_PATH,dir,&dummy);
814 if (dir_len >= size || dir_len < 1)
816 *MSVCRT__errno() = MSVCRT_ERANGE;
817 return NULL; /* buf too small */
820 TRACE(":returning '%s'\n", dir);
822 return MSVCRT__strdup(dir); /* allocate */
829 /*********************************************************************
830 * _wgetdcwd (MSVCRT.@)
832 * Unicode version of _wgetdcwd.
834 MSVCRT_wchar_t* CDECL MSVCRT__wgetdcwd(int drive, MSVCRT_wchar_t * buf, int size)
836 static MSVCRT_wchar_t* dummy;
838 TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
840 if (!drive || drive == MSVCRT__getdrive())
841 return MSVCRT__wgetcwd(buf,size); /* current */
844 MSVCRT_wchar_t dir[MAX_PATH];
845 MSVCRT_wchar_t drivespec[4] = {'A', ':', '\\', 0};
848 drivespec[0] += drive - 1;
849 if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
851 *MSVCRT__errno() = MSVCRT_EACCES;
855 dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
856 if (dir_len >= size || dir_len < 1)
858 *MSVCRT__errno() = MSVCRT_ERANGE;
859 return NULL; /* buf too small */
862 TRACE(":returning %s\n", debugstr_w(dir));
864 return MSVCRT__wcsdup(dir); /* allocate */
870 /*********************************************************************
871 * _getdiskfree (MSVCRT.@)
873 * Get information about the free space on a drive.
876 * disk [I] Drive number to get information about (1 = 'A', 2 = 'B', ...)
877 * info [O] Destination for the resulting information.
880 * Success: 0. info is updated with the free space information.
881 * Failure: An error code from GetLastError().
884 * See GetLastError().
886 unsigned int CDECL MSVCRT__getdiskfree(unsigned int disk, struct MSVCRT__diskfree_t * d)
888 WCHAR drivespec[] = {'@', ':', '\\', 0};
893 return ERROR_INVALID_PARAMETER; /* MSVCRT doesn't set errno here */
895 drivespec[0] += disk; /* make a drive letter */
897 if (GetDiskFreeSpaceW(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
899 d->sectors_per_cluster = ret[0];
900 d->bytes_per_sector = ret[1];
901 d->avail_clusters = ret[2];
902 d->total_clusters = ret[3];
905 err = GetLastError();
906 msvcrt_set_errno(err);
910 /*********************************************************************
913 * Create a directory.
916 * newdir [I] Name of directory to create.
919 * Success: 0. The directory indicated by newdir is created.
920 * Failure: -1. errno indicates the error.
923 * See CreateDirectoryA.
925 int CDECL MSVCRT__mkdir(const char * newdir)
927 if (CreateDirectoryA(newdir,NULL))
929 msvcrt_set_errno(GetLastError());
933 /*********************************************************************
936 * Unicode version of _mkdir.
938 int CDECL MSVCRT__wmkdir(const MSVCRT_wchar_t* newdir)
940 if (CreateDirectoryW(newdir,NULL))
942 msvcrt_set_errno(GetLastError());
946 /*********************************************************************
949 * Delete a directory.
952 * dir [I] Name of directory to delete.
955 * Success: 0. The directory indicated by newdir is deleted.
956 * Failure: -1. errno indicates the error.
959 * See RemoveDirectoryA.
961 int CDECL MSVCRT__rmdir(const char * dir)
963 if (RemoveDirectoryA(dir))
965 msvcrt_set_errno(GetLastError());
969 /*********************************************************************
972 * Unicode version of _rmdir.
974 int CDECL MSVCRT__wrmdir(const MSVCRT_wchar_t * dir)
976 if (RemoveDirectoryW(dir))
978 msvcrt_set_errno(GetLastError());
982 /******************************************************************
983 * _splitpath_s (MSVCRT.@)
985 int CDECL _splitpath_s(const char* inpath,
986 char* drive, MSVCRT_size_t sz_drive,
987 char* dir, MSVCRT_size_t sz_dir,
988 char* fname, MSVCRT_size_t sz_fname,
989 char* ext, MSVCRT_size_t sz_ext)
993 if (!inpath || (!drive && sz_drive) ||
994 (drive && !sz_drive) ||
997 (!fname && sz_fname) ||
998 (fname && !sz_fname) ||
1002 *MSVCRT__errno() = MSVCRT_EINVAL;
1003 return MSVCRT_EINVAL;
1006 if (inpath[0] && inpath[1] == ':')
1010 if (sz_drive <= 2) goto do_error;
1011 drive[0] = inpath[0];
1012 drive[1] = inpath[1];
1017 else if (drive) drive[0] = '\0';
1019 /* look for end of directory part */
1021 for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
1023 if (end) /* got a directory */
1027 if (sz_dir <= end - inpath) goto do_error;
1028 memcpy( dir, inpath, (end - inpath) );
1029 dir[end - inpath] = 0;
1033 else if (dir) dir[0] = 0;
1035 /* look for extension: what's after the last dot */
1037 for (p = inpath; *p; p++) if (*p == '.') end = p;
1039 if (!end) end = p; /* there's no extension */
1043 if (sz_fname <= end - inpath) goto do_error;
1044 memcpy( fname, inpath, (end - inpath) );
1045 fname[end - inpath] = 0;
1049 if (sz_ext <= strlen(end)) goto do_error;
1054 if (drive) drive[0] = '\0';
1055 if (dir) dir[0] = '\0';
1056 if (fname) fname[0]= '\0';
1057 if (ext) ext[0]= '\0';
1058 *MSVCRT__errno() = MSVCRT_ERANGE;
1059 return MSVCRT_ERANGE;
1062 /*********************************************************************
1063 * _splitpath (MSVCRT.@)
1065 void CDECL _splitpath(const char *inpath, char *drv, char *dir,
1066 char *fname, char *ext)
1068 _splitpath_s(inpath, drv, drv?MSVCRT__MAX_DRIVE:0, dir, dir?MSVCRT__MAX_DIR:0,
1069 fname, fname?MSVCRT__MAX_FNAME:0, ext, ext?MSVCRT__MAX_EXT:0);
1072 /******************************************************************
1073 * _wsplitpath_s (MSVCRT.@)
1075 * Secure version of _wsplitpath
1077 int CDECL _wsplitpath_s(const MSVCRT_wchar_t* inpath,
1078 MSVCRT_wchar_t* drive, MSVCRT_size_t sz_drive,
1079 MSVCRT_wchar_t* dir, MSVCRT_size_t sz_dir,
1080 MSVCRT_wchar_t* fname, MSVCRT_size_t sz_fname,
1081 MSVCRT_wchar_t* ext, MSVCRT_size_t sz_ext)
1083 const MSVCRT_wchar_t *p, *end;
1085 if (!inpath || (!drive && sz_drive) ||
1086 (drive && !sz_drive) ||
1089 (!fname && sz_fname) ||
1090 (fname && !sz_fname) ||
1094 *MSVCRT__errno() = MSVCRT_EINVAL;
1095 return MSVCRT_EINVAL;
1098 if (inpath[0] && inpath[1] == ':')
1102 if (sz_drive <= 2) goto do_error;
1103 drive[0] = inpath[0];
1104 drive[1] = inpath[1];
1109 else if (drive) drive[0] = '\0';
1111 /* look for end of directory part */
1113 for (p = inpath; *p; p++) if (*p == '/' || *p == '\\') end = p + 1;
1115 if (end) /* got a directory */
1119 if (sz_dir <= end - inpath) goto do_error;
1120 memcpy( dir, inpath, (end - inpath) * sizeof(MSVCRT_wchar_t) );
1121 dir[end - inpath] = 0;
1125 else if (dir) dir[0] = 0;
1127 /* look for extension: what's after the last dot */
1129 for (p = inpath; *p; p++) if (*p == '.') end = p;
1131 if (!end) end = p; /* there's no extension */
1135 if (sz_fname <= end - inpath) goto do_error;
1136 memcpy( fname, inpath, (end - inpath) * sizeof(MSVCRT_wchar_t) );
1137 fname[end - inpath] = 0;
1141 if (sz_ext <= strlenW(end)) goto do_error;
1142 strcpyW( ext, end );
1146 if (drive) drive[0] = '\0';
1147 if (dir) dir[0] = '\0';
1148 if (fname) fname[0]= '\0';
1149 if (ext) ext[0]= '\0';
1150 *MSVCRT__errno() = MSVCRT_ERANGE;
1151 return MSVCRT_ERANGE;
1154 /*********************************************************************
1155 * _wsplitpath (MSVCRT.@)
1157 * Unicode version of _splitpath.
1159 void CDECL _wsplitpath(const MSVCRT_wchar_t *inpath, MSVCRT_wchar_t *drv, MSVCRT_wchar_t *dir,
1160 MSVCRT_wchar_t *fname, MSVCRT_wchar_t *ext)
1162 _wsplitpath_s(inpath, drv, drv?MSVCRT__MAX_DRIVE:0, dir, dir?MSVCRT__MAX_DIR:0,
1163 fname, fname?MSVCRT__MAX_FNAME:0, ext, ext?MSVCRT__MAX_EXT:0);
1166 /*********************************************************************
1167 * _wfullpath (MSVCRT.@)
1169 * Unicode version of _fullpath.
1171 MSVCRT_wchar_t * CDECL _wfullpath(MSVCRT_wchar_t * absPath, const MSVCRT_wchar_t* relPath, MSVCRT_size_t size)
1176 BOOL alloced = FALSE;
1178 if (!relPath || !*relPath)
1179 return MSVCRT__wgetcwd(absPath, size);
1181 if (absPath == NULL)
1183 buffer = MSVCRT_malloc(MAX_PATH * sizeof(WCHAR));
1192 *MSVCRT__errno() = MSVCRT_ERANGE;
1196 TRACE(":resolving relative path %s\n",debugstr_w(relPath));
1198 rc = GetFullPathNameW(relPath,size,buffer,&lastpart);
1200 if (rc > 0 && rc <= size )
1205 MSVCRT_free(buffer);
1210 /*********************************************************************
1211 * _fullpath (MSVCRT.@)
1213 * Create an absolute path from a relative path.
1216 * absPath [O] Destination for absolute path
1217 * relPath [I] Relative path to convert to absolute
1218 * size [I] Length of absPath in characters.
1221 * Success: If absPath is NULL, returns an allocated string containing the path.
1222 * Otherwise populates absPath with the path and returns it.
1223 * Failure: NULL. errno indicates the error.
1225 char * CDECL _fullpath(char * absPath, const char* relPath, unsigned int size)
1230 BOOL alloced = FALSE;
1232 if (!relPath || !*relPath)
1233 return MSVCRT__getcwd(absPath, size);
1235 if (absPath == NULL)
1237 buffer = MSVCRT_malloc(MAX_PATH);
1246 *MSVCRT__errno() = MSVCRT_ERANGE;
1250 TRACE(":resolving relative path '%s'\n",relPath);
1252 rc = GetFullPathNameA(relPath,size,buffer,&lastpart);
1254 if (rc > 0 && rc <= size)
1259 MSVCRT_free(buffer);
1264 /*********************************************************************
1265 * _makepath (MSVCRT.@)
1267 * Create a pathname.
1270 * path [O] Destination for created pathname
1271 * drive [I] Drive letter (e.g. "A:")
1272 * directory [I] Directory
1273 * filename [I] Name of the file, excluding extension
1274 * extension [I] File extension (e.g. ".TXT")
1277 * Nothing. If path is not large enough to hold the resulting pathname,
1278 * random process memory will be overwritten.
1280 VOID CDECL _makepath(char * path, const char * drive,
1281 const char *directory, const char * filename,
1282 const char * extension)
1286 TRACE("(%s %s %s %s)\n", debugstr_a(drive), debugstr_a(directory),
1287 debugstr_a(filename), debugstr_a(extension) );
1292 if (drive && drive[0])
1297 if (directory && directory[0])
1299 unsigned int len = strlen(directory);
1300 memmove(p, directory, len);
1302 if (p[-1] != '/' && p[-1] != '\\')
1305 if (filename && filename[0])
1307 unsigned int len = strlen(filename);
1308 memmove(p, filename, len);
1311 if (extension && extension[0])
1313 if (extension[0] != '.')
1315 strcpy(p, extension);
1319 TRACE("returning %s\n",path);
1322 /*********************************************************************
1323 * _wmakepath (MSVCRT.@)
1325 * Unicode version of _wmakepath.
1327 VOID CDECL _wmakepath(MSVCRT_wchar_t *path, const MSVCRT_wchar_t *drive, const MSVCRT_wchar_t *directory,
1328 const MSVCRT_wchar_t *filename, const MSVCRT_wchar_t *extension)
1330 MSVCRT_wchar_t *p = path;
1332 TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory),
1333 debugstr_w(filename), debugstr_w(extension));
1338 if (drive && drive[0])
1343 if (directory && directory[0])
1345 unsigned int len = strlenW(directory);
1346 memmove(p, directory, len * sizeof(MSVCRT_wchar_t));
1348 if (p[-1] != '/' && p[-1] != '\\')
1351 if (filename && filename[0])
1353 unsigned int len = strlenW(filename);
1354 memmove(p, filename, len * sizeof(MSVCRT_wchar_t));
1357 if (extension && extension[0])
1359 if (extension[0] != '.')
1361 strcpyW(p, extension);
1366 TRACE("returning %s\n", debugstr_w(path));
1369 /*********************************************************************
1370 * _makepath_s (MSVCRT.@)
1372 * Safe version of _makepath.
1374 int CDECL _makepath_s(char *path, MSVCRT_size_t size, const char *drive,
1375 const char *directory, const char *filename,
1376 const char *extension)
1382 *MSVCRT__errno() = MSVCRT_EINVAL;
1383 return MSVCRT_EINVAL;
1386 if (drive && drive[0])
1396 if (directory && directory[0])
1398 unsigned int len = strlen(directory);
1399 unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
1400 unsigned int copylen = min(size - 1, len);
1405 memmove(p, directory, copylen);
1413 if (needs_separator)
1423 if (filename && filename[0])
1425 unsigned int len = strlen(filename);
1426 unsigned int copylen = min(size - 1, len);
1431 memmove(p, filename, copylen);
1440 if (extension && extension[0])
1442 unsigned int len = strlen(extension);
1443 unsigned int needs_period = extension[0] != '.';
1444 unsigned int copylen;
1455 copylen = min(size - 1, len);
1456 memcpy(p, extension, copylen);
1469 *MSVCRT__errno() = MSVCRT_ERANGE;
1470 return MSVCRT_ERANGE;
1473 /*********************************************************************
1474 * _wmakepath_s (MSVCRT.@)
1476 * Safe version of _wmakepath.
1478 int CDECL _wmakepath_s(MSVCRT_wchar_t *path, MSVCRT_size_t size, const MSVCRT_wchar_t *drive,
1479 const MSVCRT_wchar_t *directory, const MSVCRT_wchar_t *filename,
1480 const MSVCRT_wchar_t *extension)
1482 MSVCRT_wchar_t *p = path;
1486 *MSVCRT__errno() = MSVCRT_EINVAL;
1487 return MSVCRT_EINVAL;
1490 if (drive && drive[0])
1500 if (directory && directory[0])
1502 unsigned int len = strlenW(directory);
1503 unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
1504 unsigned int copylen = min(size - 1, len);
1509 memmove(p, directory, copylen * sizeof(MSVCRT_wchar_t));
1517 if (needs_separator)
1527 if (filename && filename[0])
1529 unsigned int len = strlenW(filename);
1530 unsigned int copylen = min(size - 1, len);
1535 memmove(p, filename, copylen * sizeof(MSVCRT_wchar_t));
1544 if (extension && extension[0])
1546 unsigned int len = strlenW(extension);
1547 unsigned int needs_period = extension[0] != '.';
1548 unsigned int copylen;
1559 copylen = min(size - 1, len);
1560 memcpy(p, extension, copylen * sizeof(MSVCRT_wchar_t));
1573 *MSVCRT__errno() = MSVCRT_ERANGE;
1574 return MSVCRT_ERANGE;
1577 /*********************************************************************
1578 * _searchenv (MSVCRT.@)
1580 * Search for a file in a list of paths from an environment variable.
1583 * file [I] Name of the file to search for.
1584 * env [I] Name of the environment variable containing a list of paths.
1585 * buf [O] Destination for the found file path.
1588 * Nothing. If the file is not found, buf will contain an empty string
1591 void CDECL MSVCRT__searchenv(const char* file, const char* env, char *buf)
1594 char curPath[MAX_PATH];
1599 if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
1601 GetFullPathNameA( file, MAX_PATH, buf, NULL );
1602 /* Sigh. This error is *always* set, regardless of success */
1603 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1607 /* Search given environment variable */
1608 envVal = MSVCRT_getenv(env);
1611 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1616 TRACE(":searching for %s in paths %s\n", file, envVal);
1622 while(*end && *end != ';') end++; /* Find end of next path */
1623 if (penv == end || !*penv)
1625 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1628 memcpy(curPath, penv, end - penv);
1629 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
1631 curPath[end - penv] = '\\';
1632 curPath[end - penv + 1] = '\0';
1635 curPath[end - penv] = '\0';
1637 strcat(curPath, file);
1638 TRACE("Checking for file %s\n", curPath);
1639 if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES)
1641 strcpy(buf, curPath);
1642 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1645 penv = *end ? end + 1 : end;
1649 /*********************************************************************
1650 * _searchenv_s (MSVCRT.@)
1652 int CDECL _searchenv_s(const char* file, const char* env, char *buf, MSVCRT_size_t count)
1655 char curPath[MAX_PATH];
1657 if (!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_EINVAL;
1658 if (!MSVCRT_CHECK_PMT(buf != NULL)) return MSVCRT_EINVAL;
1659 if (!MSVCRT_CHECK_PMT(count > 0)) return MSVCRT_EINVAL;
1664 if (GetFileAttributesA( file ) != INVALID_FILE_ATTRIBUTES)
1666 if (GetFullPathNameA( file, count, buf, NULL )) return 0;
1667 msvcrt_set_errno(GetLastError());
1671 /* Search given environment variable */
1672 envVal = MSVCRT_getenv(env);
1675 *MSVCRT__errno() = MSVCRT_ENOENT;
1676 return MSVCRT_ENOENT;
1680 TRACE(":searching for %s in paths %s\n", file, envVal);
1686 while(*end && *end != ';') end++; /* Find end of next path */
1687 if (penv == end || !*penv)
1689 *MSVCRT__errno() = MSVCRT_ENOENT;
1690 return MSVCRT_ENOENT;
1692 memcpy(curPath, penv, end - penv);
1693 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
1695 curPath[end - penv] = '\\';
1696 curPath[end - penv + 1] = '\0';
1699 curPath[end - penv] = '\0';
1701 strcat(curPath, file);
1702 TRACE("Checking for file %s\n", curPath);
1703 if (GetFileAttributesA( curPath ) != INVALID_FILE_ATTRIBUTES)
1705 if (strlen(curPath) + 1 > count)
1707 MSVCRT_INVALID_PMT("buf[count] is too small", MSVCRT_ERANGE);
1708 return MSVCRT_ERANGE;
1710 strcpy(buf, curPath);
1713 penv = *end ? end + 1 : end;
1717 /*********************************************************************
1718 * _wsearchenv (MSVCRT.@)
1720 * Unicode version of _searchenv
1722 void CDECL MSVCRT__wsearchenv(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env, MSVCRT_wchar_t *buf)
1724 MSVCRT_wchar_t *envVal, *penv;
1725 MSVCRT_wchar_t curPath[MAX_PATH];
1730 if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
1732 GetFullPathNameW( file, MAX_PATH, buf, NULL );
1733 /* Sigh. This error is *always* set, regardless of success */
1734 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1738 /* Search given environment variable */
1739 envVal = MSVCRT__wgetenv(env);
1742 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1747 TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal));
1751 MSVCRT_wchar_t *end = penv;
1753 while(*end && *end != ';') end++; /* Find end of next path */
1754 if (penv == end || !*penv)
1756 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1759 memcpy(curPath, penv, (end - penv) * sizeof(MSVCRT_wchar_t));
1760 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
1762 curPath[end - penv] = '\\';
1763 curPath[end - penv + 1] = '\0';
1766 curPath[end - penv] = '\0';
1768 strcatW(curPath, file);
1769 TRACE("Checking for file %s\n", debugstr_w(curPath));
1770 if (GetFileAttributesW( curPath ) != INVALID_FILE_ATTRIBUTES)
1772 strcpyW(buf, curPath);
1773 msvcrt_set_errno(ERROR_FILE_NOT_FOUND);
1776 penv = *end ? end + 1 : end;
1780 /*********************************************************************
1781 * _wsearchenv_s (MSVCRT.@)
1783 int CDECL _wsearchenv_s(const MSVCRT_wchar_t* file, const MSVCRT_wchar_t* env,
1784 MSVCRT_wchar_t *buf, MSVCRT_size_t count)
1786 MSVCRT_wchar_t* envVal, *penv;
1787 MSVCRT_wchar_t curPath[MAX_PATH];
1789 if (!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_EINVAL;
1790 if (!MSVCRT_CHECK_PMT(buf != NULL)) return MSVCRT_EINVAL;
1791 if (!MSVCRT_CHECK_PMT(count > 0)) return MSVCRT_EINVAL;
1796 if (GetFileAttributesW( file ) != INVALID_FILE_ATTRIBUTES)
1798 if (GetFullPathNameW( file, count, buf, NULL )) return 0;
1799 msvcrt_set_errno(GetLastError());
1803 /* Search given environment variable */
1804 envVal = MSVCRT__wgetenv(env);
1807 *MSVCRT__errno() = MSVCRT_ENOENT;
1808 return MSVCRT_ENOENT;
1812 TRACE(":searching for %s in paths %s\n", debugstr_w(file), debugstr_w(envVal));
1816 MSVCRT_wchar_t *end = penv;
1818 while(*end && *end != ';') end++; /* Find end of next path */
1819 if (penv == end || !*penv)
1821 *MSVCRT__errno() = MSVCRT_ENOENT;
1822 return MSVCRT_ENOENT;
1824 memcpy(curPath, penv, (end - penv) * sizeof(MSVCRT_wchar_t));
1825 if (curPath[end - penv] != '/' && curPath[end - penv] != '\\')
1827 curPath[end - penv] = '\\';
1828 curPath[end - penv + 1] = '\0';
1831 curPath[end - penv] = '\0';
1833 strcatW(curPath, file);
1834 TRACE("Checking for file %s\n", debugstr_w(curPath));
1835 if (GetFileAttributesW( curPath ) != INVALID_FILE_ATTRIBUTES)
1837 if (strlenW(curPath) + 1 > count)
1839 MSVCRT_INVALID_PMT("buf[count] is too small", MSVCRT_ERANGE);
1840 return MSVCRT_ERANGE;
1842 strcpyW(buf, curPath);
1845 penv = *end ? end + 1 : end;