Exemplo n.º 1
0
/** @brief Convert a hexadecimal ASCII number into a D_UINT64 value.

    The function processes all hex digits up to a NUL-terminator, or to the
    first non-hex character.  Only hexadecimal digits are processed, so leading
    white space, or a leading "0x" prefix are not allowed.

    If pachNum points to an empty string (points to a NUL), this function will
    return NULL, and the value at *pulNum will not be modified.

    @note This function does not check for overflow.  If there are more
          significant digits than can be represented in a uint64_t variable, the
          output is unspecified.

    @param pszNum   A pointer to a constant array of hex characters.
    @param pullNum  A pointer to the location in which to store the uint64_t
                    result.  Upon return, this value will be modified ONLY if
                    the function succeeds and the returned pointer is valid (not
                    NULL).

    @return A pointer to the byte following the converted number, or NULL to
            indicate failure.
*/
const char *RedHtoULL(
    const char *pszNum,
    uint64_t   *pullNum)
{
    uint64_t    ullValue = 0U;
    const char *pszReturn = NULL;
    uint32_t    ulIdx = 0U;

    REDASSERT(pszNum != NULL);
    REDASSERT(pullNum != NULL);

    while(pszNum[ulIdx] != '\0')
    {
        char cDigit = pszNum[ulIdx];

        if(ISDIGIT(cDigit))
        {
            cDigit -= '0';
        }
        else if(ISHEXDIGITU(cDigit))
        {
            cDigit -= ('A' - 10);
        }
        else if(ISHEXDIGITL(cDigit))
        {
            cDigit -= ('a' - 10);
        }
        else
        {
            break;
        }

        REDASSERT((ullValue & UINT64_SUFFIX(0xF000000000000000)) == 0U);

        ullValue <<= 4U;
        ullValue += cDigit;

        ulIdx++;
        pszReturn = &pszNum[ulIdx];
    }

    /*  Modify the number returned only if we found one or more valid hex
        digits.
    */
    if(pszReturn != NULL)
    {
        *pullNum = ullValue;
    }

    return pszReturn;
}
Exemplo n.º 2
0
/** @brief Delete an inode.

    @param pInode   Pointer to the cached inode structure.

    @return A negated ::REDSTATUS code indicating the operation result.

    @retval 0           Operation was successful.
    @retval -RED_EBADF  The inode is free.
    @retval -RED_EINVAL @p pInode is `NULL`; or pInode->pBuffer is `NULL`.
    @retval -RED_EIO    A disk I/O error occurred.
*/
REDSTATUS RedInodeDelete(
    CINODE     *pInode)
{
    REDSTATUS   ret = 0;

    if(!CINODE_IS_MOUNTED(pInode))
    {
        ret = -RED_EINVAL;
    }
    else
    {
        if(pInode->pInodeBuf->ullSize != 0U)
        {
            ret = RedInodeDataTruncate(pInode, UINT64_SUFFIX(0));
        }

        if(ret == 0)
        {
            ret = RedInodeFree(pInode);
        }
    }

    return ret;
}