source: trunk/src/kernel32/directory.cpp@ 7798

Last change on this file since 7798 was 7798, checked in by sandervl, 24 years ago

Ported GetTempPathA/W from Wine

File size: 23.9 KB
Line 
1/* $Id: directory.cpp,v 1.43 2002-02-03 21:06:40 sandervl Exp $ */
2
3/*
4 * Win32 Directory functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
7 *
8 * NOTE: Directory creation has to be done in install program (odin\win)
9 *
10 * Parts based on Wine code (991031) (files\directory.c)
11 *
12 * DOS directories functions
13 *
14 * Copyright 1995 Alexandre Julliard
15 *
16 * TODO:
17 * - System/window directories should be created by install program!
18 *
19 * Project Odin Software License can be found in LICENSE.TXT
20 *
21 */
22
23
24/*****************************************************************************
25 * Includes *
26 *****************************************************************************/
27
28#include <odin.h>
29#include <odinwrap.h>
30#include <os2win.h>
31#include <stdlib.h>
32#include <unicode.h>
33#include <heapstring.h>
34#include <options.h>
35#include "initterm.h"
36#include <win\file.h>
37#include <string.h>
38#include "oslibdos.h"
39#include "profile.h"
40#include "fileio.h"
41
42#define DBG_LOCALLOG DBG_directory
43#include "dbglocal.h"
44
45ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
46
47
48/*****************************************************************************
49 * Local Prototypes *
50 *****************************************************************************/
51
52
53static char DIR_Windows[MAX_PATHNAME_LEN];
54static char DIR_System[MAX_PATHNAME_LEN];
55static BOOL fDirInit = FALSE;
56
57//******************************************************************************
58//******************************************************************************
59char *InternalGetWindowsDirectoryA()
60{
61 return DIR_Windows;
62}
63//******************************************************************************
64//******************************************************************************
65char *InternalGetSystemDirectoryA()
66{
67 return DIR_System;
68}
69//******************************************************************************
70//******************************************************************************
71void InitDirectories()
72{
73 char *endofwinpath, *tmp;
74 int len;
75
76 if(fDirInit == TRUE) return;
77
78 fDirInit = TRUE;
79 strcpy(DIR_System, kernel32Path);
80 len = strlen(DIR_System);
81 if(DIR_System[len-1] == '\\') {
82 DIR_System[len-1] = 0;
83 }
84 len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",DIR_Windows,sizeof(DIR_Windows));
85 if (len > 2) {
86 if(DIR_Windows[len-1] == '\\') {
87 DIR_Windows[len-1] = 0;
88 }
89 }
90 else {
91 strcpy(DIR_Windows, DIR_System);
92 endofwinpath = tmp = strchr(DIR_Windows, '\\');
93 while(tmp) {
94 tmp = strchr(endofwinpath+1, '\\');
95 if(tmp)
96 endofwinpath = tmp;
97 }
98 if(endofwinpath) {
99 *endofwinpath = 0; //remove \SYSTEM32
100 }
101 else DebugInt3();
102 }
103 dprintf(("Windows dir: %s", DIR_Windows));
104 dprintf(("System32 dir: %s", DIR_System));
105}
106//*****************************************************************************
107//*****************************************************************************
108void InitDirectoriesCustom(char *szSystemDir, char *szWindowsDir)
109{
110 int len;
111
112 if(fDirInit == TRUE) return;
113 fDirInit = TRUE;
114
115 strcpy(DIR_System, szSystemDir);
116 len = strlen(DIR_System);
117 if(DIR_System[len-1] == '\\') {
118 DIR_System[len-1] = 0;
119 }
120 strcpy(DIR_Windows, szWindowsDir);
121 len = strlen(DIR_Windows);
122 if(DIR_Windows[len-1] == '\\') {
123 DIR_Windows[len-1] = 0;
124 }
125
126 dprintf(("Windows dir: %s", DIR_Windows));
127 dprintf(("System32 dir: %s", DIR_System));
128}
129/*****************************************************************************
130 * Name : GetCurrentDirectoryA
131 * Purpose : query the current directory
132 * Parameters:
133 * Variables :
134 * Result :
135 * Remark : returned length is number of characters required or used for current dir
136 * *excluding* terminator
137 * Status :
138 *
139 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
140 *****************************************************************************/
141
142ODINFUNCTION2(UINT, GetCurrentDirectoryA, UINT, nBufferLength,
143 LPSTR, lpBuffer)
144{
145 UINT rc;
146
147 rc = OSLibDosQueryDir(nBufferLength, lpBuffer);
148 if(rc && rc < nBufferLength) {
149 dprintf(("CurrentDirectory = %s (%d)", lpBuffer, rc));
150 }
151 else dprintf(("CurrentDirectory returned %d", rc));
152 return rc;
153}
154
155
156/*****************************************************************************
157 * Name : GetCurrentDirectoryW
158 * Purpose : query the current directory
159 * Parameters:
160 * Variables :
161 * Result :
162 * Remark :
163 * Status :
164 *
165 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
166 *****************************************************************************/
167
168ODINFUNCTION2(UINT, GetCurrentDirectoryW, UINT, nBufferLength,
169 LPWSTR, lpBuffer)
170{
171 char *asciidir = (char *)malloc(nBufferLength+1);
172 int rc;
173
174 rc = CALL_ODINFUNC(GetCurrentDirectoryA)(nBufferLength, asciidir);
175 if(rc != 0)
176 AsciiToUnicode(asciidir, lpBuffer);
177 free(asciidir);
178 return(rc);
179}
180
181
182/*****************************************************************************
183 * Name : SetCurrentDirectoryA
184 * Purpose :
185 * Parameters:
186 * Variables :
187 * Result :
188 * Remark :
189 * Status :
190 *
191 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
192 *****************************************************************************/
193
194
195ODINFUNCTION1(BOOL, SetCurrentDirectoryA,
196 LPCSTR, lpstrDirectory)
197{
198 if(HIWORD(lpstrDirectory) == 0)
199 {
200 SetLastError(ERROR_INVALID_PARAMETER);
201 return FALSE;
202 }
203
204 // cut off trailing backslashes
205 // not if a process wants to change to the root directory
206 int len = lstrlenA(lpstrDirectory);
207 if ( ( (lpstrDirectory[len - 1] == '\\') ||
208 (lpstrDirectory[len - 1] == '/') ) &&
209 (len != 1) )
210 {
211 LPSTR lpTemp = (LPSTR)_alloca(len);
212 lstrcpynA(lpTemp,
213 lpstrDirectory,
214 len); // len is including trailing NULL!!
215 lpstrDirectory = lpTemp;
216 }
217
218 dprintf(("SetCurrentDirectoryA %s", lpstrDirectory));
219 return O32_SetCurrentDirectory((LPSTR)lpstrDirectory);
220}
221
222
223/*****************************************************************************
224 * Name : SetCurrentDirectoryW
225 * Purpose :
226 * Parameters:
227 * Variables :
228 * Result :
229 * Remark :
230 * Status :
231 *
232 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
233 *****************************************************************************/
234
235ODINFUNCTION1(BOOL,SetCurrentDirectoryW,LPCWSTR,lpPathName)
236{
237 char *asciipath;
238 BOOL rc;
239
240 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
241 rc = SetCurrentDirectoryA(asciipath);
242 FreeAsciiString(asciipath);
243 return(rc);
244}
245
246
247/*****************************************************************************
248 * Name : CreateDirectoryA
249 * Purpose :
250 * Parameters:
251 * Variables :
252 * Result :
253 * Remark :
254 * Status :
255 *
256 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
257 *****************************************************************************/
258
259ODINFUNCTION2(BOOL, CreateDirectoryA,
260 LPCSTR, lpstrDirectory,
261 PSECURITY_ATTRIBUTES,arg2)
262{
263 // 2001-05-28 PH
264 // verify filename first (NT4SP6)
265 // @@@PH: if (IsBadStringPtr( (LPVOID)lpstrDirectory, 0xFFFF))
266 if (lpstrDirectory == NULL)
267 {
268 SetLastError(ERROR_PATH_NOT_FOUND);
269 return FALSE;
270 }
271
272 int len = strlen(lpstrDirectory);
273
274 // cut off trailing backslashes
275 if ( (lpstrDirectory[len - 1] == '\\') ||
276 (lpstrDirectory[len - 1] == '/') )
277 {
278 LPSTR lpTemp = (LPSTR)_alloca(len);
279 lstrcpynA(lpTemp,
280 lpstrDirectory,
281 len ); // len is including trailing NULL!!
282 lpstrDirectory = lpTemp;
283 }
284
285 dprintf(("CreateDirectoryA %s", lpstrDirectory));
286
287 // PH Note 2000/06/12:
288 // Creation of an existing directory is NO ERROR it seems.
289 DWORD dwAttr = GetFileAttributesA(lpstrDirectory);
290 if(dwAttr != -1)
291 {
292 if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
293 {
294 SetLastError(ERROR_SUCCESS);
295 return TRUE;
296 }
297 }
298 return(OSLibDosCreateDirectory(lpstrDirectory));
299}
300
301/*****************************************************************************
302 * Name : CreateDirectoryW
303 * Purpose :
304 * Parameters:
305 * Variables :
306 * Result :
307 * Remark :
308 * Status :
309 *
310 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
311 *****************************************************************************/
312
313ODINFUNCTION2(BOOL,CreateDirectoryW,LPCWSTR, arg1,
314 PSECURITY_ATTRIBUTES,arg2)
315{
316 BOOL rc;
317 char *astring;
318
319 astring = UnicodeToAsciiString((LPWSTR)arg1);
320 rc = CALL_ODINFUNC(CreateDirectoryA)(astring, arg2);
321 FreeAsciiString(astring);
322 return(rc);
323}
324
325/*****************************************************************************
326 * Name : BOOL WIN32API CreateDirectoryExA
327 * Purpose : The CreateDirectoryExA function creates a new directory with a
328 * specified path that retains the attributes of a specified
329 * template directory. If the underlying file system supports
330 * security on files and directories, the function applies a
331 * specified security descriptor to the new directory.
332 * The new directory retains the other attributes of the specified
333 * template directory. Note that CreateDirectoryEx has a template
334 * parameter, while CreateDirectory does not.
335 * Parameters: LPCSTR lpTemplateDirectory pointer to path string of template
336 * directory
337 * LPCSTR lpNewDirectory pointer to path string of directory
338 * to create
339 * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
340 * descriptor
341 *
342 * Variables :
343 * Result : If the function succeeds, the return value is nonzero.
344 * If the function fails, the return value is zero.
345 * To get extended error information, call GetLastError.
346 * Remark :
347 * Status : UNTESTED STUB
348 *
349 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
350 *****************************************************************************/
351
352BOOL WIN32API CreateDirectoryExA( LPCSTR lpTemplateDirectory,
353 LPCSTR lpNewDirectory,
354 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
355{
356
357 dprintf(("KERNEL32:CreateDirectoryExA(%08x,%08x,%08x) not properly implemented\n",
358 lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
359 ));
360
361 return CreateDirectoryA(lpNewDirectory, lpSecurityAttributes);
362}
363
364/*****************************************************************************
365 * Name : BOOL WIN32API CreateDirectoryExW
366 * Purpose : The CreateDirectoryExW function creates a new directory with a
367 * specified path that retains the attributes of a specified
368 * template directory. If the underlying file system supports
369 * security on files and directories, the function applies a
370 * specified security descriptor to the new directory.
371 * The new directory retains the other attributes of the specified
372 * template directory. Note that CreateDirectoryEx has a template
373 * parameter, while CreateDirectory does not.
374 * Parameters: LPCWSTR lpTemplateDirectory pointer to path string of template
375 * directory
376 * LPCWSTR lpNewDirectory pointer to path string of directory
377 * to create
378 * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
379 * descriptor
380 *
381 * Variables :
382 * Result : If the function succeeds, the return value is nonzero.
383 * If the function fails, the return value is zero.
384 * To get extended error information, call GetLastError.
385 * Remark :
386 * Status : UNTESTED STUB
387 *
388 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
389 *****************************************************************************/
390
391BOOL WIN32API CreateDirectoryExW( LPCWSTR lpTemplateDirectory,
392 LPCWSTR lpNewDirectory,
393 LPSECURITY_ATTRIBUTES lpSecurityAttributes)
394{
395
396 dprintf(("KERNEL32:CreateDirectoryExW(%08x,%08x,%08x) not properly implemented\n",
397 lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
398 ));
399
400 return CreateDirectoryW(lpNewDirectory, lpSecurityAttributes);
401}
402
403/*****************************************************************************
404 * Name : GetSystemDirectoryA
405 * Purpose :
406 * Parameters:
407 * Variables :
408 * Result :
409 * Remark : Should return length of system dir even if lpBuffer == NULL
410 * Status :
411 *
412 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
413 *****************************************************************************/
414
415ODINFUNCTION2(UINT,GetSystemDirectoryA,LPSTR,lpBuffer,
416 UINT,uSize)
417{
418 int len;
419 char *dir;
420
421 dir = InternalGetSystemDirectoryA();
422 len = lstrlenA(dir);
423 if(lpBuffer)
424 lstrcpynA(lpBuffer, dir, uSize);
425 return len;
426}
427
428
429/*****************************************************************************
430 * Name : GetSystemDirectoryW
431 * Purpose :
432 * Parameters:
433 * Variables :
434 * Result :
435 * Remark : Should return length of system dir even if lpBuffer == NULL
436 * Status :
437 *
438 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
439 *****************************************************************************/
440
441ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
442 UINT, uSize)
443{
444 char *asciibuffer = NULL;
445 UINT rc;
446
447 if(lpBuffer)
448 asciibuffer = (char *)alloca(uSize+1);
449
450 if(lpBuffer && asciibuffer == NULL)
451 {
452 DebugInt3();
453 }
454
455 rc = GetSystemDirectoryA(asciibuffer, uSize);
456 if(rc && asciibuffer)
457 AsciiToUnicode(asciibuffer, lpBuffer);
458
459 return(rc);
460}
461
462
463/*****************************************************************************
464 * Name : GetWindowsDirectoryA
465 * Purpose :
466 * Parameters:
467 * Variables :
468 * Result :
469 * Remark : Should return length of system dir even if lpBuffer == NULL
470 * Status :
471 *
472 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
473 *****************************************************************************/
474
475ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
476 UINT,uSize)
477{
478 char *dir;
479 int len;
480
481 dir = InternalGetWindowsDirectoryA();
482 len = lstrlenA(dir);
483 if(lpBuffer)
484 lstrcpynA(lpBuffer, dir, uSize);
485 return len;
486}
487
488
489/*****************************************************************************
490 * Name : GetWindowsDirectoryW
491 * Purpose :
492 * Parameters:
493 * Variables :
494 * Result :
495 * Remark : Should return length of system dir even if lpBuffer == NULL
496 * Status :
497 *
498 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
499 *****************************************************************************/
500
501ODINFUNCTION2(UINT,GetWindowsDirectoryW,LPWSTR,lpBuffer,
502 UINT, uSize)
503{
504 char *asciibuffer = NULL;
505 UINT rc;
506
507 if(lpBuffer)
508 asciibuffer = (char *)alloca(uSize+1);
509
510 if(lpBuffer && asciibuffer == NULL)
511 {
512 DebugInt3();
513 }
514
515 rc = GetWindowsDirectoryA(asciibuffer, uSize);
516 if(rc && asciibuffer)
517 AsciiToUnicode(asciibuffer, lpBuffer);
518
519 return(rc);
520}
521
522
523/*****************************************************************************
524 * Name : RemoveDirectoryA
525 * Purpose :
526 * Parameters:
527 * Variables :
528 * Result :
529 * Remark :
530 * Status :
531 *
532 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
533 *****************************************************************************/
534
535
536ODINFUNCTION1(BOOL, RemoveDirectoryA, LPCSTR, lpstrDirectory)
537{
538 int len = strlen(lpstrDirectory);
539
540 if(lpstrDirectory == NULL) {
541 SetLastError(ERROR_INVALID_PARAMETER);
542 return FALSE;
543 }
544 // cut off trailing backslashes
545 if ( (lpstrDirectory[len - 1] == '\\') ||
546 (lpstrDirectory[len - 1] == '/') )
547 {
548 LPSTR lpTemp = (LPSTR)_alloca(len);
549 lstrcpynA(lpTemp,
550 lpstrDirectory,
551 len ); // len is including trailing NULL!!
552 lpstrDirectory = lpTemp;
553 }
554
555 dprintf(("RemoveDirectory %s", lpstrDirectory));
556
557 return OSLibDosRemoveDir(lpstrDirectory);
558}
559
560
561/*****************************************************************************
562 * Name : RemoveDirectoryW
563 * Purpose :
564 * Parameters:
565 * Variables :
566 * Result :
567 * Remark :
568 * Status :
569 *
570 * Author : Patrick Haller [Wed, 1999/09/28 20:44]
571 *****************************************************************************/
572
573ODINFUNCTION1(BOOL,RemoveDirectoryW,LPCWSTR,lpPathName)
574{
575 char *asciipath;
576 BOOL rc;
577
578 asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
579 rc = RemoveDirectoryA(asciipath);
580 FreeAsciiString(asciipath);
581 return(rc);
582}
583
584/***********************************************************************
585 * DIR_TryModulePath
586 *
587 * Helper function for DIR_SearchPath.
588 */
589static BOOL DIR_TryModulePath( LPCSTR name, char *full_name )
590{
591 char buffer[OFS_MAXPATHNAME];
592 LPSTR p;
593
594 if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
595 buffer[0]='\0';
596
597 if (!(p = strrchr( buffer, '\\' ))) return FALSE;
598 if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
599 strcpy( p, name );
600
601 return OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, buffer, full_name, MAX_PATHNAME_LEN);
602}
603
604
605/***********************************************************************
606 * DIR_SearchPath
607 *
608 * Implementation of SearchPath32A. 'win32' specifies whether the search
609 * order is Win16 (module path last) or Win32 (module path first).
610 *
611 * FIXME: should return long path names.
612 */
613DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
614 char *full_name )
615{
616 DWORD len;
617 LPCSTR p;
618 LPSTR tmp = NULL;
619 BOOL ret = TRUE;
620
621 /* First check the supplied parameters */
622
623 p = strrchr( name, '.' );
624 if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
625 ext = NULL; /* Ignore the specified extension */
626 if ((*name && (name[1] == ':')) ||
627 strchr( name, '/' ) || strchr( name, '\\' ))
628 path = NULL; /* Ignore path if name already contains a path */
629 if (path && !*path) path = NULL; /* Ignore empty path */
630
631 /* See if path is a list of directories to search. If so, only search
632 those (according to SDK docs) */
633 if ((path != NULL) && strchr(path, ';')) {
634 ret = OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)path, (LPSTR)name,
635 full_name, MAX_PATHNAME_LEN);
636 goto done;
637 }
638
639 len = strlen(name);
640 if (ext) len += strlen(ext);
641 if (path) len += strlen(path) + 1;
642
643 /* Allocate a buffer for the file name and extension */
644
645 if (path || ext)
646 {
647 if (!(tmp = (LPSTR)HeapAlloc( GetProcessHeap(), 0, len + 1 )))
648 {
649 SetLastError( ERROR_OUTOFMEMORY );
650 return 0;
651 }
652 if (path)
653 {
654 strcpy( tmp, path );
655 strcat( tmp, "\\" );
656 strcat( tmp, name );
657 }
658 else strcpy( tmp, name );
659 if (ext) strcat( tmp, ext );
660 name = tmp;
661 }
662
663 /* If we have an explicit path, everything's easy */
664
665 if (path || (*name && (name[1] == ':')) ||
666 strchr( name, '/' ) || strchr( name, '\\' ))
667 {
668 ret = OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN);
669 goto done;
670 }
671
672 /* Try the path of the current executable (for Win32 search order) */
673 if (DIR_TryModulePath( name, full_name )) goto done;
674
675 /* Try the current directory */
676 if (OSLibDosSearchPath(OSLIB_SEARCHCURDIR, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
677 goto done;
678
679 /* Try the Windows system directory */
680 if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_System, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
681 goto done;
682
683 /* Try the Windows directory */
684 if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_Windows, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
685 goto done;
686
687 /* Try all directories in path */
688 ret = OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", (LPSTR)name, full_name, MAX_PATHNAME_LEN);
689
690done:
691 if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
692 return ret;
693}
694
695
696/***********************************************************************
697 * SearchPath32A [KERNEL32.447]
698 *
699 * Searches for a specified file in the search path.
700 *
701 * PARAMS
702 * path [I] Path to search
703 * name [I] Filename to search for.
704 * ext [I] File extension to append to file name. The first
705 * character must be a period. This parameter is
706 * specified only if the filename given does not
707 * contain an extension.
708 * buflen [I] size of buffer, in characters
709 * buffer [O] buffer for found filename
710 * lastpart [O] address of pointer to last used character in
711 * buffer (the final '\')
712 *
713 * RETURNS
714 * Success: length of string copied into buffer, not including
715 * terminating null character. If the filename found is
716 * longer than the length of the buffer, the length of the
717 * filename is returned.
718 * Failure: Zero
719 *
720 * NOTES
721 * Should call SetLastError(but currently doesn't).
722 */
723DWORD WINAPI SearchPathA(LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
724 LPSTR buffer, LPSTR *lastpart )
725{
726 char full_name[MAX_PATHNAME_LEN];
727
728 if (!DIR_SearchPath( path, name, ext, (LPSTR)full_name )) return 0;
729 lstrcpynA( buffer, (LPSTR)full_name, buflen);
730 SetLastError(0);
731 return strlen(full_name);
732}
733
734
735/***********************************************************************
736 * SearchPath32W (KERNEL32.448)
737 */
738DWORD WINAPI SearchPathW(LPCWSTR path, LPCWSTR name, LPCWSTR ext,
739 DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
740{
741 char full_name[MAX_PATHNAME_LEN];
742
743 LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
744 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
745 LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
746 DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name );
747 HeapFree( GetProcessHeap(), 0, extA );
748 HeapFree( GetProcessHeap(), 0, nameA );
749 HeapFree( GetProcessHeap(), 0, pathA );
750 if (!ret) return 0;
751
752 lstrcpynAtoW( buffer, full_name, buflen);
753 SetLastError(0);
754 return ret;
755}
756//******************************************************************************
757//******************************************************************************
758ODINFUNCTION2(UINT, GetTempPathA,
759 UINT, count, LPSTR, path)
760{
761 UINT ret;
762 if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
763 if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
764 if (!(ret = GetCurrentDirectoryA( count, path )))
765 return 0;
766 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
767 {
768 path[ret++] = '\\';
769 path[ret] = '\0';
770 }
771 return ret;
772}
773//******************************************************************************
774//******************************************************************************
775ODINFUNCTION2(UINT, GetTempPathW,
776 UINT, count, LPWSTR, path)
777{
778 static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
779 static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
780 UINT ret;
781 if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
782 if (!(ret = GetEnvironmentVariableW( temp, path, count )))
783 if (!(ret = GetCurrentDirectoryW( count, path )))
784 return 0;
785 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
786 {
787 path[ret++] = '\\';
788 path[ret] = '\0';
789 }
790 return ret;
791}
792//******************************************************************************
793//******************************************************************************
Note: See TracBrowser for help on using the repository browser.