mirror of
https://github.com/reactos/reactos.git
synced 2025-01-05 22:12:46 +00:00
[RTL]
- Remove qsort, its already in crt. - Fix a number of MSVC/64 bit issues svn path=/trunk/; revision=53776
This commit is contained in:
parent
cca6723c9a
commit
16bab3bc1c
13 changed files with 43 additions and 265 deletions
|
@ -42,7 +42,6 @@ list(APPEND SOURCE
|
||||||
ppb.c
|
ppb.c
|
||||||
process.c
|
process.c
|
||||||
propvar.c
|
propvar.c
|
||||||
qsort.c
|
|
||||||
random.c
|
random.c
|
||||||
rangelist.c
|
rangelist.c
|
||||||
registry.c
|
registry.c
|
||||||
|
|
|
@ -461,7 +461,7 @@ RtlAddAce(
|
||||||
{
|
{
|
||||||
PACE Ace;
|
PACE Ace;
|
||||||
PACE Current;
|
PACE Current;
|
||||||
ULONG NewAceCount;
|
WORD NewAceCount;
|
||||||
ULONG Index;
|
ULONG Index;
|
||||||
PAGED_CODE_RTL();
|
PAGED_CODE_RTL();
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ RtlAddAce(
|
||||||
(ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
|
(ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
|
||||||
|
|
||||||
Acl->AceCount = Acl->AceCount + NewAceCount;
|
Acl->AceCount = Acl->AceCount + NewAceCount;
|
||||||
Acl->AclRevision = AclRevision;
|
Acl->AclRevision = (BYTE)AclRevision;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -737,8 +737,8 @@ RtlCreateAcl(
|
||||||
}
|
}
|
||||||
|
|
||||||
AclSize = ROUND_UP(AclSize, 4);
|
AclSize = ROUND_UP(AclSize, 4);
|
||||||
Acl->AclSize = AclSize;
|
Acl->AclSize = (WORD)AclSize;
|
||||||
Acl->AclRevision = AclRevision;
|
Acl->AclRevision = (BYTE)AclRevision;
|
||||||
Acl->AceCount = 0;
|
Acl->AceCount = 0;
|
||||||
Acl->Sbz1 = 0;
|
Acl->Sbz1 = 0;
|
||||||
Acl->Sbz2 = 0;
|
Acl->Sbz2 = 0;
|
||||||
|
@ -850,7 +850,7 @@ RtlSetInformationAcl(PACL Acl,
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
Acl->AclRevision = Info->AclRevision;
|
Acl->AclRevision = (BYTE)Info->AclRevision;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ RtlpGetLengthOfRunClear(
|
||||||
BitScanForward(&BitPos, Value);
|
BitScanForward(&BitPos, Value);
|
||||||
|
|
||||||
/* Calculate length up to where we read */
|
/* Calculate length up to where we read */
|
||||||
Length = (Buffer - BitMapHeader->Buffer) * 32 - StartingIndex;
|
Length = (ULONG)(Buffer - BitMapHeader->Buffer) * 32 - StartingIndex;
|
||||||
Length += BitPos - 32;
|
Length += BitPos - 32;
|
||||||
|
|
||||||
/* Make sure we don't go past the last bit */
|
/* Make sure we don't go past the last bit */
|
||||||
|
@ -130,7 +130,7 @@ RtlpGetLengthOfRunSet(
|
||||||
BitScanForward(&BitPos, InvValue);
|
BitScanForward(&BitPos, InvValue);
|
||||||
|
|
||||||
/* Calculate length up to where we read */
|
/* Calculate length up to where we read */
|
||||||
Length = (Buffer - BitMapHeader->Buffer) * 32 - StartingIndex;
|
Length = (ULONG)(Buffer - BitMapHeader->Buffer) * 32 - StartingIndex;
|
||||||
Length += BitPos - 32;
|
Length += BitPos - 32;
|
||||||
|
|
||||||
/* Make sure we don't go past the last bit */
|
/* Make sure we don't go past the last bit */
|
||||||
|
|
|
@ -407,7 +407,7 @@ NTAPI
|
||||||
RtlSetCriticalSectionSpinCount(PRTL_CRITICAL_SECTION CriticalSection,
|
RtlSetCriticalSectionSpinCount(PRTL_CRITICAL_SECTION CriticalSection,
|
||||||
ULONG SpinCount)
|
ULONG SpinCount)
|
||||||
{
|
{
|
||||||
ULONG OldCount = CriticalSection->SpinCount;
|
ULONG OldCount = (ULONG)CriticalSection->SpinCount;
|
||||||
|
|
||||||
/* Set to parameter if MP, or to 0 if this is Uniprocessor */
|
/* Set to parameter if MP, or to 0 if this is Uniprocessor */
|
||||||
CriticalSection->SpinCount = (NtCurrentPeb()->NumberOfProcessors > 1) ? SpinCount : 0;
|
CriticalSection->SpinCount = (NtCurrentPeb()->NumberOfProcessors > 1) ? SpinCount : 0;
|
||||||
|
|
|
@ -36,7 +36,7 @@ RtlCreateQueryDebugBuffer(IN ULONG Size,
|
||||||
}
|
}
|
||||||
|
|
||||||
Buf->ViewBaseClient = Buf;
|
Buf->ViewBaseClient = Buf;
|
||||||
Buf->ViewSize = ViewSize;
|
Buf->ViewSize = (ULONG)ViewSize;
|
||||||
|
|
||||||
DPRINT("RtlCQDB: BA: %p BS: 0x%lx\n", Buf->ViewBaseClient, Buf->ViewSize);
|
DPRINT("RtlCQDB: BA: %p BS: 0x%lx\n", Buf->ViewBaseClient, Buf->ViewSize);
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ RtlpQueryRemoteProcessModules(HANDLE ProcessHandle,
|
||||||
|
|
||||||
p = strrchr(ModulePtr->FullPathName, '\\');
|
p = strrchr(ModulePtr->FullPathName, '\\');
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
ModulePtr->OffsetToFileName = p - ModulePtr->FullPathName + 1;
|
ModulePtr->OffsetToFileName = (USHORT)(p - ModulePtr->FullPathName + 1);
|
||||||
else
|
else
|
||||||
ModulePtr->OffsetToFileName = 0;
|
ModulePtr->OffsetToFileName = 0;
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
|
||||||
IN OUT PRTL_DEBUG_INFORMATION Buf)
|
IN OUT PRTL_DEBUG_INFORMATION Buf)
|
||||||
{
|
{
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
ULONG Pid = (ULONG_PTR) NtCurrentTeb()->ClientId.UniqueProcess;
|
ULONG Pid = (ULONG)(ULONG_PTR) NtCurrentTeb()->ClientId.UniqueProcess;
|
||||||
|
|
||||||
Buf->Flags = DebugInfoMask;
|
Buf->Flags = DebugInfoMask;
|
||||||
Buf->OffsetFree = sizeof(RTL_DEBUG_INFORMATION);
|
Buf->OffsetFree = sizeof(RTL_DEBUG_INFORMATION);
|
||||||
|
|
|
@ -57,7 +57,7 @@ vDbgPrintExWithPrefixInternal(IN PCCH Prefix,
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
STRING DebugString;
|
STRING DebugString;
|
||||||
CHAR Buffer[512];
|
CHAR Buffer[512];
|
||||||
ULONG Length, PrefixLength;
|
SIZE_T Length, PrefixLength;
|
||||||
EXCEPTION_RECORD ExceptionRecord;
|
EXCEPTION_RECORD ExceptionRecord;
|
||||||
|
|
||||||
/* Check if we should print it or not */
|
/* Check if we should print it or not */
|
||||||
|
@ -110,7 +110,7 @@ vDbgPrintExWithPrefixInternal(IN PCCH Prefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build the string */
|
/* Build the string */
|
||||||
DebugString.Length = Length;
|
DebugString.Length = (USHORT)Length;
|
||||||
DebugString.Buffer = Buffer;
|
DebugString.Buffer = Buffer;
|
||||||
|
|
||||||
/* First, let the debugger know as well */
|
/* First, let the debugger know as well */
|
||||||
|
@ -281,7 +281,7 @@ DbgPrompt(IN PCCH Prompt,
|
||||||
Input.Buffer = Response;
|
Input.Buffer = Response;
|
||||||
|
|
||||||
/* Setup the output string */
|
/* Setup the output string */
|
||||||
Output.Length = strlen(Prompt);
|
Output.Length = (USHORT)strlen(Prompt);
|
||||||
Output.Buffer = (PCHAR)Prompt;
|
Output.Buffer = (PCHAR)Prompt;
|
||||||
|
|
||||||
/* Call the system service */
|
/* Call the system service */
|
||||||
|
@ -380,9 +380,9 @@ DbgCommandString(IN PCCH Name,
|
||||||
|
|
||||||
/* Setup the strings */
|
/* Setup the strings */
|
||||||
NameString.Buffer = (PCHAR)Name;
|
NameString.Buffer = (PCHAR)Name;
|
||||||
NameString.Length = strlen(Name);
|
NameString.Length = (USHORT)strlen(Name);
|
||||||
CommandString.Buffer = (PCHAR)Command;
|
CommandString.Buffer = (PCHAR)Command;
|
||||||
CommandString.Length = strlen(Command);
|
CommandString.Length = (USHORT)strlen(Command);
|
||||||
|
|
||||||
/* Send them to the debugger */
|
/* Send them to the debugger */
|
||||||
DebugService2(&NameString, &CommandString, BREAKPOINT_COMMAND_STRING);
|
DebugService2(&NameString, &CommandString, BREAKPOINT_COMMAND_STRING);
|
||||||
|
|
|
@ -119,7 +119,7 @@ RtlGenerate8dot3Name(IN PUNICODE_STRING Name,
|
||||||
{
|
{
|
||||||
c = 0;
|
c = 0;
|
||||||
RtlUpcaseUnicodeToOemN(&c, sizeof(CHAR), &Count, &Name->Buffer[i], sizeof(WCHAR));
|
RtlUpcaseUnicodeToOemN(&c, sizeof(CHAR), &Count, &Name->Buffer[i], sizeof(WCHAR));
|
||||||
if (Count != 1 || c == 0 || RtlpIsShortIllegal(Name->Buffer[i]))
|
if (Count != 1 || c == 0 || RtlpIsShortIllegal(c))
|
||||||
{
|
{
|
||||||
ExtBuffer[ExtLength++] = L'_';
|
ExtBuffer[ExtLength++] = L'_';
|
||||||
}
|
}
|
||||||
|
@ -211,12 +211,12 @@ RtlGenerate8dot3Name(IN PUNICODE_STRING Name,
|
||||||
j += IndexLength + 1;
|
j += IndexLength + 1;
|
||||||
|
|
||||||
memcpy(Name8dot3->Buffer + j, ExtBuffer, ExtLength * sizeof(WCHAR));
|
memcpy(Name8dot3->Buffer + j, ExtBuffer, ExtLength * sizeof(WCHAR));
|
||||||
Name8dot3->Length = (j + ExtLength) * sizeof(WCHAR);
|
Name8dot3->Length = (USHORT)(j + ExtLength) * sizeof(WCHAR);
|
||||||
|
|
||||||
DPRINT("Name8dot3: '%wZ'\n", Name8dot3);
|
DPRINT("Name8dot3: '%wZ'\n", Name8dot3);
|
||||||
|
|
||||||
/* Update context */
|
/* Update context */
|
||||||
Context->NameLength = CopyLength;
|
Context->NameLength = (UCHAR)CopyLength;
|
||||||
Context->ExtensionLength = ExtLength;
|
Context->ExtensionLength = ExtLength;
|
||||||
memcpy(Context->NameBuffer, NameBuffer, CopyLength * sizeof(WCHAR));
|
memcpy(Context->NameBuffer, NameBuffer, CopyLength * sizeof(WCHAR));
|
||||||
memcpy(Context->ExtensionBuffer, ExtBuffer, ExtLength * sizeof(WCHAR));
|
memcpy(Context->ExtensionBuffer, ExtBuffer, ExtLength * sizeof(WCHAR));
|
||||||
|
|
|
@ -163,11 +163,11 @@ RtlExpandEnvironmentStrings_U(PWSTR Environment,
|
||||||
if (Tail != 0)
|
if (Tail != 0)
|
||||||
{
|
{
|
||||||
Variable.MaximumLength =
|
Variable.MaximumLength =
|
||||||
Variable.Length = (VariableEnd - (SourceBuffer + 1)) * sizeof(WCHAR);
|
Variable.Length = (USHORT)(VariableEnd - (SourceBuffer + 1)) * sizeof(WCHAR);
|
||||||
Variable.Buffer = SourceBuffer + 1;
|
Variable.Buffer = SourceBuffer + 1;
|
||||||
|
|
||||||
Value.Length = 0;
|
Value.Length = 0;
|
||||||
Value.MaximumLength = DestMax * sizeof(WCHAR);
|
Value.MaximumLength = (USHORT)DestMax * sizeof(WCHAR);
|
||||||
Value.Buffer = DestBuffer;
|
Value.Buffer = DestBuffer;
|
||||||
|
|
||||||
Status = RtlQueryEnvironmentVariable_U(Environment, &Variable,
|
Status = RtlQueryEnvironmentVariable_U(Environment, &Variable,
|
||||||
|
@ -227,7 +227,7 @@ RtlExpandEnvironmentStrings_U(PWSTR Environment,
|
||||||
else
|
else
|
||||||
ReturnStatus = STATUS_BUFFER_TOO_SMALL;
|
ReturnStatus = STATUS_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
Destination->Length = (DestBuffer - Destination->Buffer) * sizeof(WCHAR);
|
Destination->Length = (USHORT)(DestBuffer - Destination->Buffer) * sizeof(WCHAR);
|
||||||
if (Length != NULL)
|
if (Length != NULL)
|
||||||
*Length = TotalLength * sizeof(WCHAR);
|
*Length = TotalLength * sizeof(WCHAR);
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ RtlSetEnvironmentVariable(PWSTR *Environment,
|
||||||
{
|
{
|
||||||
MEMORY_BASIC_INFORMATION mbi;
|
MEMORY_BASIC_INFORMATION mbi;
|
||||||
UNICODE_STRING var;
|
UNICODE_STRING var;
|
||||||
int hole_len, new_len, env_len = 0;
|
size_t hole_len, new_len, env_len = 0;
|
||||||
WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0;
|
WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0;
|
||||||
PWSTR head = NULL;
|
PWSTR head = NULL;
|
||||||
SIZE_T size = 0, new_size;
|
SIZE_T size = 0, new_size;
|
||||||
|
@ -328,7 +328,7 @@ RtlSetEnvironmentVariable(PWSTR *Environment,
|
||||||
}
|
}
|
||||||
if (*wcs)
|
if (*wcs)
|
||||||
{
|
{
|
||||||
var.Length = (wcs - var.Buffer) * sizeof(WCHAR);
|
var.Length = (USHORT)(wcs - var.Buffer) * sizeof(WCHAR);
|
||||||
var.MaximumLength = var.Length;
|
var.MaximumLength = var.Length;
|
||||||
val = ++wcs;
|
val = ++wcs;
|
||||||
wcs += wcslen(wcs);
|
wcs += wcslen(wcs);
|
||||||
|
@ -532,14 +532,14 @@ RtlQueryEnvironmentVariable_U(PWSTR Environment,
|
||||||
}
|
}
|
||||||
if (*wcs)
|
if (*wcs)
|
||||||
{
|
{
|
||||||
var.Length = var.MaximumLength = (wcs - var.Buffer) * sizeof(WCHAR);
|
var.Length = var.MaximumLength = (USHORT)(wcs - var.Buffer) * sizeof(WCHAR);
|
||||||
val = ++wcs;
|
val = ++wcs;
|
||||||
wcs += wcslen(wcs);
|
wcs += wcslen(wcs);
|
||||||
DPRINT("Search at :%S\n", wcs);
|
DPRINT("Search at :%S\n", wcs);
|
||||||
|
|
||||||
if (RtlEqualUnicodeString(&var, Name, TRUE))
|
if (RtlEqualUnicodeString(&var, Name, TRUE))
|
||||||
{
|
{
|
||||||
Value->Length = (wcs - val) * sizeof(WCHAR);
|
Value->Length = (USHORT)(wcs - val) * sizeof(WCHAR);
|
||||||
if (Value->Length <= Value->MaximumLength)
|
if (Value->Length <= Value->MaximumLength)
|
||||||
{
|
{
|
||||||
memcpy(Value->Buffer, val,
|
memcpy(Value->Buffer, val,
|
||||||
|
|
|
@ -47,7 +47,7 @@ RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString)
|
||||||
{
|
{
|
||||||
UNICODE_STRING DeviceName;
|
UNICODE_STRING DeviceName;
|
||||||
PWCHAR Start, End, Ptr;
|
PWCHAR Start, End, Ptr;
|
||||||
ULONG DeviceNameLength;
|
SIZE_T DeviceNameLength;
|
||||||
|
|
||||||
/* Validate the input */
|
/* Validate the input */
|
||||||
if (!PathString) return 0;
|
if (!PathString) return 0;
|
||||||
|
@ -363,9 +363,9 @@ RtlpWin32NTNameToNtPathName_U(IN PUNICODE_STRING DosPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build the final NT path string */
|
/* Build the final NT path string */
|
||||||
NtPath->Length = DosLength;
|
NtPath->Length = (USHORT)DosLength;
|
||||||
NtPath->Buffer = NewBuffer;
|
NtPath->Buffer = NewBuffer;
|
||||||
NtPath->MaximumLength = DosLength + sizeof(UNICODE_NULL);
|
NtPath->MaximumLength = (USHORT)DosLength + sizeof(UNICODE_NULL);
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,8 +502,8 @@ RtlpDosPathNameToRelativeNtPathName_Ustr(IN BOOLEAN HaveRelative,
|
||||||
|
|
||||||
/* Setup the actual NT path string and terminate it */
|
/* Setup the actual NT path string and terminate it */
|
||||||
NtName->Buffer = NewBuffer;
|
NtName->Buffer = NewBuffer;
|
||||||
NtName->Length = Length;
|
NtName->Length = (USHORT)Length;
|
||||||
NtName->MaximumLength = MaxLength;
|
NtName->MaximumLength = (USHORT)MaxLength;
|
||||||
NewBuffer[LengthChars] = UNICODE_NULL;
|
NewBuffer[LengthChars] = UNICODE_NULL;
|
||||||
DPRINT("new buffer: %S\n", NewBuffer);
|
DPRINT("new buffer: %S\n", NewBuffer);
|
||||||
DPRINT("NT Name: %wZ\n", NtName);
|
DPRINT("NT Name: %wZ\n", NtName);
|
||||||
|
@ -550,7 +550,7 @@ RtlpDosPathNameToRelativeNtPathName_Ustr(IN BOOLEAN HaveRelative,
|
||||||
{
|
{
|
||||||
Length = ((cd->DosPath.Length / sizeof(WCHAR)) - PrefixCut) + ((InputPathType == 1) ? 8 : 4);
|
Length = ((cd->DosPath.Length / sizeof(WCHAR)) - PrefixCut) + ((InputPathType == 1) ? 8 : 4);
|
||||||
RelativeName->RelativeName.Buffer = NewBuffer + Length;
|
RelativeName->RelativeName.Buffer = NewBuffer + Length;
|
||||||
RelativeName->RelativeName.Length = NtName->Length - (Length * sizeof(WCHAR));
|
RelativeName->RelativeName.Length = NtName->Length - (USHORT)(Length * sizeof(WCHAR));
|
||||||
RelativeName->RelativeName.MaximumLength = RelativeName->RelativeName.Length;
|
RelativeName->RelativeName.MaximumLength = RelativeName->RelativeName.Length;
|
||||||
RelativeName->ContainingDirectory = cd->Handle;
|
RelativeName->ContainingDirectory = cd->Handle;
|
||||||
}
|
}
|
||||||
|
@ -875,7 +875,7 @@ RtlSetCurrentDirectory_U(PUNICODE_STRING dir)
|
||||||
IO_STATUS_BLOCK iosb;
|
IO_STATUS_BLOCK iosb;
|
||||||
PCURDIR cd;
|
PCURDIR cd;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
ULONG size;
|
USHORT size;
|
||||||
HANDLE handle = NULL;
|
HANDLE handle = NULL;
|
||||||
PWSTR ptr;
|
PWSTR ptr;
|
||||||
|
|
||||||
|
@ -1055,7 +1055,7 @@ static ULONG get_full_path_helper(
|
||||||
LPWSTR buffer,
|
LPWSTR buffer,
|
||||||
ULONG size)
|
ULONG size)
|
||||||
{
|
{
|
||||||
ULONG reqsize = 0, mark = 0, dep = 0, deplen;
|
SIZE_T reqsize = 0, mark = 0, dep = 0, deplen;
|
||||||
LPWSTR ins_str = NULL;
|
LPWSTR ins_str = NULL;
|
||||||
LPCWSTR ptr;
|
LPCWSTR ptr;
|
||||||
const UNICODE_STRING* cd;
|
const UNICODE_STRING* cd;
|
||||||
|
@ -1103,7 +1103,7 @@ static ULONG get_full_path_helper(
|
||||||
var.MaximumLength = 4 * sizeof(WCHAR);
|
var.MaximumLength = 4 * sizeof(WCHAR);
|
||||||
var.Buffer = tmp;
|
var.Buffer = tmp;
|
||||||
val.Length = 0;
|
val.Length = 0;
|
||||||
val.MaximumLength = size;
|
val.MaximumLength = (USHORT)size;
|
||||||
val.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
|
val.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
|
||||||
if (val.Buffer == NULL)
|
if (val.Buffer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -1221,12 +1221,12 @@ static ULONG get_full_path_helper(
|
||||||
if (ins_str != tmp && ins_str != cd->Buffer)
|
if (ins_str != tmp && ins_str != cd->Buffer)
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, ins_str);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, ins_str);
|
||||||
|
|
||||||
collapse_path( buffer, mark );
|
collapse_path( buffer, (ULONG)mark );
|
||||||
reqsize = wcslen(buffer) * sizeof(WCHAR);
|
reqsize = wcslen(buffer) * sizeof(WCHAR);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
RtlReleasePebLock();
|
RtlReleasePebLock();
|
||||||
return reqsize;
|
return (ULONG)reqsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,220 +0,0 @@
|
||||||
/*
|
|
||||||
* COPYRIGHT:
|
|
||||||
*-
|
|
||||||
* Copyright (c) 1992, 1993
|
|
||||||
* The Regents of the University of California. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by the University of
|
|
||||||
* California, Berkeley and its contributors.
|
|
||||||
* 4. Neither the name of the University nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
||||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* PROJECT: ReactOS system libraries
|
|
||||||
* PURPOSE: Unicode Conversion Routines
|
|
||||||
* FILE: lib/rtl/qsort.c
|
|
||||||
* PROGRAMMER: Adapted from CygWin newlib 2000-03-12.
|
|
||||||
*/
|
|
||||||
#include <rtl.h>
|
|
||||||
|
|
||||||
/* FIXME: these types should be from the default includes */
|
|
||||||
|
|
||||||
typedef int (__cdecl* _pfunccmp_t) (const void *, const void *);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
|
|
||||||
*/
|
|
||||||
#define swapcode(TYPE, parmi, parmj, n) { \
|
|
||||||
long i = (n) / sizeof (TYPE); \
|
|
||||||
register TYPE *pi = (TYPE *) (parmi); \
|
|
||||||
register TYPE *pj = (TYPE *) (parmj); \
|
|
||||||
do { \
|
|
||||||
register TYPE t = *pi; \
|
|
||||||
*pi++ = *pj; \
|
|
||||||
*pj++ = t; \
|
|
||||||
} while (--i > 0); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
|
|
||||||
es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
|
|
||||||
|
|
||||||
static __inline void
|
|
||||||
swapfunc (
|
|
||||||
char * a,
|
|
||||||
char * b,
|
|
||||||
int n,
|
|
||||||
int swaptype
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if(swaptype <= 1)
|
|
||||||
swapcode(long, a, b, n)
|
|
||||||
else
|
|
||||||
swapcode(char, a, b, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
#define swap(a, b) \
|
|
||||||
if (swaptype == 0) { \
|
|
||||||
long t = *(long *)(a); \
|
|
||||||
*(long *)(a) = *(long *)(b); \
|
|
||||||
*(long *)(b) = t; \
|
|
||||||
} else \
|
|
||||||
swapfunc(a, b, es, swaptype)
|
|
||||||
|
|
||||||
#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
|
|
||||||
|
|
||||||
static __inline char *
|
|
||||||
med3 (
|
|
||||||
char * a,
|
|
||||||
char * b,
|
|
||||||
char * c,
|
|
||||||
_pfunccmp_t cmp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return cmp(a, b) < 0 ?
|
|
||||||
(cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
|
|
||||||
:(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* EXPORTED */
|
|
||||||
void
|
|
||||||
__cdecl
|
|
||||||
qsort (
|
|
||||||
void * a,
|
|
||||||
size_t n,
|
|
||||||
size_t es,
|
|
||||||
_pfunccmp_t cmp
|
|
||||||
)
|
|
||||||
{
|
|
||||||
char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
|
|
||||||
int d, r, swaptype, swap_cnt;
|
|
||||||
|
|
||||||
loop: SWAPINIT(a, es);
|
|
||||||
swap_cnt = 0;
|
|
||||||
if (n < 7)
|
|
||||||
{
|
|
||||||
for ( pm = (char *) a + es;
|
|
||||||
pm < (char *) a + n * es;
|
|
||||||
pm += es
|
|
||||||
)
|
|
||||||
{
|
|
||||||
for ( pl = pm;
|
|
||||||
pl > (char *) a && cmp(pl - es, pl) > 0;
|
|
||||||
pl -= es
|
|
||||||
)
|
|
||||||
{
|
|
||||||
swap(pl, pl - es);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pm = (char *) a + (n / 2) * es;
|
|
||||||
if (n > 7)
|
|
||||||
{
|
|
||||||
pl = (char *) a;
|
|
||||||
pn = (char *) a + (n - 1) * es;
|
|
||||||
if (n > 40)
|
|
||||||
{
|
|
||||||
d = (n / 8) * es;
|
|
||||||
pl = med3(pl, pl + d, pl + 2 * d, cmp);
|
|
||||||
pm = med3(pm - d, pm, pm + d, cmp);
|
|
||||||
pn = med3(pn - 2 * d, pn - d, pn, cmp);
|
|
||||||
}
|
|
||||||
pm = med3(pl, pm, pn, cmp);
|
|
||||||
}
|
|
||||||
swap(a, pm);
|
|
||||||
pa = pb = (char *) a + es;
|
|
||||||
|
|
||||||
pc = pd = (char *) a + (n - 1) * es;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
while (pb <= pc && (r = cmp(pb, a)) <= 0)
|
|
||||||
{
|
|
||||||
if (r == 0)
|
|
||||||
{
|
|
||||||
swap_cnt = 1;
|
|
||||||
swap(pa, pb);
|
|
||||||
pa += es;
|
|
||||||
}
|
|
||||||
pb += es;
|
|
||||||
}
|
|
||||||
while (pb <= pc && (r = cmp(pc, a)) >= 0)
|
|
||||||
{
|
|
||||||
if (r == 0)
|
|
||||||
{
|
|
||||||
swap_cnt = 1;
|
|
||||||
swap(pc, pd);
|
|
||||||
pd -= es;
|
|
||||||
}
|
|
||||||
pc -= es;
|
|
||||||
}
|
|
||||||
if (pb > pc)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
swap(pb, pc);
|
|
||||||
swap_cnt = 1;
|
|
||||||
pb += es;
|
|
||||||
pc -= es;
|
|
||||||
}
|
|
||||||
if (swap_cnt == 0) /* Switch to insertion sort */
|
|
||||||
{
|
|
||||||
for ( pm = (char *) a + es;
|
|
||||||
pm < (char *) a + n * es;
|
|
||||||
pm += es
|
|
||||||
)
|
|
||||||
{
|
|
||||||
for ( pl = pm;
|
|
||||||
pl > (char *) a && cmp(pl - es, pl) > 0;
|
|
||||||
pl -= es
|
|
||||||
)
|
|
||||||
{
|
|
||||||
swap(pl, pl - es);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pn = (char *) a + n * es;
|
|
||||||
r = min(pa - (char *)a, pb - pa);
|
|
||||||
vecswap(a, pb - r, r);
|
|
||||||
r = min(pd - pc, pn - pd - es);
|
|
||||||
vecswap(pb, pn - r, r);
|
|
||||||
if ((r = pb - pa) > es)
|
|
||||||
{
|
|
||||||
qsort(a, r / es, es, cmp);
|
|
||||||
}
|
|
||||||
if ((r = pd - pc) > es)
|
|
||||||
{
|
|
||||||
/* Iterate rather than recurse to save stack space */
|
|
||||||
a = pn - r;
|
|
||||||
n = r / es;
|
|
||||||
goto loop;
|
|
||||||
}
|
|
||||||
/* qsort(pn - r, r / es, es, cmp);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* EOF */
|
|
|
@ -81,7 +81,6 @@
|
||||||
<file>ppb.c</file>
|
<file>ppb.c</file>
|
||||||
<file>process.c</file>
|
<file>process.c</file>
|
||||||
<file>propvar.c</file>
|
<file>propvar.c</file>
|
||||||
<file>qsort.c</file>
|
|
||||||
<file>random.c</file>
|
<file>random.c</file>
|
||||||
<file>rangelist.c</file>
|
<file>rangelist.c</file>
|
||||||
<file>registry.c</file>
|
<file>registry.c</file>
|
||||||
|
|
|
@ -120,7 +120,7 @@ RtlCreateSecurityDescriptor(OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
|
||||||
return STATUS_UNKNOWN_REVISION;
|
return STATUS_UNKNOWN_REVISION;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSD->Revision = Revision;
|
pSD->Revision = SECURITY_DESCRIPTOR_REVISION1;
|
||||||
pSD->Sbz1 = 0;
|
pSD->Sbz1 = 0;
|
||||||
pSD->Control = 0;
|
pSD->Control = 0;
|
||||||
pSD->Owner = NULL;
|
pSD->Owner = NULL;
|
||||||
|
@ -230,7 +230,7 @@ RtlCreateSecurityDescriptorRelative (OUT PISECURITY_DESCRIPTOR_RELATIVE Security
|
||||||
return STATUS_UNKNOWN_REVISION;
|
return STATUS_UNKNOWN_REVISION;
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityDescriptor->Revision = Revision;
|
SecurityDescriptor->Revision = SECURITY_DESCRIPTOR_REVISION1;
|
||||||
SecurityDescriptor->Sbz1 = 0;
|
SecurityDescriptor->Sbz1 = 0;
|
||||||
SecurityDescriptor->Control = SE_SELF_RELATIVE;
|
SecurityDescriptor->Control = SE_SELF_RELATIVE;
|
||||||
SecurityDescriptor->Owner = 0;
|
SecurityDescriptor->Owner = 0;
|
||||||
|
|
|
@ -332,7 +332,7 @@ RtlConvertSidToUnicodeString(PUNICODE_STRING String,
|
||||||
{
|
{
|
||||||
WCHAR Buffer[256];
|
WCHAR Buffer[256];
|
||||||
PWSTR wcs;
|
PWSTR wcs;
|
||||||
ULONG Length;
|
SIZE_T Length;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
PISID Sid = Sid_;
|
PISID Sid = Sid_;
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ RtlConvertSidToUnicodeString(PUNICODE_STRING String,
|
||||||
if (Length > String->MaximumLength)
|
if (Length > String->MaximumLength)
|
||||||
return STATUS_BUFFER_TOO_SMALL;
|
return STATUS_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
String->Length = Length;
|
String->Length = (USHORT)Length;
|
||||||
RtlCopyMemory (String->Buffer,
|
RtlCopyMemory (String->Buffer,
|
||||||
Buffer,
|
Buffer,
|
||||||
Length);
|
Length);
|
||||||
|
|
Loading…
Reference in a new issue