本文整理汇总了C++中RTStrDup函数的典型用法代码示例。如果您正苦于以下问题:C++ RTStrDup函数的具体用法?C++ RTStrDup怎么用?C++ RTStrDup使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTStrDup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RTR3DECL
RTR3DECL(int) RTS3Create(PRTS3 ppS3, const char* pszAccessKey, const char* pszSecretKey, const char* pszBaseUrl, const char* pszUserAgent /* = NULL */)
{
AssertPtrReturn(ppS3, VERR_INVALID_POINTER);
/* We need at least an URL to connect with */
if (pszBaseUrl == NULL ||
pszBaseUrl[0] == 0)
return VERR_INVALID_PARAMETER;
/* In windows, this will init the winsock stuff */
if (curl_global_init(CURL_GLOBAL_ALL) != 0)
return VERR_INTERNAL_ERROR;
CURL* pCurl = curl_easy_init();
if (!pCurl)
return VERR_INTERNAL_ERROR;
PRTS3INTERNAL pS3Int = (PRTS3INTERNAL)RTMemAllocZ(sizeof(RTS3INTERNAL));
if (pS3Int == NULL)
return VERR_NO_MEMORY;
pS3Int->u32Magic = RTS3_MAGIC;
pS3Int->pCurl = pCurl;
pS3Int->pszAccessKey = RTStrDup(pszAccessKey);
pS3Int->pszSecretKey = RTStrDup(pszSecretKey);
pS3Int->pszBaseUrl = RTStrDup(pszBaseUrl);
if (pszUserAgent)
pS3Int->pszUserAgent = RTStrDup(pszUserAgent);
*ppS3 = (RTS3)pS3Int;
return VINF_SUCCESS;
}
示例2: ScmSvnSetProperty
/**
* Schedules the setting of a property.
*
* @returns IPRT status code.
* @retval VERR_INVALID_STATE if not a SVN WC file.
* @param pState The rewrite state to work on.
* @param pszName The name of the property to set.
* @param pszValue The value. NULL means deleting it.
*/
int ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue)
{
/*
* Update any existing entry first.
*/
size_t i = pState->cSvnPropChanges;
while (i-- > 0)
if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName))
{
if (!pszValue)
{
RTStrFree(pState->paSvnPropChanges[i].pszValue);
pState->paSvnPropChanges[i].pszValue = NULL;
}
else
{
char *pszCopy;
int rc = RTStrDupEx(&pszCopy, pszValue);
if (RT_FAILURE(rc))
return rc;
pState->paSvnPropChanges[i].pszValue = pszCopy;
}
return VINF_SUCCESS;
}
/*
* Insert a new entry.
*/
i = pState->cSvnPropChanges;
if ((i % 32) == 0)
{
void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP));
if (!pvNew)
return VERR_NO_MEMORY;
pState->paSvnPropChanges = (PSCMSVNPROP)pvNew;
}
pState->paSvnPropChanges[i].pszName = RTStrDup(pszName);
pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL;
if ( pState->paSvnPropChanges[i].pszName
&& (pState->paSvnPropChanges[i].pszValue || !pszValue) )
pState->cSvnPropChanges = i + 1;
else
{
RTStrFree(pState->paSvnPropChanges[i].pszName);
pState->paSvnPropChanges[i].pszName = NULL;
RTStrFree(pState->paSvnPropChanges[i].pszValue);
pState->paSvnPropChanges[i].pszValue = NULL;
return VERR_NO_MEMORY;
}
return VINF_SUCCESS;
}
示例3: AssertPtrReturn
int DnDURIList::AppendNativePath(const char *pszPath, uint32_t fFlags)
{
AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
int rc;
char *pszPathNative = RTStrDup(pszPath);
if (pszPathNative)
{
RTPathChangeToUnixSlashes(pszPathNative, true /* fForce */);
char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */,
pszPathNative, NULL /* pszQuery */, NULL /* pszFragment */);
if (pszPathURI)
{
rc = AppendURIPath(pszPathURI, fFlags);
RTStrFree(pszPathURI);
}
else
rc = VERR_INVALID_PARAMETER;
RTStrFree(pszPathNative);
}
else
rc = VERR_NO_MEMORY;
return rc;
}
示例4: RTSemFastMutexRequest
PUSBDEVICE USBProxyBackendUsbIp::getDevices(void)
{
PUSBDEVICE pFirst = NULL;
PUSBDEVICE *ppNext = &pFirst;
/* Create a deep copy of the device list. */
RTSemFastMutexRequest(m->hMtxDevices);
PUSBDEVICE pCur = m->pUsbDevicesCur;
while (pCur)
{
PUSBDEVICE pNew = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
if (pNew)
{
pNew->pszManufacturer = RTStrDup(pCur->pszManufacturer);
pNew->pszProduct = RTStrDup(pCur->pszProduct);
if (pCur->pszSerialNumber)
pNew->pszSerialNumber = RTStrDup(pCur->pszSerialNumber);
pNew->pszBackend = RTStrDup(pCur->pszBackend);
pNew->pszAddress = RTStrDup(pCur->pszAddress);
pNew->idVendor = pCur->idVendor;
pNew->idProduct = pCur->idProduct;
pNew->bcdDevice = pCur->bcdDevice;
pNew->bcdUSB = pCur->bcdUSB;
pNew->bDeviceClass = pCur->bDeviceClass;
pNew->bDeviceSubClass = pCur->bDeviceSubClass;
pNew->bDeviceProtocol = pCur->bDeviceProtocol;
pNew->bNumConfigurations = pCur->bNumConfigurations;
pNew->enmState = pCur->enmState;
pNew->u64SerialHash = pCur->u64SerialHash;
pNew->bBus = pCur->bBus;
pNew->bPort = pCur->bPort;
pNew->enmSpeed = pCur->enmSpeed;
/* link it */
pNew->pNext = NULL;
pNew->pPrev = *ppNext;
*ppNext = pNew;
ppNext = &pNew->pNext;
}
pCur = pCur->pNext;
}
RTSemFastMutexRelease(m->hMtxDevices);
return pFirst;
}
示例5: rtS3ExtractAllKeys
static void rtS3ExtractAllKeys(xmlDocPtr pDoc, xmlNodePtr pNode, PCRTS3KEYENTRY *ppKeys)
{
if (pNode != NULL)
{
PRTS3KEYENTRY pPrevKey = NULL;
xmlNodePtr pCurKey = pNode->xmlChildrenNode;
while (pCurKey != NULL)
{
if ((!xmlStrcmp(pCurKey->name, (const xmlChar *)"Contents")))
{
PRTS3KEYENTRY pKey = (PRTS3KEYENTRY)RTMemAllocZ(sizeof(RTS3KEYENTRY));
pKey->pPrev = pPrevKey;
if (pPrevKey)
pPrevKey->pNext = pKey;
else
(*ppKeys) = pKey;
pPrevKey = pKey;
xmlNodePtr pCurCont = pCurKey->xmlChildrenNode;
while (pCurCont != NULL)
{
if ((!xmlStrcmp(pCurCont->name, (const xmlChar *)"Key")))
{
xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1);
pKey->pszName = RTStrDup((const char*)pszKey);
xmlFree(pszKey);
}
if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"LastModified")))
{
xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1);
pKey->pszLastModified = RTStrDup((const char*)pszKey);
xmlFree(pszKey);
}
if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"Size")))
{
xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1);
pKey->cbFile = RTStrToUInt64((const char*)pszKey);
xmlFree(pszKey);
}
pCurCont = pCurCont->next;
}
}
pCurKey = pCurKey->next;
}
}
}
示例6: RT_ZERO
/**
* Search for a USB test device and return the device path.
*
* @returns Path to the USB test device or NULL if none was found.
*/
static char *usbTestFindDevice(void)
{
/*
* Very crude and quick way to search for the correct test device.
* Assumption is that the path looks like /dev/bus/usb/%3d/%3d.
*/
uint8_t uBus = 1;
bool fBusExists = false;
char aszDevPath[64];
RT_ZERO(aszDevPath);
do
{
RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d", uBus);
fBusExists = RTPathExists(aszDevPath);
if (fBusExists)
{
/* Check every device. */
bool fDevExists = false;
uint8_t uDev = 1;
do
{
RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d/%03d", uBus, uDev);
fDevExists = RTPathExists(aszDevPath);
if (fDevExists)
{
RTFILE hFileDev;
int rc = RTFileOpen(&hFileDev, aszDevPath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
if (RT_SUCCESS(rc))
{
USBDEVDESC DevDesc;
rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL);
RTFileClose(hFileDev);
if ( RT_SUCCESS(rc)
&& DevDesc.idVendor == 0x0525
&& DevDesc.idProduct == 0xa4a0)
return RTStrDup(aszDevPath);
}
}
uDev++;
} while (fDevExists);
}
uBus++;
} while (fBusExists);
return NULL;
}
示例7: m
MemoryBuf::MemoryBuf (const char *aBuf, size_t aLen, const char *aURI /* = NULL */)
: m (new Data())
{
if (aBuf == NULL)
throw EInvalidArg (RT_SRC_POS);
m->buf = aBuf;
m->len = aLen;
m->uri = RTStrDup (aURI);
}
示例8: tst1
static void tst1(size_t cTest, size_t cchDigits, char chSep)
{
RTTestISubF("tst #%u (digits: %u; sep: %c)", cTest, cchDigits, chSep ? chSep : ' ');
/* We try to create max possible + one. */
size_t cTimes = 1;
for (size_t i = 0; i < cchDigits; ++i)
cTimes *= 10;
/* Allocate the result array. */
char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *));
RTTESTI_CHECK_RETV(papszNames != NULL);
int rc = VERR_INTERNAL_ERROR;
/* The test loop. */
size_t i;
for (i = 0; i < cTimes; i++)
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_FAILURE(rc))
break;
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VINF_SUCCESS);
if (RT_FAILURE(rc))
{
RTTestIFailed("RTDirCreateUniqueNumbered(%s) call #%u -> %Rrc\n", szName, i, rc);
break;
}
RTTESTI_CHECK(papszNames[i] = RTStrDup(szName));
if (!papszNames[i])
break;
RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]);
}
/* Try to create one more, which shouldn't be possible. */
if (RT_SUCCESS(rc))
{
char szName[RTPATH_MAX];
RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS);
if (RT_SUCCESS(rc))
RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VERR_ALREADY_EXISTS);
}
/* cleanup */
while (i-- > 0)
{
RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS);
RTStrFree(papszNames[i]);
}
RTMemTmpFree(papszNames);
}
示例9: RTR3DECL
RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation)
{
PRTHTTPINTERNAL pHttpInt = hHttp;
RTHTTP_VALID_RETURN(pHttpInt);
if (!pHttpInt->pszRedirLocation)
return VERR_HTTP_NOT_FOUND;
*ppszRedirLocation = RTStrDup(pHttpInt->pszRedirLocation);
return VINF_SUCCESS;
}
示例10: RTUriFilePath
/* static */
int DnDURIObject::RebaseURIPath(RTCString &strPathAbs,
const RTCString &strBaseOld /* = "" */,
const RTCString &strBaseNew /* = "" */)
{
char *pszPath = RTUriFilePath(strPathAbs.c_str());
if (!pszPath) /* No URI? */
pszPath = RTStrDup(strPathAbs.c_str());
int rc;
if (pszPath)
{
const char *pszPathStart = pszPath;
const char *pszBaseOld = strBaseOld.c_str();
if ( pszBaseOld
&& RTPathStartsWith(pszPath, pszBaseOld))
{
pszPathStart += strlen(pszBaseOld);
}
rc = VINF_SUCCESS;
if (RT_SUCCESS(rc))
{
char *pszPathNew = RTPathJoinA(strBaseNew.c_str(), pszPathStart);
if (pszPathNew)
{
char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */,
pszPathNew /* pszPath */,
NULL /* pszQuery */, NULL /* pszFragment */);
if (pszPathURI)
{
LogFlowFunc(("Rebasing \"%s\" to \"%s\"\n", strPathAbs.c_str(), pszPathURI));
strPathAbs = RTCString(pszPathURI) + "\r\n";
RTStrFree(pszPathURI);
}
else
rc = VERR_INVALID_PARAMETER;
RTStrFree(pszPathNew);
}
else
rc = VERR_NO_MEMORY;
}
RTStrFree(pszPath);
}
else
rc = VERR_NO_MEMORY;
return rc;
}
示例11: rtS3ExtractAllBuckets
static void rtS3ExtractAllBuckets(xmlDocPtr pDoc, xmlNodePtr pNode, PCRTS3BUCKETENTRY *ppBuckets)
{
pNode = rtS3FindNode(pNode, "Buckets");
if (pNode != NULL)
{
PRTS3BUCKETENTRY pPrevBucket = NULL;
xmlNodePtr pCurBucket = pNode->xmlChildrenNode;
while (pCurBucket != NULL)
{
if ((!xmlStrcmp(pCurBucket->name, (const xmlChar *)"Bucket")))
{
PRTS3BUCKETENTRY pBucket = (PRTS3BUCKETENTRY)RTMemAllocZ(sizeof(RTS3BUCKETENTRY));
pBucket->pPrev = pPrevBucket;
if (pPrevBucket)
pPrevBucket->pNext = pBucket;
else
(*ppBuckets) = pBucket;
pPrevBucket = pBucket;
xmlNodePtr pCurCont = pCurBucket->xmlChildrenNode;
while (pCurCont != NULL)
{
if ((!xmlStrcmp(pCurCont->name, (const xmlChar *)"Name")))
{
xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1);
pBucket->pszName = RTStrDup((const char*)pszKey);
xmlFree(pszKey);
}
if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"CreationDate")))
{
xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1);
pBucket->pszCreationDate = RTStrDup((const char*)pszKey);
xmlFree(pszKey);
}
pCurCont = pCurCont->next;
}
}
pCurBucket = pCurBucket->next;
}
}
}
示例12: alock
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);
}
示例13: rtR0DbgKrnlInfoModRetainEx
/**
* 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;
}
示例14: autoCaller
STDMETHODIMP VFSExplorer::CdUp(IProgress **aProgress)
{
AutoCaller autoCaller(this);
if (FAILED(autoCaller.rc())) return autoCaller.rc();
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(Bstr(strUpPath).raw(), aProgress);
}
示例15: rtTarFileCreateForWrite
/* Only used for write handles. */
static PRTTARFILEINTERNAL rtTarFileCreateForWrite(PRTTARINTERNAL pInt, const char *pszFilename, uint32_t fOpen)
{
PRTTARFILEINTERNAL pFileInt = (PRTTARFILEINTERNAL)RTMemAllocZ(sizeof(RTTARFILEINTERNAL));
if (!pFileInt)
return NULL;
pFileInt->u32Magic = RTTARFILE_MAGIC;
pFileInt->pTar = pInt;
pFileInt->fOpenMode = fOpen;
pFileInt->pszFilename = RTStrDup(pszFilename);
pFileInt->hVfsIos = NIL_RTVFSIOSTREAM;
if (pFileInt->pszFilename)
return pFileInt;
RTMemFree(pFileInt);
return NULL;
}