Moved ts_xlib.c into x11drv and removed libwine_tsx11.
[wine] / dlls / msvcrt / dir.c
1 /*
2  * msvcrt.dll drive/directory functions
3  *
4  * Copyright 1996,1998 Marcus Meissner
5  * Copyright 1996 Jukka Iivonen
6  * Copyright 1997,2000 Uwe Bonnes
7  * Copyright 2000 Jon Griffiths
8  *
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.
13  *
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.
18  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <time.h>
28 #include "winternl.h"
29 #include "wine/unicode.h"
30 #include "msvcrt.h"
31 #include "msvcrt/errno.h"
32
33 #include "wine/unicode.h"
34 #include "msvcrt/direct.h"
35 #include "msvcrt/dos.h"
36 #include "msvcrt/io.h"
37 #include "msvcrt/stdlib.h"
38 #include "msvcrt/string.h"
39
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
43
44 /* INTERNAL: Translate finddata_t to PWIN32_FIND_DATAA */
45 static void msvcrt_fttofd(LPWIN32_FIND_DATAA fd, struct _finddata_t* ft)
46 {
47   DWORD dw;
48
49   if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
50     ft->attrib = 0;
51   else
52     ft->attrib = fd->dwFileAttributes;
53
54   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftCreationTime, &dw );
55   ft->time_create = dw;
56   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
57   ft->time_access = dw;
58   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
59   ft->time_write = dw;
60   ft->size = fd->nFileSizeLow;
61   strcpy(ft->name, fd->cFileName);
62 }
63
64 /* INTERNAL: Translate wfinddata_t to PWIN32_FIND_DATAA */
65 static void msvcrt_wfttofd(LPWIN32_FIND_DATAW fd, struct _wfinddata_t* ft)
66 {
67   DWORD dw;
68
69   if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
70     ft->attrib = 0;
71   else
72     ft->attrib = fd->dwFileAttributes;
73
74   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftCreationTime, &dw );
75   ft->time_create = dw;
76   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastAccessTime, &dw );
77   ft->time_access = dw;
78   RtlTimeToSecondsSince1970( (LARGE_INTEGER *)&fd->ftLastWriteTime, &dw );
79   ft->time_write = dw;
80   ft->size = fd->nFileSizeLow;
81   strcpyW(ft->name, fd->cFileName);
82 }
83
84 /*********************************************************************
85  *              _chdir (MSVCRT.@)
86  */
87 int _chdir(const char * newdir)
88 {
89   if (!SetCurrentDirectoryA(newdir))
90   {
91     MSVCRT__set_errno(newdir?GetLastError():0);
92     return -1;
93   }
94   return 0;
95 }
96
97 /*********************************************************************
98  *              _wchdir (MSVCRT.@)
99  */
100 int _wchdir(const WCHAR * newdir)
101 {
102   if (!SetCurrentDirectoryW(newdir))
103   {
104     MSVCRT__set_errno(newdir?GetLastError():0);
105     return -1;
106   }
107   return 0;
108 }
109
110 /*********************************************************************
111  *              _chdrive (MSVCRT.@)
112  */
113 int _chdrive(int newdrive)
114 {
115   char buffer[3] = "A:";
116   buffer[0] += newdrive - 1;
117   if (!SetCurrentDirectoryA( buffer ))
118   {
119     MSVCRT__set_errno(GetLastError());
120     if (newdrive <= 0)
121       *MSVCRT__errno() = MSVCRT_EACCES;
122     return -1;
123   }
124   return 0;
125 }
126
127 /*********************************************************************
128  *              _findclose (MSVCRT.@)
129  */
130 int _findclose(long hand)
131 {
132   TRACE(":handle %ld\n",hand);
133   if (!FindClose((HANDLE)hand))
134   {
135     MSVCRT__set_errno(GetLastError());
136     return -1;
137   }
138   return 0;
139 }
140
141 /*********************************************************************
142  *              _findfirst (MSVCRT.@)
143  */
144 long _findfirst(const char * fspec, struct _finddata_t* ft)
145 {
146   WIN32_FIND_DATAA find_data;
147   HANDLE hfind;
148
149   hfind  = FindFirstFileA(fspec, &find_data);
150   if (hfind == INVALID_HANDLE_VALUE)
151   {
152     MSVCRT__set_errno(GetLastError());
153     return -1;
154   }
155   msvcrt_fttofd(&find_data,ft);
156   TRACE(":got handle %d\n",hfind);
157   return hfind;
158 }
159
160 /*********************************************************************
161  *              _wfindfirst (MSVCRT.@)
162  */
163 long _wfindfirst(const WCHAR * fspec, struct _wfinddata_t* ft)
164 {
165   WIN32_FIND_DATAW find_data;
166   HANDLE hfind;
167
168   hfind  = FindFirstFileW(fspec, &find_data);
169   if (hfind == INVALID_HANDLE_VALUE)
170   {
171     MSVCRT__set_errno(GetLastError());
172     return -1;
173   }
174   msvcrt_wfttofd(&find_data,ft);
175   TRACE(":got handle %d\n",hfind);
176   return hfind;
177 }
178
179 /*********************************************************************
180  *              _findnext (MSVCRT.@)
181  */
182 int _findnext(long hand, struct _finddata_t * ft)
183 {
184   WIN32_FIND_DATAA find_data;
185
186   if (!FindNextFileA(hand, &find_data))
187   {
188     *MSVCRT__errno() = MSVCRT_ENOENT;
189     return -1;
190   }
191
192   msvcrt_fttofd(&find_data,ft);
193   return 0;
194 }
195
196 /*********************************************************************
197  *              _wfindnext (MSVCRT.@)
198  */
199 int _wfindnext(long hand, struct _wfinddata_t * ft)
200 {
201   WIN32_FIND_DATAW find_data;
202
203   if (!FindNextFileW(hand, &find_data))
204   {
205     *MSVCRT__errno() = MSVCRT_ENOENT;
206     return -1;
207   }
208
209   msvcrt_wfttofd(&find_data,ft);
210   return 0;
211 }
212
213 /*********************************************************************
214  *              _getcwd (MSVCRT.@)
215  */
216 char* _getcwd(char * buf, int size)
217 {
218   char dir[MAX_PATH];
219   int dir_len = GetCurrentDirectoryA(MAX_PATH,dir);
220
221   if (dir_len < 1)
222     return NULL; /* FIXME: Real return value untested */
223
224   if (!buf)
225   {
226     if (size < 0)
227       return _strdup(dir);
228     return msvcrt_strndup(dir,size);
229   }
230   if (dir_len >= size)
231   {
232     *MSVCRT__errno() = MSVCRT_ERANGE;
233     return NULL; /* buf too small */
234   }
235   strcpy(buf,dir);
236   return buf;
237 }
238
239 /*********************************************************************
240  *              _wgetcwd (MSVCRT.@)
241  */
242 WCHAR* _wgetcwd(WCHAR * buf, int size)
243 {
244   WCHAR dir[MAX_PATH];
245   int dir_len = GetCurrentDirectoryW(MAX_PATH,dir);
246
247   if (dir_len < 1)
248     return NULL; /* FIXME: Real return value untested */
249
250   if (!buf)
251   {
252     if (size < 0)
253       return _wcsdup(dir);
254     return msvcrt_wstrndup(dir,size);
255   }
256   if (dir_len >= size)
257   {
258     *MSVCRT__errno() = MSVCRT_ERANGE;
259     return NULL; /* buf too small */
260   }
261   strcpyW(buf,dir);
262   return buf;
263 }
264
265 /*********************************************************************
266  *              _getdrive (MSVCRT.@)
267  */
268 int _getdrive(void)
269 {
270     char buffer[MAX_PATH];
271     if (!GetCurrentDirectoryA( sizeof(buffer), buffer )) return 0;
272     if (buffer[1] != ':') return 0;
273     return toupper(buffer[0]) - 'A' + 1;
274 }
275
276 /*********************************************************************
277  *              _getdcwd (MSVCRT.@)
278  */
279 char* _getdcwd(int drive, char * buf, int size)
280 {
281   static char* dummy;
282
283   TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
284
285   if (!drive || drive == _getdrive())
286     return _getcwd(buf,size); /* current */
287   else
288   {
289     char dir[MAX_PATH];
290     char drivespec[4] = {'A', ':', '\\', 0};
291     int dir_len;
292
293     drivespec[0] += drive - 1;
294     if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE)
295     {
296       *MSVCRT__errno() = MSVCRT_EACCES;
297       return NULL;
298     }
299
300     dir_len = GetFullPathNameA(drivespec,MAX_PATH,dir,&dummy);
301     if (dir_len >= size || dir_len < 1)
302     {
303       *MSVCRT__errno() = MSVCRT_ERANGE;
304       return NULL; /* buf too small */
305     }
306
307     TRACE(":returning '%s'\n", dir);
308     if (!buf)
309       return _strdup(dir); /* allocate */
310
311     strcpy(buf,dir);
312   }
313   return buf;
314 }
315
316 /*********************************************************************
317  *              _wgetdcwd (MSVCRT.@)
318  */
319 WCHAR* _wgetdcwd(int drive, WCHAR * buf, int size)
320 {
321   static WCHAR* dummy;
322
323   TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
324
325   if (!drive || drive == _getdrive())
326     return _wgetcwd(buf,size); /* current */
327   else
328   {
329     WCHAR dir[MAX_PATH];
330     WCHAR drivespec[4] = {'A', ':', '\\', 0};
331     int dir_len;
332
333     drivespec[0] += drive - 1;
334     if (GetDriveTypeW(drivespec) < DRIVE_REMOVABLE)
335     {
336       *MSVCRT__errno() = MSVCRT_EACCES;
337       return NULL;
338     }
339
340     dir_len = GetFullPathNameW(drivespec,MAX_PATH,dir,&dummy);
341     if (dir_len >= size || dir_len < 1)
342     {
343       *MSVCRT__errno() = MSVCRT_ERANGE;
344       return NULL; /* buf too small */
345     }
346
347     TRACE(":returning %s\n", debugstr_w(dir));
348     if (!buf)
349       return _wcsdup(dir); /* allocate */
350     strcpyW(buf,dir);
351   }
352   return buf;
353 }
354
355 /*********************************************************************
356  *              _getdiskfree (MSVCRT.@)
357  */
358 unsigned int _getdiskfree(unsigned int disk, struct _diskfree_t* d)
359 {
360   char drivespec[4] = {'@', ':', '\\', 0};
361   DWORD ret[4];
362   unsigned int err;
363
364   if (disk > 26)
365     return ERROR_INVALID_PARAMETER; /* MSVCRT doesn't set errno here */
366
367   drivespec[0] += disk; /* make a drive letter */
368
369   if (GetDiskFreeSpaceA(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
370   {
371     d->sectors_per_cluster = (unsigned)ret[0];
372     d->bytes_per_sector = (unsigned)ret[1];
373     d->avail_clusters = (unsigned)ret[2];
374     d->total_clusters = (unsigned)ret[3];
375     return 0;
376   }
377   err = GetLastError();
378   MSVCRT__set_errno(err);
379   return err;
380 }
381
382 /*********************************************************************
383  *              _mkdir (MSVCRT.@)
384  */
385 int _mkdir(const char * newdir)
386 {
387   if (CreateDirectoryA(newdir,NULL))
388     return 0;
389   MSVCRT__set_errno(GetLastError());
390   return -1;
391 }
392
393 /*********************************************************************
394  *              _wmkdir (MSVCRT.@)
395  */
396 int _wmkdir(const WCHAR* newdir)
397 {
398   if (CreateDirectoryW(newdir,NULL))
399     return 0;
400   MSVCRT__set_errno(GetLastError());
401   return -1;
402 }
403
404 /*********************************************************************
405  *              _rmdir (MSVCRT.@)
406  */
407 int _rmdir(const char * dir)
408 {
409   if (RemoveDirectoryA(dir))
410     return 0;
411   MSVCRT__set_errno(GetLastError());
412   return -1;
413 }
414
415 /*********************************************************************
416  *              _wrmdir (MSVCRT.@)
417  */
418 int _wrmdir(const WCHAR * dir)
419 {
420   if (RemoveDirectoryW(dir))
421     return 0;
422   MSVCRT__set_errno(GetLastError());
423   return -1;
424 }
425
426 /*********************************************************************
427  *              _wsplitpath (MSVCRT.@)
428  */
429 void _wsplitpath(const WCHAR *inpath, WCHAR *drv, WCHAR *dir,
430                                 WCHAR *fname, WCHAR *ext )
431 {
432   /* Modified PD code from 'snippets' collection. */
433   WCHAR ch, *ptr, *p;
434   WCHAR pathbuff[MAX_PATH],*path=pathbuff;
435
436   TRACE(":splitting path %s\n",debugstr_w(path));
437   /* FIXME: Should be an strncpyW or something */
438   strcpyW(pathbuff, inpath);
439
440   /* convert slashes to backslashes for searching */
441   for (ptr = (WCHAR*)path; *ptr; ++ptr)
442     if (*ptr == (WCHAR)L'/')
443       *ptr = (WCHAR)L'\\';
444
445   /* look for drive spec */
446   if ((ptr = strchrW(path, (WCHAR)L':')) != (WCHAR)L'\0')
447   {
448     ++ptr;
449     if (drv)
450     {
451       strncpyW(drv, path, ptr - path);
452       drv[ptr - path] = (WCHAR)L'\0';
453     }
454     path = ptr;
455   }
456   else if (drv)
457     *drv = (WCHAR)L'\0';
458
459   /* find rightmost backslash or leftmost colon */
460   if ((ptr = strrchrW(path, (WCHAR)L'\\')) == NULL)
461     ptr = (strchrW(path, (WCHAR)L':'));
462
463   if (!ptr)
464   {
465     ptr = (WCHAR *)path; /* no path */
466     if (dir)
467       *dir = (WCHAR)L'\0';
468   }
469   else
470   {
471     ++ptr; /* skip the delimiter */
472     if (dir)
473     {
474       ch = *ptr;
475       *ptr = (WCHAR)L'\0';
476       strcpyW(dir, path);
477       *ptr = ch;
478     }
479   }
480
481   if ((p = strrchrW(ptr, (WCHAR)L'.')) == NULL)
482   {
483     if (fname)
484       strcpyW(fname, ptr);
485     if (ext)
486       *ext = (WCHAR)L'\0';
487   }
488   else
489   {
490     *p = (WCHAR)L'\0';
491     if (fname)
492       strcpyW(fname, ptr);
493     *p = (WCHAR)L'.';
494     if (ext)
495       strcpyW(ext, p);
496   }
497
498   /* Fix pathological case - Win returns ':' as part of the
499    * directory when no drive letter is given.
500    */
501   if (drv && drv[0] == (WCHAR)L':')
502   {
503     *drv = (WCHAR)L'\0';
504     if (dir)
505     {
506       pathbuff[0] = (WCHAR)L':';
507       pathbuff[1] = (WCHAR)L'\0';
508       strcatW(pathbuff,dir);
509       strcpyW(dir, pathbuff);
510     }
511   }
512 }
513
514 /* INTERNAL: Helper for _fullpath. Modified PD code from 'snippets'. */
515 static void msvcrt_fln_fix(char *path)
516 {
517   int dir_flag = 0, root_flag = 0;
518   char *r, *p, *q, *s;
519
520   /* Skip drive */
521   if (NULL == (r = strrchr(path, ':')))
522     r = path;
523   else
524     ++r;
525
526   /* Ignore leading slashes */
527   while ('\\' == *r)
528     if ('\\' == r[1])
529       strcpy(r, &r[1]);
530     else
531     {
532       root_flag = 1;
533       ++r;
534     }
535
536   p = r; /* Change "\\" to "\" */
537   while (NULL != (p = strchr(p, '\\')))
538     if ('\\' ==  p[1])
539       strcpy(p, &p[1]);
540     else
541       ++p;
542
543   while ('.' == *r) /* Scrunch leading ".\" */
544   {
545     if ('.' == r[1])
546     {
547       /* Ignore leading ".." */
548       for (p = (r += 2); *p && (*p != '\\'); ++p)
549         ;
550     }
551     else
552     {
553       for (p = r + 1 ;*p && (*p != '\\'); ++p)
554         ;
555     }
556     strcpy(r, p + ((*p) ? 1 : 0));
557   }
558
559   while ('\\' == path[strlen(path)-1])   /* Strip last '\\' */
560   {
561     dir_flag = 1;
562     path[strlen(path)-1] = '\0';
563   }
564
565   s = r;
566
567   /* Look for "\." in path */
568
569   while (NULL != (p = strstr(s, "\\.")))
570   {
571     if ('.' == p[2])
572     {
573       /* Execute this section if ".." found */
574       q = p - 1;
575       while (q > r)           /* Backup one level           */
576       {
577         if (*q == '\\')
578           break;
579         --q;
580       }
581       if (q > r)
582       {
583         strcpy(q, p + 3);
584         s = q;
585       }
586       else if ('.' != *q)
587       {
588         strcpy(q + ((*q == '\\') ? 1 : 0),
589                p + 3 + ((*(p + 3)) ? 1 : 0));
590         s = q;
591       }
592       else  s = ++p;
593     }
594     else
595     {
596       /* Execute this section if "." found */
597       q = p + 2;
598       for ( ;*q && (*q != '\\'); ++q)
599         ;
600       strcpy (p, q);
601     }
602   }
603
604   if (root_flag)  /* Embedded ".." could have bubbled up to root  */
605   {
606     for (p = r; *p && ('.' == *p || '\\' == *p); ++p)
607       ;
608     if (r != p)
609       strcpy(r, p);
610   }
611
612   if (dir_flag)
613     strcat(path, "\\");
614 }
615
616 /*********************************************************************
617  *              _fullpath (MSVCRT.@)
618  */
619 char *_fullpath(char * absPath, const char* relPath, unsigned int size)
620 {
621   char drive[5],dir[MAX_PATH],file[MAX_PATH],ext[MAX_PATH];
622   char res[MAX_PATH];
623   size_t len;
624
625   res[0] = '\0';
626
627   if (!relPath || !*relPath)
628     return _getcwd(absPath, size);
629
630   if (size < 4)
631   {
632     *MSVCRT__errno() = MSVCRT_ERANGE;
633     return NULL;
634   }
635
636   TRACE(":resolving relative path '%s'\n",relPath);
637
638   _splitpath(relPath, drive, dir, file, ext);
639
640   /* Get Directory and drive into 'res' */
641   if (!dir[0] || (dir[0] != '/' && dir[0] != '\\'))
642   {
643     /* Relative or no directory given */
644     _getdcwd(drive[0] ? toupper(drive[0]) - 'A' + 1 :  0, res, MAX_PATH);
645     strcat(res,"\\");
646     if (dir[0])
647       strcat(res,dir);
648     if (drive[0])
649       res[0] = drive[0]; /* If given a drive, preserve the letter case */
650   }
651   else
652   {
653     strcpy(res,drive);
654     strcat(res,dir);
655   }
656
657   strcat(res,"\\");
658   strcat(res, file);
659   strcat(res, ext);
660   msvcrt_fln_fix(res);
661
662   len = strlen(res);
663   if (len >= MAX_PATH || len >= (size_t)size)
664     return NULL; /* FIXME: errno? */
665
666   if (!absPath)
667     return _strdup(res);
668   strcpy(absPath,res);
669   return absPath;
670 }
671
672 /*********************************************************************
673  *              _makepath (MSVCRT.@)
674  */
675 VOID _makepath(char * path, const char * drive,
676                               const char *directory, const char * filename,
677                               const char * extension )
678 {
679     char ch;
680     TRACE("got %s %s %s %s\n", drive, directory,
681           filename, extension);
682
683     if ( !path )
684         return;
685
686     path[0] = 0;
687     if (drive && drive[0])
688     {
689         path[0] = drive[0];
690         path[1] = ':';
691         path[2] = 0;
692     }
693     if (directory && directory[0])
694     {
695         strcat(path, directory);
696         ch = path[strlen(path)-1];
697         if (ch != '/' && ch != '\\')
698             strcat(path,"\\");
699     }
700     if (filename && filename[0])
701     {
702         strcat(path, filename);
703         if (extension && extension[0])
704         {
705             if ( extension[0] != '.' )
706                 strcat(path,".");
707             strcat(path,extension);
708         }
709     }
710
711     TRACE("returning %s\n",path);
712 }
713
714 /*********************************************************************
715  *              _wmakepath (MSVCRT.@)
716  */
717 VOID _wmakepath(WCHAR *path, const WCHAR *drive, const WCHAR *directory,
718                 const WCHAR *filename, const WCHAR *extension)
719 {
720     WCHAR ch;
721     TRACE("%s %s %s %s\n", debugstr_w(drive), debugstr_w(directory),
722           debugstr_w(filename), debugstr_w(extension));
723
724     if ( !path )
725         return;
726
727     path[0] = 0;
728     if (drive && drive[0])
729     {
730         path[0] = drive[0];
731         path[1] = ':';
732         path[2] = 0;
733     }
734     if (directory && directory[0])
735     {
736         strcatW(path, directory);
737         ch = path[strlenW(path) - 1];
738         if (ch != '/' && ch != '\\')
739         {
740             static const WCHAR backslashW[] = {'\\',0};
741             strcatW(path, backslashW);
742         }
743     }
744     if (filename && filename[0])
745     {
746         strcatW(path, filename);
747         if (extension && extension[0])
748         {
749             if ( extension[0] != '.' )
750             {
751                 static const WCHAR dotW[] = {'.',0};
752                 strcatW(path, dotW);
753             }
754             strcatW(path, extension);
755         }
756     }
757
758     TRACE("returning %s\n", debugstr_w(path));
759 }
760
761 /*********************************************************************
762  *              _searchenv (MSVCRT.@)
763  */
764 void _searchenv(const char* file, const char* env, char *buf)
765 {
766   char*envVal, *penv;
767   char curPath[MAX_PATH];
768
769   *buf = '\0';
770
771   /* Try CWD first */
772   if (GetFileAttributesA( file ) != 0xFFFFFFFF)
773   {
774     GetFullPathNameA( file, MAX_PATH, buf, NULL );
775     /* Sigh. This error is *always* set, regardless of success */
776     MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
777     return;
778   }
779
780   /* Search given environment variable */
781   envVal = MSVCRT_getenv(env);
782   if (!envVal)
783   {
784     MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
785     return;
786   }
787
788   penv = envVal;
789   TRACE(":searching for %s in paths %s\n", file, envVal);
790
791   do
792   {
793     char *end = penv;
794
795     while(*end && *end != ';') end++; /* Find end of next path */
796     if (penv == end || !*penv)
797     {
798       MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
799       return;
800     }
801     strncpy(curPath, penv, end - penv);
802     if (curPath[end - penv] != '/' || curPath[end - penv] != '\\')
803     {
804       curPath[end - penv] = '\\';
805       curPath[end - penv + 1] = '\0';
806     }
807     else
808       curPath[end - penv] = '\0';
809
810     strcat(curPath, file);
811     TRACE("Checking for file %s\n", curPath);
812     if (GetFileAttributesA( curPath ) != 0xFFFFFFFF)
813     {
814       strcpy(buf, curPath);
815       MSVCRT__set_errno(ERROR_FILE_NOT_FOUND);
816       return; /* Found */
817     }
818     penv = *end ? end + 1 : end;
819   } while(1);
820 }