int NXLFSMessageCache::fcached(const char* msgid) const { if(!m_cache || !m_maxdisk) return 1; char p[MAX_PATH]; if(sprintf_s(p, "%s\\%s\\%X\\%s", m_cache, "msg", slot(msgid), msgid) == -1) return R(-1, "buffer error"); return _access_s(p, 0x04); }
int Directory_Exist( _In_z_ const char *path) { #if defined(_MSC_VER) return _access_s(path, 0); #else return access(path, 0); #endif }
bool File::isWritable(const char *file) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) // VC++2005 or later return _access_s(file, W_OK) == 0; #else return access(file, W_OK) == 0; #endif }
int dbg_help_client_t::init(char* path) { DWORD64 dwBaseAddr=0; int chars; char exe_path[MAX_PATH]; chars = GetModuleFileName(NULL, exe_path, MAX_PATH); if (chars == 0) { fprintf(stderr,"Could not find base path for XED executable\n"); fflush(stderr); exit(1); } //fprintf(stderr,"EXE PATH %s\n", exe_path); char* dir = find_base_path(exe_path); //fprintf(stderr,"DIR %s\n", dir); char* dbghelp = append3(dir,"\\","dbghelp.dll"); //fprintf(stderr,"DBGHLP %s\n", dbghelp); if (_access_s(dbghelp,4) != 0) { //fprintf(stderr, // "WARNING: Could not find dbghelp.dll in xed.exe directory\n"); //fflush(stderr); return 0; } //fprintf(stderr,"FOUND DBGHELP\n"); if (validate_version(dbghelp)) { fprintf(stderr, "WARNING: dbghelp.dll version is too old\n"); fflush(stderr); return 0; } //FIXME: Add a version check for the dll ( ImagehlpApiVersion is NOT //the right thing) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS); hProcess = GetCurrentProcess(); if (SymInitialize(hProcess, NULL, FALSE)) { // nothing } else { error = GetLastError(); fprintf(stderr,"SymInitialize returned error : %d 0x%x\n", error, error); fflush(stderr); return 0; } actual_base = SymLoadModuleEx(hProcess, NULL, path, NULL, dwBaseAddr, 0, NULL, 0); if (actual_base) { // nothing } else { error = GetLastError(); fprintf(stderr,"SymLoadModuleEx returned error : %d 0x%x\n", error, error); fflush(stderr); return 0; } if (SymEnumerateModules64(hProcess, (PSYM_ENUMMODULES_CALLBACK64)enum_modules, this)) { // nothing } else { error = GetLastError(); fprintf(stderr,"SymEnumerateModules64 returned error : %d 0x%x\n", error, error); fflush(stderr); return 0; } if (SymEnumSymbols(hProcess, actual_base, 0, enum_sym, this)) { // nothing } else { error = GetLastError(); fprintf(stderr,"SymEnumSymbols failed: %d 0x%x\n", error, error); fflush(stderr); return 0; } make_symbol_vector(&sym_tab); initialized = true; return 1; }
FileStatsStruct::FileStatsStruct(std::string path) { errno = 0; #if __MINGW__ || _MSC_VER FileStatsStruct::existing = _access_s(path.c_str(), F_OK); //check exist #elif __GNUC__ FileStatsStruct::existing = access(path.c_str(), F_OK); //check exist #endif FileStatsStruct::existingErrno = errno; if (FileStatsStruct::existing != 0) { switch (FileStatsStruct::existingErrno) { case (ENOENT) : //not existing FileStatsStruct::existingStr = "not existing"; break; case (EACCES) : //not accessible FileStatsStruct::existingStr = "not accessible"; break; default : FileStatsStruct::existingStr = "not accessible"; break; } } #if __MINGW__ || _MSC_VER FileStatsStruct::readable = _access_s(path.c_str(), R_OK); //check exist #elif __GNUC__ FileStatsStruct::readable = access(path.c_str(), R_OK); //check exist #endif if (FileStatsStruct::readable != 0) { switch (FileStatsStruct::readable) { case (0) : FileStatsStruct::readableStr = "readable"; break; default : FileStatsStruct::readableStr = "not readable (access denied)"; break; } } errno = 0; #if __MINGW__ || _MSC_VER FileStatsStruct::writeable = _access_s(path.c_str(), W_OK); //check exist #elif __GNUC__ FileStatsStruct::writeable = access(path.c_str(), W_OK); //check exist #endif int curErrno = errno; if (FileStatsStruct::writeable != 0) { switch (curErrno) { case (EACCES) : //access denied FileStatsStruct::writeableStr = "not writable (access denied)"; break; case (EROFS) : //read only filesystem FileStatsStruct::writeableStr = "not writable (read-only filesystem)"; break; default : FileStatsStruct::writeableStr = "not writable"; break; } } struct stat sb; stat((path).c_str(), &sb); FileStatsStruct::fileType = sb.st_mode; }