本文整理汇总了C++中RTErrConvertFromErrno函数的典型用法代码示例。如果您正苦于以下问题:C++ RTErrConvertFromErrno函数的具体用法?C++ RTErrConvertFromErrno怎么用?C++ RTErrConvertFromErrno使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTErrConvertFromErrno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RTDECL
RTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransfered)
{
PRTFILEAIOREQINTERNAL pReqInt = hReq;
RTFILEAIOREQ_VALID_RETURN(pReqInt);
RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, PREPARED, VERR_FILE_AIO_NOT_SUBMITTED);
AssertPtrNull(pcbTransfered);
int rcSol = aio_error(&pReqInt->AioCB);
Assert(rcSol != EINPROGRESS); /* Handled by our own state handling. */
if (rcSol == 0)
{
if (pcbTransfered)
*pcbTransfered = aio_return(&pReqInt->AioCB);
return VINF_SUCCESS;
}
/* An error occurred. */
return RTErrConvertFromErrno(rcSol);
}
示例2: RTR3DECL
/**
* Rewinds the stream.
*
* Stream errors will be reset on success.
*
* @returns IPRT status code.
*
* @param pStream The stream.
*
* @remarks Not all streams are rewindable and that behavior is currently
* undefined for those.
*/
RTR3DECL(int) RTStrmRewind(PRTSTREAM pStream)
{
AssertPtrReturn(pStream, VERR_INVALID_HANDLE);
AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE);
int rc;
clearerr(pStream->pFile);
errno = 0;
if (!fseek(pStream->pFile, 0, SEEK_SET))
{
ASMAtomicWriteS32(&pStream->i32Error, VINF_SUCCESS);
rc = VINF_SUCCESS;
}
else
{
rc = RTErrConvertFromErrno(errno);
ASMAtomicWriteS32(&pStream->i32Error, rc);
}
return rc;
}
示例3: RTR3DECL
RTR3DECL(int) RTThreadSetAffinity(PCRTCPUSET pCpuSet)
{
/* convert */
cpu_set_t LnxCpuSet;
CPU_ZERO(&LnxCpuSet);
if (!pCpuSet)
for (unsigned iCpu = 0; iCpu < CPU_SETSIZE; iCpu++)
CPU_SET(iCpu, &LnxCpuSet);
else
for (unsigned iCpu = 0; iCpu < RT_MIN(CPU_SETSIZE, RTCPUSET_MAX_CPUS); iCpu++)
if (RTCpuSetIsMemberByIndex(pCpuSet, iCpu))
CPU_SET(iCpu, &LnxCpuSet);
int rc = pthread_setaffinity_np(pthread_self(), sizeof(LnxCpuSet), &LnxCpuSet);
if (!rc)
return VINF_SUCCESS;
rc = errno;
if (rc == ENOENT)
return VERR_CPU_NOT_FOUND;
return RTErrConvertFromErrno(errno);
}
示例4: DECLCALLBACK
/**
* @interface_method_impl{PDMIBASE,pfnRead}
*/
static DECLCALLBACK(int) drvHostParallelRead(PPDMIHOSTPARALLELCONNECTOR pInterface, void *pvBuf, size_t cbRead, PDMPARALLELPORTMODE enmMode)
{
PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector));
int rc = VINF_SUCCESS;
# ifndef VBOX_WITH_WIN_PARPORT_SUP
int rcLnx = 0;
LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead));
rc = drvHostParallelSetMode(pThis, enmMode);
if (RT_FAILURE(rc))
return rc;
if (enmMode == PDM_PARALLEL_PORT_MODE_SPP)
{
/* Set the data lines directly. */
rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWDATA, pvBuf);
}
else
{
/* Use write interface. */
rcLnx = read(RTFileToNative(pThis->hFileDevice), pvBuf, cbRead);
}
if (RT_UNLIKELY(rcLnx < 0))
rc = RTErrConvertFromErrno(errno);
# else /* VBOX_WITH_WIN_PARPORT_SUP */
if (pThis->fParportAvail)
{
*((uint8_t*)(pvBuf)) = 0; /* Initialize the buffer. */
for (size_t i = 0; i < cbRead; i++)
{
LogFlowFunc(("calling R0 to read from parallel port\n"));
int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0);
AssertRC(rc);
*((uint8_t *)pvBuf + i) = (uint8_t)pThis->u8ReadIn;
}
}
# endif /* VBOX_WITH_WIN_PARPORT_SUP */
return rc;
}
示例5: drvHostParallelSetMode
/**
* Changes the current mode of the host parallel port.
*
* @returns VBox status code.
* @param pThis The host parallel port instance data.
* @param enmMode The mode to change the port to.
*/
static int drvHostParallelSetMode(PDRVHOSTPARALLEL pThis, PDMPARALLELPORTMODE enmMode)
{
int iMode = 0;
int rc = VINF_SUCCESS;
LogFlowFunc(("mode=%d\n", enmMode));
# ifndef VBOX_WITH_WIN_PARPORT_SUP
int rcLnx;
if (pThis->enmModeCur != enmMode)
{
switch (enmMode)
{
case PDM_PARALLEL_PORT_MODE_SPP:
iMode = IEEE1284_MODE_COMPAT;
break;
case PDM_PARALLEL_PORT_MODE_EPP_DATA:
iMode = IEEE1284_MODE_EPP | IEEE1284_DATA;
break;
case PDM_PARALLEL_PORT_MODE_EPP_ADDR:
iMode = IEEE1284_MODE_EPP | IEEE1284_ADDR;
break;
case PDM_PARALLEL_PORT_MODE_ECP:
case PDM_PARALLEL_PORT_MODE_INVALID:
default:
return VERR_NOT_SUPPORTED;
}
rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPSETMODE, &iMode);
if (RT_UNLIKELY(rcLnx < 0))
rc = RTErrConvertFromErrno(errno);
else
pThis->enmModeCur = enmMode;
}
return rc;
# else /* VBOX_WITH_WIN_PARPORT_SUP */
return VINF_SUCCESS;
# endif /* VBOX_WITH_WIN_PARPORT_SUP */
}
示例6: RTR3DECL
RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)
{
/*
* Validate.
*/
AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER);
/*
* Convert the path and query the information.
*/
char const *pszNativeFsPath;
int rc = rtPathToNative(&pszNativeFsPath, pszFsPath, NULL);
if (RT_SUCCESS(rc))
{
struct statvfs StatVFS;
RT_ZERO(StatVFS);
if (!statvfs(pszNativeFsPath, &StatVFS))
{
/*
* Calc/fake the returned values.
*/
pProperties->cbMaxComponent = StatVFS.f_namemax;
pProperties->fCaseSensitive = true;
pProperties->fCompressed = false;
pProperties->fFileCompression = false;
pProperties->fReadOnly = !!(StatVFS.f_flag & ST_RDONLY);
pProperties->fRemote = false;
pProperties->fSupportsUnicode = true;
}
else
rc = RTErrConvertFromErrno(errno);
rtPathFreeNative(pszNativeFsPath, pszFsPath);
}
LogFlow(("RTFsQueryProperties(%p:{%s}, %p:{.cbMaxComponent=%u, .fCaseSensitive=%RTbool}): returns %Rrc\n",
pszFsPath, pszFsPath, pProperties, pProperties->cbMaxComponent, pProperties->fReadOnly));
return VINF_SUCCESS;
}
示例7: RTDECL
RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq)
{
PRTFILEAIOREQINTERNAL pReqInt = hReq;
RTFILEAIOREQ_VALID_RETURN(pReqInt);
RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED);
ASMAtomicXchgBool(&pReqInt->fCanceled, true);
int rcPosix = aio_cancel(pReqInt->AioCB.aio_fildes, &pReqInt->AioCB);
if (rcPosix == AIO_CANCELED)
{
PRTFILEAIOCTXINTERNAL pCtxInt = pReqInt->pCtxInt;
/*
* Notify the waiting thread that the request was canceled.
*/
AssertMsg(VALID_PTR(pCtxInt),
("Invalid state. Request was canceled but wasn't submitted\n"));
Assert(!pCtxInt->pReqToCancel);
ASMAtomicWritePtr(&pCtxInt->pReqToCancel, pReqInt);
rtFileAioCtxWakeup(pCtxInt);
/* Wait for acknowledge. */
int rc = RTSemEventWait(pCtxInt->SemEventCancel, RT_INDEFINITE_WAIT);
AssertRC(rc);
ASMAtomicWriteNullPtr(&pCtxInt->pReqToCancel);
pReqInt->Rc = VERR_FILE_AIO_CANCELED;
RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
return VINF_SUCCESS;
}
else if (rcPosix == AIO_ALLDONE)
return VERR_FILE_AIO_COMPLETED;
else if (rcPosix == AIO_NOTCANCELED)
return VERR_FILE_AIO_IN_PROGRESS;
else
return RTErrConvertFromErrno(errno);
}
示例8: RTDECL
RTDECL(int) RTEnvSetBad(const char *pszVar, const char *pszValue)
{
AssertMsgReturn(strchr(pszVar, '=') == NULL, ("'%s'\n", pszVar), VERR_ENV_INVALID_VAR_NAME);
/* make a local copy and feed it to putenv. */
const size_t cchVar = strlen(pszVar);
const size_t cchValue = strlen(pszValue);
char *pszTmp = (char *)alloca(cchVar + cchValue + 2 + !*pszValue);
memcpy(pszTmp, pszVar, cchVar);
pszTmp[cchVar] = '=';
if (*pszValue)
memcpy(pszTmp + cchVar + 1, pszValue, cchValue + 1);
else
{
pszTmp[cchVar + 1] = ' '; /* wrong, but putenv will remove it otherwise. */
pszTmp[cchVar + 2] = '\0';
}
if (!putenv(pszTmp))
return 0;
return RTErrConvertFromErrno(errno);
}
示例9: DECLCALLBACK
/**
* interface_method_impl{SUPDRVTRACERREG,pfnProviderRegister}
*/
static DECLCALLBACK(int) vboxDtTOps_ProviderRegister(PCSUPDRVTRACERREG pThis, PSUPDRVVDTPROVIDERCORE pCore)
{
LOG_DTRACE(("%s: %p %s/%s\n", __FUNCTION__, pThis, pCore->pszModName, pCore->pszName));
AssertReturn(pCore->TracerData.DTrace.idProvider == 0, VERR_INTERNAL_ERROR_3);
PVTGDESCPROVIDER pDesc = pCore->pDesc;
dtrace_pattr_t DtAttrs;
vboxDtVtgConvAttr(&DtAttrs.dtpa_provider, &pDesc->AttrSelf);
vboxDtVtgConvAttr(&DtAttrs.dtpa_mod, &pDesc->AttrModules);
vboxDtVtgConvAttr(&DtAttrs.dtpa_func, &pDesc->AttrFunctions);
vboxDtVtgConvAttr(&DtAttrs.dtpa_name, &pDesc->AttrNames);
vboxDtVtgConvAttr(&DtAttrs.dtpa_args, &pDesc->AttrArguments);
/* Note! DTrace may call us back before dtrace_register returns, so we
have to point it to pCore->TracerData.DTrace.idProvider. */
AssertCompile(sizeof(dtrace_provider_id_t) == sizeof(pCore->TracerData.DTrace.idProvider));
int rc = dtrace_register(pCore->pszName,
&DtAttrs,
DTRACE_PRIV_KERNEL,
NULL /* cred */,
&g_vboxDtVtgProvOps,
pCore,
&pCore->TracerData.DTrace.idProvider);
if (!rc)
{
LOG_DTRACE(("%s: idProvider=%p\n", __FUNCTION__, pCore->TracerData.DTrace.idProvider));
AssertPtr(pCore->TracerData.DTrace.idProvider);
rc = VINF_SUCCESS;
}
else
{
pCore->TracerData.DTrace.idProvider = 0;
rc = RTErrConvertFromErrno(FIX_UEK_RC(rc));
}
LOG_DTRACE(("%s: returns %Rrc\n", __FUNCTION__, rc));
return rc;
}
示例10: RTDECL
RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
{
LogFlow(("RTThreadSleep: cMillies=%d\n", cMillies));
if (!cMillies)
{
/* pthread_yield() isn't part of SuS, thus this fun. */
#ifdef RT_OS_DARWIN
pthread_yield_np();
#elif defined(RT_OS_FREEBSD) /* void pthread_yield */
pthread_yield();
#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
sched_yield();
#else
if (!pthread_yield())
#endif
{
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));
return VINF_SUCCESS;
}
}
else
{
struct timespec ts;
struct timespec tsrem = {0,0};
ts.tv_nsec = (cMillies % 1000) * 1000000;
ts.tv_sec = cMillies / 1000;
if (!nanosleep(&ts, &tsrem))
{
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", VINF_SUCCESS, cMillies));
return VINF_SUCCESS;
}
}
int rc = RTErrConvertFromErrno(errno);
LogFlow(("RTThreadSleep: returning %Rrc (cMillies=%d)\n", rc, cMillies));
return rc;
}
示例11: RTR3DECL
RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
{
/*
* We can only set AccessTime and ModificationTime, so if neither
* are specified we can return immediately.
*/
if (!pAccessTime && !pModificationTime)
return VINF_SUCCESS;
/*
* Convert the input to timeval, getting the missing one if necessary,
* and call the API which does the change.
*/
struct timeval aTimevals[2];
if (pAccessTime && pModificationTime)
{
RTTimeSpecGetTimeval(pAccessTime, &aTimevals[0]);
RTTimeSpecGetTimeval(pModificationTime, &aTimevals[1]);
}
else
{
RTFSOBJINFO ObjInfo;
int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
if (RT_FAILURE(rc))
return rc;
RTTimeSpecGetTimeval(pAccessTime ? pAccessTime : &ObjInfo.AccessTime, &aTimevals[0]);
RTTimeSpecGetTimeval(pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, &aTimevals[1]);
}
if (futimes(RTFileToNative(hFile), aTimevals))
{
int rc = RTErrConvertFromErrno(errno);
Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc));
return rc;
}
return VINF_SUCCESS;
}
示例12: DECLHIDDEN
DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThread, PRTNATIVETHREAD pNativeThread)
{
/*
* Default stack size.
*/
if (!pThread->cbStack)
pThread->cbStack = 512*1024;
/*
* Create the thread.
*/
int iThreadId = _beginthread(rtThreadNativeMain, NULL, pThread->cbStack, pThread);
if (iThreadId > 0)
{
#ifdef fibGetTidPid
*pNativeThread = iThreadId | (fibGetPid() << 16);
#else
*pNativeThread = iThreadId;
#endif
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
示例13: RTR3DECL
RTR3DECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree,
uint32_t *pcbBlock, uint32_t *pcbSector)
{
struct statvfs StatVFS;
RT_ZERO(StatVFS);
if (fstatvfs(RTFileToNative(hFile), &StatVFS))
return RTErrConvertFromErrno(errno);
/*
* Calc the returned values.
*/
if (pcbTotal)
*pcbTotal = (RTFOFF)StatVFS.f_blocks * StatVFS.f_frsize;
if (pcbFree)
*pcbFree = (RTFOFF)StatVFS.f_bavail * StatVFS.f_frsize;
if (pcbBlock)
*pcbBlock = StatVFS.f_frsize;
/* no idea how to get the sector... */
if (pcbSector)
*pcbSector = 512;
return VINF_SUCCESS;
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:23,代码来源:RTFileQueryFsSizes-posix.cpp
示例14: RTDECL
RTDECL(int) RTKrnlModLoadedQueryInfo(const char *pszName, PRTKRNLMODINFO phKrnlModInfo)
{
AssertPtrReturn(pszName, VERR_INVALID_POINTER);
AssertPtrReturn(phKrnlModInfo, VERR_INVALID_POINTER);
int rc = VERR_NOT_FOUND;
int iId = -1;
struct modinfo ModInfo;
ModInfo.mi_info = MI_INFO_ALL | MI_INFO_CNT;
ModInfo.mi_id = iId;
ModInfo.mi_nextid = iId;
do
{
int rcSol = modctl(MODINFO, iId, &ModInfo);
if (rcSol < 0)
{
rc = RTErrConvertFromErrno(errno);
break;
}
if (ModInfo.mi_id != -1)
{
ModInfo.mi_name[MODMAXNAMELEN - 1] = '\0'; /* Paranoia. */
if (!RTStrCmp(pszName, &ModInfo.mi_name[0]))
{
rc = rtKrnlModSolInfoCreate(&ModInfo, phKrnlModInfo);
break;
}
}
iId = ModInfo.mi_id;
} while (iId != -1);
return rc;
}
示例15: DECL_FORCE_INLINE
//.........这里部分代码省略.........
ts.tv_nsec = (cMillies % 1000) * UINT32_C(1000000);
u64End = RTTimeSystemNanoTS() + cMillies * UINT64_C(1000000);
pTimeout = &ts;
}
/*
* Lock the mutex.
* Optimize for the uncontended case (makes 1-2 ns difference).
*/
if (RT_UNLIKELY(!ASMAtomicCmpXchgS32(&pThis->iState, 1, 0)))
{
for (;;)
{
int32_t iOld = ASMAtomicXchgS32(&pThis->iState, 2);
/*
* Was the lock released in the meantime? This is unlikely (but possible)
*/
if (RT_UNLIKELY(iOld == 0))
break;
/*
* Go to sleep.
*/
if (pTimeout && ( pTimeout->tv_sec || pTimeout->tv_nsec ))
{
#ifdef RTSEMMUTEX_STRICT
int rc9 = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true,
cMillies, RTTHREADSTATE_MUTEX, true);
if (RT_FAILURE(rc9))
return rc9;
#else
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX, true);
#endif
}
long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 2, pTimeout, NULL, 0);
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
if (RT_UNLIKELY(pThis->u32Magic != RTSEMMUTEX_MAGIC))
return VERR_SEM_DESTROYED;
/*
* Act on the wakup code.
*/
if (rc == -ETIMEDOUT)
{
Assert(pTimeout);
return VERR_TIMEOUT;
}
if (rc == 0)
/* we'll leave the loop now unless another thread is faster */;
else if (rc == -EWOULDBLOCK)
/* retry with new value. */;
else if (rc == -EINTR)
{
if (!fAutoResume)
return VERR_INTERRUPTED;
}
else
{
/* this shouldn't happen! */
AssertMsgFailed(("rc=%ld errno=%d\n", rc, errno));
return RTErrConvertFromErrno(rc);
}
/* adjust the relative timeout */
if (pTimeout)
{
int64_t i64Diff = u64End - RTTimeSystemNanoTS();
if (i64Diff < 1000)
{
rc = VERR_TIMEOUT;
break;
}
ts.tv_sec = (uint64_t)i64Diff / UINT32_C(1000000000);
ts.tv_nsec = (uint64_t)i64Diff % UINT32_C(1000000000);
}
}
/*
* When leaving this loop, iState is set to 2. This means that we gained the
* lock and there are _possibly_ some waiters. We don't know exactly as another
* thread might entered this loop at nearly the same time. Therefore we will
* call futex_wakeup once too often (if _no_ other thread entered this loop).
* The key problem is the simple futex_wait test for x != y (iState != 2) in
* our case).
*/
}
/*
* Set the owner and nesting.
*/
pThis->Owner = Self;
ASMAtomicWriteU32(&pThis->cNestings, 1);
#ifdef RTSEMMUTEX_STRICT
RTLockValidatorRecExclSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true);
#endif
return VINF_SUCCESS;
}