/ Set the full path of a file relatively to a given path. */ Note: this routine is not really implemented for Unix. */ /
| 246 | /* Note: this routine is not really implemented for Unix. */ |
| 247 | /***********************************************************************/ |
| 248 | LPCSTR PlugSetPath(LPSTR pBuff, LPCSTR prefix, LPCSTR FileName, LPCSTR defpath) |
| 249 | { |
| 250 | char newname[_MAX_PATH]; |
| 251 | char direc[_MAX_DIR], defdir[_MAX_DIR], tmpdir[_MAX_DIR]; |
| 252 | char fname[_MAX_FNAME]; |
| 253 | char ftype[_MAX_EXT]; |
| 254 | #if defined(_WIN32) |
| 255 | char drive[_MAX_DRIVE], defdrv[_MAX_DRIVE]; |
| 256 | #else |
| 257 | char *drive = NULL, *defdrv = NULL; |
| 258 | #endif |
| 259 | |
| 260 | if (trace(2)) |
| 261 | htrc("prefix=%-.256s fn=%-.256s path=%-.256s\n", prefix, FileName, defpath); |
| 262 | |
| 263 | if (strlen(FileName) >= _MAX_PATH) |
| 264 | { |
| 265 | *pBuff= 0; /* Hope this is treated as error of some kind*/ |
| 266 | return FileName; |
| 267 | } |
| 268 | |
| 269 | if (!strncmp(FileName, "//", 2) || !strncmp(FileName, "\\\\", 2)) { |
| 270 | strcpy(pBuff, FileName); // Remote file |
| 271 | return pBuff; |
| 272 | } // endif |
| 273 | |
| 274 | if (PlugIsAbsolutePath(FileName)) |
| 275 | { |
| 276 | strcpy(pBuff, FileName); // FileName includes absolute path |
| 277 | return pBuff; |
| 278 | } // endif |
| 279 | |
| 280 | #if !defined(_WIN32) |
| 281 | if (*FileName == '~') { |
| 282 | if (_fullpath(pBuff, FileName, _MAX_PATH)) { |
| 283 | if (trace(2)) |
| 284 | htrc("pbuff='%-.256s'\n", pBuff); |
| 285 | |
| 286 | return pBuff; |
| 287 | } else |
| 288 | return FileName; // Error, return unchanged name |
| 289 | |
| 290 | } // endif FileName |
| 291 | #endif // !_WIN32 |
| 292 | |
| 293 | if (prefix && strcmp(prefix, ".") && !PlugIsAbsolutePath(defpath)) |
| 294 | { |
| 295 | char tmp[_MAX_PATH]; |
| 296 | int len= snprintf(tmp, sizeof(tmp) - 1, "%s%s%s", |
| 297 | prefix, defpath, FileName); |
| 298 | memcpy(pBuff, tmp, (size_t) len); |
| 299 | pBuff[len]= '\0'; |
| 300 | return pBuff; |
| 301 | } |
| 302 | |
| 303 | _splitpath(FileName, drive, direc, fname, ftype); |
| 304 | |
| 305 | if (defpath) { |
no test coverage detected