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.

154 lines
4.0 KiB

  1. //*****************************************************************************
  2. //
  3. // Name: util.c
  4. //
  5. // Description: Utility routines for the common library.
  6. //
  7. // History:
  8. // 01/21/94 JayPh Created.
  9. // 26-Nov-96 MohsinA io.h,fcntl.h for CR-LF fix.
  10. //*****************************************************************************
  11. //*****************************************************************************
  12. //
  13. // Copyright (c) 1994-2000 by Microsoft Corp. All rights reserved.
  14. //
  15. //*****************************************************************************
  16. //
  17. // Include Files
  18. //
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #include <windows.h>
  23. #include <stdio.h>
  24. #include <io.h>
  25. #include <fcntl.h>
  26. #include "common2.h"
  27. //*****************************************************************************
  28. //
  29. // Name: InetEqual
  30. //
  31. // Description: Compares to ip addresses to determine whether they are equal.
  32. //
  33. // Parameters: uchar *Inet1: pointer to array of uchars.
  34. // uchar *Inet2: pointer to array of uchars.
  35. //
  36. // Returns: ulong: TRUE if the addresses are equal, FALSE otherwise.
  37. //
  38. // History:
  39. // 12/16/93 JayPh Created.
  40. //
  41. //*****************************************************************************
  42. ulong InetEqual( uchar *Inet1, uchar *Inet2 )
  43. {
  44. if ( ( Inet1[0] == Inet2[0] ) && ( Inet1[1] == Inet2[1] ) &&
  45. ( Inet1[2] == Inet2[2] ) && ( Inet1[3] == Inet2[3] ) )
  46. {
  47. return TRUE;
  48. }
  49. return FALSE;
  50. }
  51. //*****************************************************************************
  52. //
  53. // Name: PutMsg
  54. //
  55. // Description: Reads a message resource, formats it in the current language
  56. // and displays the message.
  57. //
  58. // Parameters: ulong Handle: device to display message on.
  59. // ulong MsgNum: ID of the message resource.
  60. //
  61. // Returns: ulong: number of characters displayed.
  62. //
  63. // History:
  64. // 01/05/93 JayPh Created.
  65. // 25-Nov-96. MohsinA, CR-CR-LF => CR-LF = 0d0a = \r\n.
  66. //
  67. //*****************************************************************************
  68. ulong
  69. PutMsg(ulong Handle, ulong MsgNum, ... )
  70. {
  71. ulong msglen;
  72. uchar *vp;
  73. va_list arglist;
  74. FILE * pfile;
  75. va_start( arglist, MsgNum );
  76. msglen = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER
  77. | FORMAT_MESSAGE_FROM_HMODULE
  78. // | FORMAT_MESSAGE_MAX_WIDTH_MASK
  79. ,
  80. NULL,
  81. MsgNum,
  82. 0L, // Default country ID.
  83. (LPTSTR)&vp,
  84. 0,
  85. &arglist );
  86. if ( msglen == 0 )
  87. {
  88. return ( 0 );
  89. }
  90. pfile = (Handle == 2) ? stderr : stdout;
  91. _setmode( _fileno(pfile), O_BINARY );
  92. // Convert vp to oem
  93. CharToOemBuff((LPCTSTR)vp,(LPSTR)vp,strlen(vp));
  94. fprintf( pfile, "%s", vp );
  95. LocalFree( vp );
  96. return ( msglen );
  97. }
  98. //*****************************************************************************
  99. //
  100. // Name: LoadMsg
  101. //
  102. // Description: Reads and formats a message resource and returns a pointer
  103. // to the buffer containing the formatted message. It is the
  104. // responsibility of the caller to free the buffer.
  105. //
  106. // Parameters: ulong MsgNum: ID of the message resource.
  107. //
  108. // Returns: uchar *: pointer to the message buffer, NULL if error.
  109. //
  110. // History:
  111. // 01/05/93 JayPh Created.
  112. //
  113. //*****************************************************************************
  114. uchar *LoadMsg( ulong MsgNum, ... )
  115. {
  116. ulong msglen;
  117. uchar *vp;
  118. va_list arglist;
  119. va_start( arglist, MsgNum );
  120. msglen = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  121. FORMAT_MESSAGE_FROM_HMODULE,
  122. NULL,
  123. MsgNum,
  124. 0L, // Default country ID.
  125. (LPTSTR)&vp,
  126. 0,
  127. &arglist );
  128. if ( msglen == 0 )
  129. {
  130. return(0);
  131. }
  132. return ( vp );
  133. }