/** * Converts dos-style attributes to Unix attributes. * * @returns * @param fMode The mode mask containing dos-style attributes only. * @param pszName The filename which this applies to (exe check). * @param cbName The length of that filename. (optional, set 0) */ RTFMODE rtFsModeFromDos(RTFMODE fMode, const char *pszName, size_t cbName) { fMode &= ~((1 << RTFS_DOS_SHIFT) - 1); /* everything is readable. */ fMode |= RTFS_UNIX_IRUSR | RTFS_UNIX_IRGRP | RTFS_UNIX_IROTH; if (fMode & RTFS_DOS_DIRECTORY) /* directories are executable. */ fMode |= RTFS_TYPE_DIRECTORY | RTFS_UNIX_IXUSR | RTFS_UNIX_IXGRP | RTFS_UNIX_IXOTH; else { fMode |= RTFS_TYPE_FILE; if (!cbName && pszName) cbName = strlen(pszName); if (cbName >= 4 && pszName[cbName - 4] == '.') { /* check for executable extension. */ const char *pszExt = &pszName[cbName - 3]; char szExt[4]; szExt[0] = RT_C_TO_LOWER(pszExt[0]); szExt[1] = RT_C_TO_LOWER(pszExt[1]); szExt[2] = RT_C_TO_LOWER(pszExt[2]); szExt[3] = '\0'; if ( !memcmp(szExt, "exe", 4) || !memcmp(szExt, "bat", 4) || !memcmp(szExt, "com", 4) || !memcmp(szExt, "cmd", 4) || !memcmp(szExt, "btm", 4) ) fMode |= RTFS_UNIX_IXUSR | RTFS_UNIX_IXGRP | RTFS_UNIX_IXOTH; } } /* Is it really a symbolic link? */ if (fMode & RTFS_DOS_NT_REPARSE_POINT) fMode = (fMode & ~RTFS_TYPE_MASK) | RTFS_TYPE_SYMLINK; /* writable? */ if (!(fMode & RTFS_DOS_READONLY)) fMode |= RTFS_UNIX_IWUSR | RTFS_UNIX_IWGRP | RTFS_UNIX_IWOTH; return fMode; }
RTDECL(int) RTPathGetCurrentOnDrive(char chDrive, char *pszPath, size_t cbPath) { #ifdef HAVE_DRIVE /* * Check if it's the same drive as the current directory. */ int rc = RTPathGetCurrent(pszPath, cbPath); if (RT_SUCCESS(rc)) { if ( ( chDrive == *pszPath || RT_C_TO_LOWER(chDrive) == RT_C_TO_LOWER(*pszPath)) && RTPATH_IS_VOLSEP(pszPath[1])) return rc; /* * Different drive, indicate root. */ if (cbPath >= 4) { pszPath[0] = RT_C_TO_UPPER(chDrive); pszPath[1] = ':'; pszPath[2] = RTPATH_SLASH; pszPath[3] = '\0'; return VINF_SUCCESS; } } return rc; #else /* * No driver letters, just return root slash on whatever we're asked. */ NOREF(chDrive); if (cbPath >= 2) { pszPath[0] = RTPATH_SLASH; pszPath[1] = '\0'; return VINF_SUCCESS; } return VERR_BUFFER_OVERFLOW; #endif }