RTDECL(int) RTGetOptArgvToUtf16String(PRTUTF16 *ppwszCmdLine, const char * const *papszArgv, uint32_t fFlags) { char *pszCmdLine; int rc = RTGetOptArgvToString(&pszCmdLine, papszArgv, fFlags); if (RT_SUCCESS(rc)) { rc = RTStrToUtf16(pszCmdLine, ppwszCmdLine); RTStrFree(pszCmdLine); } return rc; }
RTDECL(int) RTEnvDestroy(RTENV Env) { /* * Ignore NIL_RTENV and validate input. */ if ( Env == NIL_RTENV || Env == RTENV_DEFAULT) return VINF_SUCCESS; PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); /* * Do the cleanup. */ RTENV_LOCK(pIntEnv); pIntEnv->u32Magic++; size_t iVar = pIntEnv->cVars; while (iVar-- > 0) RTStrFree(pIntEnv->papszEnv[iVar]); RTMemFree(pIntEnv->papszEnv); pIntEnv->papszEnv = NULL; if (pIntEnv->papszEnvOtherCP) { for (iVar = 0; pIntEnv->papszEnvOtherCP[iVar]; iVar++) { RTStrFree(pIntEnv->papszEnvOtherCP[iVar]); pIntEnv->papszEnvOtherCP[iVar] = NULL; } RTMemFree(pIntEnv->papszEnvOtherCP); pIntEnv->papszEnvOtherCP = NULL; } RTENV_UNLOCK(pIntEnv); /*RTCritSectDelete(&pIntEnv->CritSect) */ RTMemFree(pIntEnv); return VINF_SUCCESS; }
/** * Make sure the Id and Revision keywords are expanded. * * @returns false - the state carries these kinds of changes. * @param pState The rewriter state. * @param pIn The input stream. * @param pOut The output stream. * @param pSettings The settings. */ bool rewrite_SvnKeywords(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings) { if ( !pSettings->fSetSvnKeywords || !ScmSvnIsInWorkingCopy(pState)) return false; char *pszKeywords; int rc = ScmSvnQueryProperty(pState, "svn:keywords", &pszKeywords); if ( RT_SUCCESS(rc) && ( !strstr(pszKeywords, "Id") /** @todo need some function for finding a word in a string. */ || !strstr(pszKeywords, "Revision")) ) { if (!strstr(pszKeywords, "Id") && !strstr(pszKeywords, "Revision")) rc = RTStrAAppend(&pszKeywords, " Id Revision"); else if (!strstr(pszKeywords, "Id")) rc = RTStrAAppend(&pszKeywords, " Id"); else rc = RTStrAAppend(&pszKeywords, " Revision"); if (RT_SUCCESS(rc)) { ScmVerbose(pState, 2, " * changing svn:keywords to '%s'\n", pszKeywords); rc = ScmSvnSetProperty(pState, "svn:keywords", pszKeywords); if (RT_FAILURE(rc)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */ } else RTMsgError("RTStrAppend: %Rrc\n", rc); /** @todo error propagation here.. */ RTStrFree(pszKeywords); } else if (rc == VERR_NOT_FOUND) { ScmVerbose(pState, 2, " * setting svn:keywords to 'Id Revision'\n"); rc = ScmSvnSetProperty(pState, "svn:keywords", "Id Revision"); if (RT_FAILURE(rc)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */ } else if (RT_SUCCESS(rc)) RTStrFree(pszKeywords); return false; }
RTDECL(int) RTEnvUnsetEx(RTENV Env, const char *pszVar) { AssertPtrReturn(pszVar, VERR_INVALID_POINTER); AssertReturn(*pszVar, VERR_INVALID_PARAMETER); int rc; if (Env == RTENV_DEFAULT) { /* * Since RTEnvUnset isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { rc = RTEnvUnset(pszVarOtherCP); RTStrFree(pszVarOtherCP); } } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); RTENV_LOCK(pIntEnv); /* * Remove all variable by the given name. */ rc = VINF_ENV_VAR_NOT_FOUND; const size_t cchVar = strlen(pszVar); size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) if ( !strncmp(pIntEnv->papszEnv[iVar], pszVar, cchVar) && pIntEnv->papszEnv[iVar][cchVar] == '=') { RTMemFree(pIntEnv->papszEnv[iVar]); pIntEnv->cVars--; if (pIntEnv->cVars > 0) pIntEnv->papszEnv[iVar] = pIntEnv->papszEnv[pIntEnv->cVars]; pIntEnv->papszEnv[pIntEnv->cVars] = NULL; rc = VINF_SUCCESS; /* no break, there could be more. */ } RTENV_UNLOCK(pIntEnv); } return rc; }
RTDECL(int) RTSymlinkRead(const char *pszSymlink, char *pszTarget, size_t cbTarget, uint32_t fRead) { char *pszMyTarget; int rc = RTSymlinkReadA(pszSymlink, &pszMyTarget); if (RT_SUCCESS(rc)) { rc = RTStrCopy(pszTarget, cbTarget, pszMyTarget); RTStrFree(pszMyTarget); } LogFlow(("RTSymlinkRead(%p={%s}): returns %Rrc\n", pszSymlink, pszSymlink, rc)); return rc; }
/** * Checks if a testcase is include or should be skipped. * * @param pszTestcase The testcase (filename). * * @return true if the testcase is included. * false if the testcase should be skipped. */ static bool IsTestcaseIncluded(const char *pszTestcase) { /* exclude special modules based on extension. */ const char *pszExt = RTPathExt(pszTestcase); if ( !RTStrICmp(pszExt, ".r0") || !RTStrICmp(pszExt, ".gc") || !RTStrICmp(pszExt, ".sys") || !RTStrICmp(pszExt, ".ko") || !RTStrICmp(pszExt, ".o") || !RTStrICmp(pszExt, ".obj") || !RTStrICmp(pszExt, ".lib") || !RTStrICmp(pszExt, ".a") || !RTStrICmp(pszExt, ".so") || !RTStrICmp(pszExt, ".dll") || !RTStrICmp(pszExt, ".dylib") || !RTStrICmp(pszExt, ".tmp") || !RTStrICmp(pszExt, ".log") ) return false; /* check by name */ char *pszDup = RTStrDup(pszTestcase); if (pszDup) { RTPathStripExt(pszDup); for (unsigned i = 0; i < RT_ELEMENTS(g_apszExclude); i++) { if (!strcmp(g_apszExclude[i], pszDup)) { RTStrFree(pszDup); return false; } } RTStrFree(pszDup); return true; } RTPrintf("tstRunTestcases: Out of memory!\n"); return false; }
RTDECL(bool) RTEnvExistEx(RTENV Env, const char *pszVar) { AssertPtrReturn(pszVar, false); bool fExists = false; if (Env == RTENV_DEFAULT) { #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API fExists = RTEnvExistsUtf8(pszVar); #else /* * Since RTEnvExist isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; int rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { fExists = RTEnvExist(pszVarOtherCP); RTStrFree(pszVarOtherCP); } #endif } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, false); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, false); RTENV_LOCK(pIntEnv); /* * Simple search. */ const size_t cchVar = strlen(pszVar); for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++) if (!pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar)) { if (pIntEnv->papszEnv[iVar][cchVar] == '=') { fExists = true; break; } if (pIntEnv->papszEnv[iVar][cchVar] == '\0') break; } RTENV_UNLOCK(pIntEnv); } return fExists; }
/** * Fallback for VbglR3GetAdditionsVersion. */ static int vbglR3GetAdditionsCompileTimeVersion(char **ppszVer, char **ppszVerEx, char **ppszRev) { int rc = VINF_SUCCESS; if (ppszVer) rc = RTStrDupEx(ppszVer, VBOX_VERSION_STRING_RAW); if (RT_SUCCESS(rc)) { if (ppszVerEx) rc = RTStrDupEx(ppszVerEx, VBOX_VERSION_STRING); if (RT_SUCCESS(rc)) { if (ppszRev) { #if 0 char szRev[64]; RTStrPrintf(szRev, sizeof(szRev), "%d", VBOX_SVN_REV); rc = RTStrDupEx(ppszRev, szRev); #else rc = RTStrDupEx(ppszRev, RT_XSTR(VBOX_SVN_REV)); #endif } if (RT_SUCCESS(rc)) return VINF_SUCCESS; /* bail out: */ } if (ppszVerEx) { RTStrFree(*ppszVerEx); *ppszVerEx = NULL; } } if (ppszVer) { RTStrFree(*ppszVer); *ppszVer = NULL; } return rc; }
RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pcszCAFile) { PRTHTTPINTERNAL pHttpInt = hHttp; RTHTTP_VALID_RETURN(pHttpInt); if (pHttpInt->pcszCAFile) RTStrFree(pHttpInt->pcszCAFile); pHttpInt->pcszCAFile = RTStrDup(pcszCAFile); if (!pHttpInt->pcszCAFile) return VERR_NO_MEMORY; return VINF_SUCCESS; }
RTR3DECL(void) RTS3Destroy(RTS3 hS3) { if (hS3 == NIL_RTS3) return; PRTS3INTERNAL pS3Int = hS3; RTS3_VALID_RETURN_VOID(pS3Int); curl_easy_cleanup(pS3Int->pCurl); pS3Int->u32Magic = RTS3_MAGIC_DEAD; if (pS3Int->pszUserAgent) RTStrFree(pS3Int->pszUserAgent); RTStrFree(pS3Int->pszBaseUrl); RTStrFree(pS3Int->pszSecretKey); RTStrFree(pS3Int->pszAccessKey); RTMemFree(pS3Int); curl_global_cleanup(); }
static char* rtS3CreateAuthHeader(PRTS3INTERNAL pS3Int, const char* pszAction, const char* pszBucket, const char* pszKey, char** papszHeadEnts, size_t cHeadEnts) { char *pszAuth; /* Create a signature out of the header & the bucket/key info */ char *pszSigBase64Enc = rtS3CreateSignature(pS3Int, pszAction, pszBucket, pszKey, papszHeadEnts, cHeadEnts); /* Create the authorization header entry */ RTStrAPrintf(&pszAuth, "Authorization: AWS %s:%s", pS3Int->pszAccessKey, pszSigBase64Enc); RTStrFree(pszSigBase64Enc); return pszAuth; }
/** * Formats a string and writes it to the SCM stream. * * @returns The number of bytes written (>= 0). Negative value are IPRT error * status codes. * @param pStream The stream to write to. * @param pszFormat The format string. * @param va The arguments to format. */ ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va) { char *psz; ssize_t cch = RTStrAPrintfV(&psz, pszFormat, va); if (cch) { int rc = ScmStreamWrite(pStream, psz, cch); RTStrFree(psz); if (RT_FAILURE(rc)) cch = rc; } return cch; }
/** * Reads a guest property from the host side. * * @returns VBox status code, fully bitched. * * @param u32ClientId The HGCM client ID for the guest property session. * @param pszPropName The property name. * @param fReadOnly Whether or not this property needs to be read only * by the guest side. Otherwise VERR_ACCESS_DENIED will * be returned. * @param ppszValue Where to return the value. This is always set * to NULL. Free it using RTStrFree(). * @param ppszFlags Where to return the value flags. Free it * using RTStrFree(). Optional. * @param puTimestamp Where to return the timestamp. This is only set * on success. Optional. */ int VBoxServiceReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) { AssertPtrReturn(ppszValue, VERR_INVALID_PARAMETER); char *pszValue = NULL; char *pszFlags = NULL; int rc = VBoxServiceReadProp(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp); if (RT_SUCCESS(rc)) { /* Check security bits. */ if ( fReadOnly /* Do we except a guest read-only property */ && !RTStrStr(pszFlags, "RDONLYGUEST")) { /* If we want a property which is read-only on the guest * and it is *not* marked as such, deny access! */ rc = VERR_ACCESS_DENIED; } if (RT_SUCCESS(rc)) { *ppszValue = pszValue; if (ppszFlags) *ppszFlags = pszFlags; else if (pszFlags) RTStrFree(pszFlags); } else { if (pszValue) RTStrFree(pszValue); if (pszFlags) RTStrFree(pszFlags); } } return rc; }
/** * Same as dbgfR3AsSearchEnv, except that the path is taken from the environment. * * If the environment variable doesn't exist, the current directory is searched * instead. * * @returns VBox status code. * @param pszFilename The filename. * @param pszEnvVar The environment variable name. * @param pfnOpen The open callback function. * @param pvUser User argument for the callback. */ static int dbgfR3AsSearchEnvPath(const char *pszFilename, const char *pszEnvVar, PFNDBGFR3ASSEARCHOPEN pfnOpen, void *pvUser) { int rc; char *pszPath = RTEnvDupEx(RTENV_DEFAULT, pszEnvVar); if (pszPath) { rc = dbgfR3AsSearchPath(pszFilename, pszPath, pfnOpen, pvUser); RTStrFree(pszPath); } else rc = dbgfR3AsSearchPath(pszFilename, ".", pfnOpen, pvUser); return rc; }
/** * Deletes one critical section. * * @returns Return code from RTCritSectDelete. * * @param pVM Pointer to the VM. * @param pCritSect The critical section. * @param pPrev The previous critical section in the list. * @param fFinal Set if this is the final call and statistics shouldn't be deregistered. * * @remarks Caller must have entered the ListCritSect. */ static int pdmR3CritSectDeleteOne(PVM pVM, PUVM pUVM, PPDMCRITSECTINT pCritSect, PPDMCRITSECTINT pPrev, bool fFinal) { /* * Assert free waiters and so on (c&p from RTCritSectDelete). */ Assert(pCritSect->Core.u32Magic == RTCRITSECT_MAGIC); Assert(pCritSect->Core.cNestings == 0); Assert(pCritSect->Core.cLockers == -1); Assert(pCritSect->Core.NativeThreadOwner == NIL_RTNATIVETHREAD); Assert(RTCritSectIsOwner(&pUVM->pdm.s.ListCritSect)); /* * Unlink it. */ if (pPrev) pPrev->pNext = pCritSect->pNext; else pUVM->pdm.s.pCritSects = pCritSect->pNext; /* * Delete it (parts taken from RTCritSectDelete). * In case someone is waiting we'll signal the semaphore cLockers + 1 times. */ ASMAtomicWriteU32(&pCritSect->Core.u32Magic, 0); SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->Core.EventSem; pCritSect->Core.EventSem = NIL_RTSEMEVENT; while (pCritSect->Core.cLockers-- >= 0) SUPSemEventSignal(pVM->pSession, hEvent); ASMAtomicWriteS32(&pCritSect->Core.cLockers, -1); int rc = SUPSemEventClose(pVM->pSession, hEvent); AssertRC(rc); RTLockValidatorRecExclDestroy(&pCritSect->Core.pValidatorRec); pCritSect->pNext = NULL; pCritSect->pvKey = NULL; pCritSect->pVMR3 = NULL; pCritSect->pVMR0 = NIL_RTR0PTR; pCritSect->pVMRC = NIL_RTRCPTR; RTStrFree((char *)pCritSect->pszName); pCritSect->pszName = NULL; if (!fFinal) { STAMR3Deregister(pVM, &pCritSect->StatContentionRZLock); STAMR3Deregister(pVM, &pCritSect->StatContentionRZUnlock); STAMR3Deregister(pVM, &pCritSect->StatContentionR3); #ifdef VBOX_WITH_STATISTICS STAMR3Deregister(pVM, &pCritSect->StatLocked); #endif } return rc; }
/** * Displays an error message. * * @param hPAM PAM handle. * @param pszFormat The message text. * @param ... Format arguments. */ static void pam_vbox_error(pam_handle_t *hPAM, const char *pszFormat, ...) { RT_NOREF1(hPAM); va_list va; char *buf; va_start(va, pszFormat); if (RT_SUCCESS(RTStrAPrintfV(&buf, pszFormat, va))) { LogRel(("%s: Error: %s", VBOX_MODULE_NAME, buf)); pam_vbox_writesyslog(buf); RTStrFree(buf); } va_end(va); }
DirectoryServiceProvider::~DirectoryServiceProvider() { if (mCompRegLocation) { RTStrFree(mCompRegLocation); mCompRegLocation = NULL; } if (mXPTIDatLocation) { RTStrFree(mXPTIDatLocation); mXPTIDatLocation = NULL; } if (mComponentDirLocation) { RTStrFree(mComponentDirLocation); mComponentDirLocation = NULL; } if (mCurrProcDirLocation) { RTStrFree(mCurrProcDirLocation); mCurrProcDirLocation = NULL; } }
/** * Internal worker which initializes or re-initializes the * program path, name and directory globals. * * @returns IPRT status code. * @param fFlags Flags, see RTR3INIT_XXX. * @param cArgs Pointer to the argument count. * @param ppapszArgs Pointer to the argument vector pointer. NULL * allowed if @a cArgs is 0. */ static int rtR3InitArgv(uint32_t fFlags, int cArgs, char ***ppapszArgs) { NOREF(fFlags); if (cArgs) { AssertPtr(ppapszArgs); AssertPtr(*ppapszArgs); char **papszOrgArgs = *ppapszArgs; /* * Normally we should only be asked to convert arguments once. If we * are though, it should be the already convered arguments. */ if (g_crtArgs != -1) { AssertReturn( g_crtArgs == cArgs && g_papszrtArgs == papszOrgArgs, VERR_WRONG_ORDER); /* only init once! */ return VINF_SUCCESS; } /* * Convert the arguments. */ char **papszArgs = (char **)RTMemAllocZ((cArgs + 1) * sizeof(char *)); if (!papszArgs) return VERR_NO_MEMORY; for (int i = 0; i < cArgs; i++) { int rc = RTStrCurrentCPToUtf8(&papszArgs[i], papszOrgArgs[i]); if (RT_FAILURE(rc)) { while (i--) RTStrFree(papszArgs[i]); RTMemFree(papszArgs); return rc; } } papszArgs[cArgs] = NULL; g_papszrtOrgArgs = papszOrgArgs; g_papszrtArgs = papszArgs; g_crtArgs = cArgs; *ppapszArgs = papszArgs; } return VINF_SUCCESS; }
int DnDURIList::AppendURIPath(const char *pszURI, uint32_t fFlags) { AssertPtrReturn(pszURI, VERR_INVALID_POINTER); /** @todo Check for string termination? */ #ifdef DEBUG_andy LogFlowFunc(("pszPath=%s, fFlags=0x%x\n", pszURI, fFlags)); #endif int rc = VINF_SUCCESS; /* Query the path component of a file URI. If this hasn't a * file scheme NULL is returned. */ char *pszFilePath = RTUriFilePath(pszURI, URI_FILE_FORMAT_AUTO); if (pszFilePath) { /* Add the path to our internal file list (recursive in * the case of a directory). */ size_t cbPathLen = RTPathStripTrailingSlash(pszFilePath); if (cbPathLen) { char *pszFileName = RTPathFilename(pszFilePath); if (pszFileName) { Assert(pszFileName >= pszFilePath); size_t cbBase = (fFlags & DNDURILIST_FLAGS_ABSOLUTE_PATHS) ? 0 /* Use start of path as root. */ : pszFileName - pszFilePath; char *pszRoot = &pszFilePath[cbBase]; m_lstRoot.append(pszRoot); #ifdef DEBUG_andy LogFlowFunc(("pszFilePath=%s, pszFileName=%s, pszRoot=%s\n", pszFilePath, pszFileName, pszRoot)); #endif rc = appendPathRecursive(pszFilePath, cbBase, fFlags); } else rc = VERR_NOT_FOUND; } else rc = VERR_INVALID_PARAMETER; RTStrFree(pszFilePath); } else rc = VERR_INVALID_PARAMETER; LogFlowFuncLeaveRC(rc); return rc; }
/** * Logs the message to the appropriate system log. * * In debug builds this will also put it in the debug log. * * @param pszFormat The log string. No trailing newline. * @param ... Format arguments. * * @todo This should later be replaced by the release logger and callback destination(s). */ void supSvcLogErrorV(const char *pszFormat, va_list va) { if (*pszFormat) { char *pszMsg = NULL; if (RTStrAPrintfV(&pszMsg, pszFormat, va) != -1) { supSvcLogErrorStr(pszMsg); RTStrFree(pszMsg); } else supSvcLogErrorStr(pszFormat); } }
/** * Worker for rewrite_ForceNativeEol, rewrite_ForceLF and rewrite_ForceCRLF. * * @returns true if modifications were made, false if not. * @param pIn The input stream. * @param pOut The output stream. * @param pSettings The settings. * @param enmDesiredEol The desired end of line indicator type. * @param pszDesiredSvnEol The desired svn:eol-style. */ static bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings, SCMEOL enmDesiredEol, const char *pszDesiredSvnEol) { if (!pSettings->fConvertEol) return false; bool fModified = false; SCMEOL enmEol; size_t cchLine; const char *pchLine; while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) { if ( enmEol != enmDesiredEol && enmEol != SCMEOL_NONE) { fModified = true; enmEol = enmDesiredEol; } int rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol); if (RT_FAILURE(rc)) return false; } if (fModified) ScmVerbose(pState, 2, " * Converted EOL markers\n"); /* Check svn:eol-style if appropriate */ if ( pSettings->fSetSvnEol && ScmSvnIsInWorkingCopy(pState)) { char *pszEol; int rc = ScmSvnQueryProperty(pState, "svn:eol-style", &pszEol); if ( (RT_SUCCESS(rc) && strcmp(pszEol, pszDesiredSvnEol)) || rc == VERR_NOT_FOUND) { if (rc == VERR_NOT_FOUND) ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (missing)\n", pszDesiredSvnEol); else ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (was: %s)\n", pszDesiredSvnEol, pszEol); int rc2 = ScmSvnSetProperty(pState, "svn:eol-style", pszDesiredSvnEol); if (RT_FAILURE(rc2)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc2); /** @todo propagate the error somehow... */ } if (RT_SUCCESS(rc)) RTStrFree(pszEol); } /** @todo also check the subversion svn:eol-style state! */ return fModified; }
/* * Check for HTTP errors, in particular properly display redirections. */ static void checkError(RTHTTP hHttp, int rc, const char *pszFile) { if (rc == VERR_HTTP_REDIRECTED) { char *pszRedirLocation; int rc2 = RTHttpGetRedirLocation(hHttp, &pszRedirLocation); if (RT_SUCCESS(rc2)) RTPrintf("Redirected to '%s' trying to fetch '%s'\n", pszRedirLocation, pszFile); else RTPrintf("Redirected trying to fetch '%s'\n", pszFile); RTStrFree(pszRedirLocation); } else RTPrintf("Error %Rrc trying to fetch '%s'\n", rc, pszFile); }
/** * Displays an error message. * * @returns RTEXITCODE_FAILURE. * @param pszFormat The message text. * @param ... Format arguments. */ RTEXITCODE VBoxServiceError(const char *pszFormat, ...) { va_list args; va_start(args, pszFormat); char *psz = NULL; RTStrAPrintfV(&psz, pszFormat, args); va_end(args); AssertPtr(psz); LogRel(("Error: %s", psz)); RTStrFree(psz); return RTEXITCODE_FAILURE; }
HRESULT VFSExplorer::cdUp(ComPtr<IProgress> &aProgress) { Utf8Str strUpPath; { AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); /* Remove lowest dir entry in a platform neutral way. */ char *pszNewPath = RTStrDup(m->strPath.c_str()); RTPathStripTrailingSlash(pszNewPath); RTPathStripFilename(pszNewPath); strUpPath = pszNewPath; RTStrFree(pszNewPath); } return cd(strUpPath, aProgress); }
static int rtMsgWorker(PRTSTREAM pDst, const char *pszPrefix, const char *pszFormat, va_list va) { if ( !*pszFormat || !strcmp(pszFormat, "\n")) RTStrmPrintf(pDst, "\n"); else { const char *pszProgName = g_pszProgName; if (!pszProgName) g_pszProgName = pszProgName = &g_szrtProcExePath[g_offrtProcName]; char *pszMsg; ssize_t cch = RTStrAPrintfV(&pszMsg, pszFormat, va); if (cch >= 0) { /* print it line by line. */ char *psz = pszMsg; do { char *pszEnd = strchr(psz, '\n'); if (!pszEnd) { RTStrmPrintf(pDst, "%s: %s%s\n", pszProgName, pszPrefix, psz); break; } if (pszEnd == psz) RTStrmPrintf(pDst, "\n"); else { *pszEnd = '\0'; RTStrmPrintf(pDst, "%s: %s%s\n", pszProgName, pszPrefix, psz); } psz = pszEnd + 1; } while (*psz); RTStrFree(pszMsg); } else { /* Simple fallback for handling out-of-memory conditions. */ RTStrmPrintf(pDst, "%s: %s", pszProgName, pszPrefix); RTStrmPrintfV(pDst, pszFormat, va); if (!strchr(pszFormat, '\n')) RTStrmPrintf(pDst, "\n"); } } return VINF_SUCCESS; }
/** * Finds the svn binary, updating g_szSvnPath and g_enmSvnVersion. */ static void scmSvnFindSvnBinary(PSCMRWSTATE pState) { /* Already been called? */ if (g_szSvnPath[0] != '\0') return; /* * Locate it. */ /** @todo code page fun... */ #ifdef RT_OS_WINDOWS const char *pszEnvVar = RTEnvGet("Path"); #else const char *pszEnvVar = RTEnvGet("PATH"); #endif if (pszEnvVar) { #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) int rc = RTPathTraverseList(pszEnvVar, ';', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath)); #else int rc = RTPathTraverseList(pszEnvVar, ':', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath)); #endif if (RT_FAILURE(rc)) strcpy(g_szSvnPath, "svn"); } else strcpy(g_szSvnPath, "svn"); /* * Check the version. */ const char *apszArgs[] = { g_szSvnPath, "--version", "--quiet", NULL }; char *pszVersion; int rc = scmSvnRunAndGetOutput(pState, apszArgs, false, &pszVersion); if (RT_SUCCESS(rc)) { char *pszStripped = RTStrStrip(pszVersion); if (RTStrVersionCompare(pszVersion, "1.7") >= 0) g_enmSvnVersion = kScmSvnVersion_1_7; else if (RTStrVersionCompare(pszVersion, "1.6") >= 0) g_enmSvnVersion = kScmSvnVersion_1_6; else g_enmSvnVersion = kScmSvnVersion_Ancient; RTStrFree(pszVersion); } else g_enmSvnVersion = kScmSvnVersion_Ancient; }
/** * Helper for opening the specified kernel module. * * @param pszModule The name of the module. * @param ppMod Where to store the module handle. * @param ppCtf Where to store the module's CTF handle. * * @returns Pointer to the CTF structure for the module. */ static int rtR0DbgKrnlInfoModRetainEx(const char *pszModule, modctl_t **ppMod, ctf_file_t **ppCtf) { char *pszMod = RTStrDup(pszModule); if (RT_LIKELY(pszMod)) { int rc = rtR0DbgKrnlInfoModRetain(pszMod, ppMod, ppCtf); RTStrFree(pszMod); if (RT_SUCCESS(rc)) { AssertPtrReturn(*ppMod, VERR_INTERNAL_ERROR_2); AssertPtrReturn(*ppCtf, VERR_INTERNAL_ERROR_3); } return rc; } return VERR_NO_MEMORY; }
/** * Allocating string printf. * * @returns Pointer to the string. * @param pUVM Pointer to the user mode VM structure. * @param enmTag The statistics tag. * @param pszFormat The format string. * @param va Format arguments. */ VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va) { /* * The lazy bird way. */ char *psz; int cch = RTStrAPrintfV(&psz, pszFormat, va); if (cch < 0) return NULL; Assert(psz[cch] == '\0'); char *pszRet = (char *)MMR3HeapAllocU(pUVM, enmTag, cch + 1); if (pszRet) memcpy(pszRet, psz, cch + 1); RTStrFree(psz); return pszRet; }
/** * Displays a verbose message. * * @param iLevel Minimum log level required to display this message. * @param pszFormat The message text. * @param ... Format arguments. */ void VBoxGINAVerbose(DWORD dwLevel, const char *pszFormat, ...) { if (dwLevel <= g_dwVerbosity) { va_list args; va_start(args, pszFormat); char *psz = NULL; RTStrAPrintfV(&psz, pszFormat, args); va_end(args); AssertPtr(psz); LogRel(("%s", psz)); RTStrFree(psz); } }
/** * Displays a verbose message. * * @param iLevel Minimum log level required to display this message. * @param pszFormat The message text. * @param ... Format arguments. */ void VBoxClientVerbose(int iLevel, const char *pszFormat, ...) { if (iLevel > g_cVerbosity) return; va_list args; va_start(args, pszFormat); char *psz = NULL; RTStrAPrintfV(&psz, pszFormat, args); va_end(args); AssertPtr(psz); LogRel(("%s", psz)); RTStrFree(psz); }