Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
1.8 KiB

  1. /*
  2. * String.c
  3. *
  4. * Author: BreenH
  5. *
  6. * String utilities.
  7. */
  8. /*
  9. * Includes
  10. */
  11. #include "precomp.h"
  12. #include "tsutil.h"
  13. #include "tsutilnt.h"
  14. /*
  15. * Function Implementations
  16. */
  17. PSTR WINAPI
  18. AllocateAndCopyStringA(
  19. PCSTR pString
  20. )
  21. {
  22. NTSTATUS Status;
  23. PSTR pCopy;
  24. ASSERT(pString != NULL);
  25. pCopy = NULL;
  26. Status = NtAllocateAndCopyStringA(&pCopy, pString);
  27. if (NT_SUCCESS(Status))
  28. {
  29. return(pCopy);
  30. }
  31. else
  32. {
  33. SetLastError(RtlNtStatusToDosError(Status));
  34. return(NULL);
  35. }
  36. }
  37. PWSTR WINAPI
  38. AllocateAndCopyStringW(
  39. PCWSTR pString
  40. )
  41. {
  42. NTSTATUS Status;
  43. PWSTR pCopy;
  44. ASSERT(pString != NULL);
  45. pCopy = NULL;
  46. Status = NtAllocateAndCopyStringW(&pCopy, pString);
  47. if (NT_SUCCESS(Status))
  48. {
  49. return(pCopy);
  50. }
  51. else
  52. {
  53. SetLastError(RtlNtStatusToDosError(Status));
  54. return(NULL);
  55. }
  56. }
  57. BOOL WINAPI
  58. ConvertAnsiToUnicode(
  59. PWSTR *ppUnicodeString,
  60. PCSTR pAnsiString
  61. )
  62. {
  63. BOOL fRet;
  64. NTSTATUS Status;
  65. Status = NtConvertAnsiToUnicode(ppUnicodeString, pAnsiString);
  66. if (NT_SUCCESS(Status))
  67. {
  68. fRet = TRUE;
  69. }
  70. else
  71. {
  72. fRet = FALSE;
  73. SetLastError(RtlNtStatusToDosError(Status));
  74. }
  75. return(fRet);
  76. }
  77. BOOL WINAPI
  78. ConvertUnicodeToAnsi(
  79. PSTR *ppAnsiString,
  80. PCWSTR pUnicodeString
  81. )
  82. {
  83. BOOL fRet;
  84. NTSTATUS Status;
  85. Status = NtConvertUnicodeToAnsi(ppAnsiString, pUnicodeString);
  86. if (NT_SUCCESS(Status))
  87. {
  88. fRet = TRUE;
  89. }
  90. else
  91. {
  92. fRet = FALSE;
  93. SetLastError(RtlNtStatusToDosError(Status));
  94. }
  95. return(fRet);
  96. }