Source code of Windows XP (NT5)
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.

82 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. Support.c
  5. Abstract:
  6. This module contains support functions for the client side of the
  7. Win32 Registry APIs. That is:
  8. - MakeSemiUniqueName
  9. Author:
  10. David J. Gilman (davegi) 15-Nov-1991
  11. --*/
  12. #include <rpc.h>
  13. #include "regrpc.h"
  14. #include <stdio.h>
  15. #define REG_SUNAME_FORMAT_STRING "Win32Reg.%08x.%08x"
  16. BOOL
  17. MakeSemiUniqueName (
  18. OUT PUNICODE_STRING Name,
  19. IN DWORD Sequence
  20. )
  21. /*++
  22. Routine Description:
  23. Forms a name that is very probably unique in the system, based on
  24. the current process and thread id and a sequence provided by the
  25. caller.
  26. Arguments:
  27. Name - Supplies a unicode string where the name will be put.
  28. This string must contain a valid buffer of size
  29. MAX_PATH * sizeof(WCHAR)
  30. Sequence - Supplies a sequence number that will be appended to
  31. the name. If a name happens not to be unique, the
  32. caller can try again with other sequence numbers.
  33. Return Value:
  34. BOOL - Returns TRUE if a name was obtained.
  35. --*/
  36. {
  37. CHAR NameBuffer[ MAX_PATH ];
  38. ANSI_STRING AnsiName;
  39. NTSTATUS NtStatus;
  40. ASSERT( Name && Name->Buffer );
  41. sprintf( NameBuffer,
  42. REG_SUNAME_FORMAT_STRING,
  43. HandleToUlong(NtCurrentTeb()->ClientId.UniqueProcess),
  44. Sequence
  45. );
  46. RtlInitAnsiString( &AnsiName, NameBuffer );
  47. NtStatus = RtlAnsiStringToUnicodeString(
  48. Name,
  49. &AnsiName,
  50. FALSE
  51. );
  52. return NT_SUCCESS( NtStatus );
  53. }