| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) Microsoft Corporation. All rights reserved. | |
| 3 * | |
| 4 *_TSCHAR *_fullpath( _TSCHAR *buf, const _TSCHAR *path, maxlen ); | |
| 5 * | |
| 6 *Purpose: | |
| 7 * | |
| 8 * _fullpath - combines the current directory with path to form | |
| 9 * an absolute path. i.e. _fullpath takes care of .\ and ..\ | |
| 10 * in the path. | |
| 11 * | |
| 12 * The result is placed in buf. If the length of the result | |
| 13 * is greater than maxlen NULL is returned, otherwise | |
| 14 * the address of buf is returned. | |
| 15 * | |
| 16 * If buf is NULL then a buffer is malloc'ed and maxlen is | |
| 17 * ignored. If there are no errors then the address of this | |
| 18 * buffer is returned. | |
| 19 * | |
| 20 * If path specifies a drive, the curent directory of this | |
| 21 * drive is combined with path. If the drive is not valid | |
| 22 * and _fullpath needs the current directory of this drive | |
| 23 * then NULL is returned. If the current directory of this | |
| 24 * non existant drive is not needed then a proper value is | |
| 25 * returned. | |
| 26 * For example: path = "z:\\pop" does not need z:'s current | |
| 27 * directory but path = "z:pop" does. | |
| 28 * | |
| 29 * | |
| 30 * | |
| 31 *Entry: | |
| 32 * _TSCHAR *buf - pointer to a buffer maintained by the user; | |
| 33 * _TSCHAR *path - path to "add" to the current directory | |
| 34 * int maxlen - length of the buffer pointed to by buf | |
| 35 * | |
| 36 *Exit: | |
| 37 * Returns pointer to the buffer containing the absolute path | |
| 38 * (same as buf if non-NULL; otherwise, malloc is | |
| 39 * used to allocate a buffer) | |
| 40 * | |
| 41 *Exceptions: | |
| 42 * | |
| 43 *******************************************************************************/ | |
| 44 | |
| 45 #include <tchar.h> | |
| 46 #include <malloc.h> | |
| 47 #include <stdlib.h> | |
| 48 #include <windows.h> | |
| 49 | |
| 50 | |
| 51 _TSCHAR * __cdecl _tfullpath(_TSCHAR *UserBuf, const _TSCHAR *path, size_t maxle
n) { | |
| 52 _TSCHAR *buf; | |
| 53 _TSCHAR *pfname; | |
| 54 unsigned long count; | |
| 55 | |
| 56 // don't handle this case to reduce dependancies, add this later if requ
ired | |
| 57 if (!path || !*path) /* no work to do */ | |
| 58 // return( _tgetcwd( UserBuf, (int)maxlen ) ); | |
| 59 return( NULL ); | |
| 60 | |
| 61 /* allocate buffer if necessary */ | |
| 62 | |
| 63 if (!UserBuf) | |
| 64 if (!(buf = reinterpret_cast<_TSCHAR*>(malloc(_MAX_PATH * sizeof(_TS
CHAR))))) { | |
| 65 // errno = ENOMEM; | |
| 66 return( NULL ); | |
| 67 } | |
| 68 else | |
| 69 maxlen = _MAX_PATH; | |
| 70 else | |
| 71 buf = UserBuf; | |
| 72 | |
| 73 count = GetFullPathName( path, | |
| 74 (int)maxlen, | |
| 75 buf, | |
| 76 &pfname ); | |
| 77 | |
| 78 if (count >= maxlen) { | |
| 79 if (!UserBuf) | |
| 80 free(buf); | |
| 81 // errno = ERANGE; | |
| 82 return( NULL ); | |
| 83 } | |
| 84 else if (count == 0) { | |
| 85 if (!UserBuf) | |
| 86 free(buf); | |
| 87 // _dosmaperr( GetLastError() ); | |
| 88 return( NULL ); | |
| 89 } | |
| 90 | |
| 91 return( buf ); | |
| 92 | |
| 93 } | |
| OLD | NEW |