Example #1
0
BOOLEAN
LwRtlAnsiStringIsEqual(
    IN PANSI_STRING pString1,
    IN PANSI_STRING pString2,
    IN BOOLEAN bIsCaseSensitive
    )
{
    BOOLEAN bIsEqual = FALSE;

    if (pString1->Length != pString2->Length)
    {
        bIsEqual = FALSE;
        GOTO_CLEANUP();
    }
    else if (bIsCaseSensitive)
    {
        bIsEqual = !strncmp(pString1->Buffer, pString2->Buffer, LW_RTL_STRING_NUM_CHARS(pString1));
    }
    else
    {
        bIsEqual = !strncasecmp(pString1->Buffer, pString2->Buffer, LW_RTL_STRING_NUM_CHARS(pString1));
    }

cleanup:
    return bIsEqual;
}
Example #2
0
NTSTATUS
LwRtlAnsiStringParseULONG(
    OUT PULONG pResult,
    IN PANSI_STRING pString,
    OUT PANSI_STRING pRemainingString
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    ULONG64 value = 0;
    ULONG numChars = 0;
    ULONG index = 0;
    ANSI_STRING remaining = { 0 };

    if (!pString)
    {
        status = STATUS_INVALID_PARAMETER;
        GOTO_CLEANUP();
    }

    numChars = LW_RTL_STRING_NUM_CHARS(pString);
    for (index = 0;
         ((index < numChars) &&
          LwRtlIsDecimalDigit(pString->Buffer[index]));
         index++)
    {
        value = value * 10 + LwRtlDecimalDigitValue(pString->Buffer[index]);
        if (value > MAXULONG)
        {
            status = STATUS_INTEGER_OVERFLOW;
            GOTO_CLEANUP();
        }
    }

    if (0 == index)
    {
        status = STATUS_NOT_FOUND;
        GOTO_CLEANUP();
    }

    remaining.Buffer = &pString->Buffer[index];
    remaining.Length = pString->Length - LW_PTR_OFFSET(pString->Buffer, remaining.Buffer);
    remaining.MaximumLength = remaining.Length;

    status = STATUS_SUCCESS;

cleanup:
    if (!NT_SUCCESS(status))
    {
        if (pString)
        {
            remaining = *pString;
        }
    }

    *pResult = (ULONG) value;
    *pRemainingString = remaining;

    return status;
}
Example #3
0
static
NTSTATUS
LwIoNormalizePath(
    IN PUNICODE_STRING Path,
    OUT PUNICODE_STRING NormalPath
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    UNICODE_STRING normalPath = { 0 };
    ULONG inputIndex = 0;
    ULONG outputIndex = 0;
    ULONG count = 0;

    status = LwRtlUnicodeStringDuplicate(&normalPath, Path);
    GOTO_CLEANUP_ON_STATUS(status);

    count = LW_RTL_STRING_NUM_CHARS(&normalPath);
    for (inputIndex = outputIndex = 0; inputIndex < count; inputIndex++)
    {
        switch (normalPath.Buffer[inputIndex])
        {
        case '\\':
        case '/':
            normalPath.Buffer[outputIndex++] = '/';
            while (((inputIndex + 1) < count) &&
                   IoRtlPathIsSeparator(normalPath.Buffer[inputIndex+1]))
            {
                inputIndex++;
            }
            break;
        default:
            normalPath.Buffer[outputIndex++] = normalPath.Buffer[inputIndex];
            break;
        }
    }

    normalPath.Length = LwRtlPointerToOffset(normalPath.Buffer, &normalPath.Buffer[outputIndex]);
    normalPath.MaximumLength = normalPath.Length;

cleanup:
    if (status)
    {
        LwRtlUnicodeStringFree(&normalPath);
    }

    *NormalPath = normalPath;

    return status;
}