extern BOOLEAN NlsMbOemCodePageTag;
extern PUSHORT NlsLeadByteInfo;
+extern USHORT NlsOemDefaultChar;
+extern USHORT NlsUnicodeDefaultChar;
+
/* FUNCTIONS *****************************************************************/
/*
}
}
+
+/*
+ * @implemented
+ *
+ * NOTES
+ * Check the oem-string to match the uincoded-string.
+ *
+ * Functions who convert unicode strings to oem strings will set a DefaultChar from
+ * the OemCodepage when the character are unknown. So check it against the unicode string
+ * and return false when the unicode string not contain an TransDefaultChar.
+ */
+BOOLEAN
+NTAPI
+RtlpDidUnicodeToOemWork(IN PCUNICODE_STRING UnicodeString,
+ IN POEM_STRING OemString)
+{
+ ULONG i = 0;
+
+ /* Go through all characters of a string */
+ while (i < OemString->Length)
+ {
+ /* Check if it got translated into '?', but source char
+ wasn't '?' equivalent */
+ if ((OemString->Buffer[i] != 0) &&
+ (OemString->Buffer[i] == NlsOemDefaultChar) &&
+ (UnicodeString->Buffer[i] != NlsUnicodeDefaultChar))
+ {
+ /* Yes, it means unmappable characters were found */
+ return FALSE;
+ }
+
+ /* Move to the next char */
+ i++;
+ }
+
+ /* All chars were translated successfuly */
+ return TRUE;
+}
+
/*
* @unimplemented
*/
static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
const WCHAR *s = buf;
int i;
- unsigned int flags = ~0U, out_flags = 0;
+ unsigned int flags = MAXULONG, out_flags = 0;
if (len < sizeof(WCHAR))
{
UniSource->Buffer,
UniSource->Length);
- /* FIXME: Check if everything mapped correctly and
- * return STATUS_UNMAPPABLE_CHARACTER */
+ /* Check for unmapped character */
+ if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
+ Status = STATUS_UNMAPPABLE_CHARACTER;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
IN ULONG Length,
IN OUT PCHAR String)
{
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG Radix;
- CHAR temp[65];
- ULONGLONG v = Value->QuadPart;
- ULONG i;
- PCHAR tp;
- PCHAR sp;
+ ULONGLONG Val = Value->QuadPart;
+ NTSTATUS Status = STATUS_SUCCESS;
+ CHAR Buffer[65];
+ CHAR Digit;
+ ULONG Len;
+ PCHAR Pos;
- Radix = Base;
- if (Radix == 0)
- Radix = 10;
+ if (Base == 0) Base = 10;
- if ((Radix != 2) && (Radix != 8) &&
- (Radix != 10) && (Radix != 16))
- return STATUS_INVALID_PARAMETER;
+ if ((Base != 2) && (Base != 8) &&
+ (Base != 10) && (Base != 16))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
- tp = temp;
- while (v || tp == temp)
- {
- i = v % Radix;
- v = v / Radix;
- if (i < 10)
- *tp = i + '0';
- else
- *tp = i + 'A' - 10;
- tp++;
- }
+ Pos = &Buffer[64];
+ *Pos = '\0';
- if ((ULONG)((ULONG_PTR)tp - (ULONG_PTR)temp) > Length)
- return STATUS_BUFFER_OVERFLOW;
+ do
+ {
+ Pos--;
+ Digit = Val % Base;
+ Val = Val / Base;
+ if (Digit < 10)
+ *Pos = '0' + Digit;
+ else
+ *Pos = 'A' + Digit - 10;
+ }
+ while (Val != 0L);
- //_SEH2_TRY
- {
- sp = String;
- while (tp > temp)
- *sp++ = *--tp;
+ Len = &Buffer[64] - Pos;
+
+ if (Len > Length)
+ return STATUS_BUFFER_OVERFLOW;
+
+#if 1 /* It needs to be removed, when will probably use SEH in rtl */
+ if (String == NULL)
+ {
+ return STATUS_ACCESS_VIOLATION;
+ }
+#endif
- if((ULONG)((ULONG_PTR)sp - (ULONG_PTR)String) < Length)
- *sp = 0;
- }
#if 0
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
- {
- /* Get the error code */
- Status = _SEH2_GetExceptionCode();
- }
- _SEH2_END;
+ _SEH2_TRY
+ {
+#endif
+ if (Len == Length)
+ RtlCopyMemory(String, Pos, Len);
+ else
+ RtlCopyMemory(String, Pos, Len + 1);
+#if 0
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ /* Get the error code */
+ Status = _SEH2_GetExceptionCode();
+ }
+ _SEH2_END;
#endif
- return Status;
+ return Status;
}
/*
UniSource->Buffer,
UniSource->Length);
- /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+ /* Check for unmapped characters */
+ if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
+ Status = STATUS_UNMAPPABLE_CHARACTER;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{
UniSource->Buffer,
UniSource->Length);
- /* FIXME: Special check needed and return STATUS_UNMAPPABLE_CHARACTER */
+ /* Check for unmapped characters */
+ if (NT_SUCCESS(Status) && !RtlpDidUnicodeToOemWork(UniSource, OemDest))
+ Status = STATUS_UNMAPPABLE_CHARACTER;
if (!NT_SUCCESS(Status) && AllocateDestinationString)
{