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.

168 lines
2.3 KiB

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "windows.h"
  5. #define FAILURE printf("FAIL: %d\n",__LINE__);exit(1)
  6. int __cdecl main(int argc,char *argv[]) {
  7. HANDLE hFile;
  8. char *myPort = "COM1";
  9. COMMCONFIG myConf,spareConf;
  10. DWORD sizeOfConf;
  11. DCB myDcb,spareDcb;
  12. if (argc > 1) {
  13. myPort = argv[1];
  14. }
  15. if ((hFile = CreateFile(
  16. myPort,
  17. GENERIC_READ | GENERIC_WRITE,
  18. 0,
  19. NULL,
  20. CREATE_ALWAYS,
  21. FILE_ATTRIBUTE_NORMAL,
  22. NULL
  23. )) == ((HANDLE)-1)) {
  24. FAILURE;
  25. }
  26. if (!GetCommConfig(
  27. hFile,
  28. NULL,
  29. &sizeOfConf
  30. )) {
  31. FAILURE;
  32. }
  33. if (!sizeOfConf) {
  34. FAILURE;
  35. }
  36. if (sizeOfConf != sizeof(COMMCONFIG)) {
  37. FAILURE;
  38. }
  39. if (!GetCommState(
  40. hFile,
  41. &myDcb
  42. )) {
  43. FAILURE;
  44. }
  45. RtlZeroMemory(
  46. &myConf,
  47. sizeOfConf
  48. );
  49. myConf.dwSize = sizeOfConf;
  50. if (!GetCommConfig(
  51. hFile,
  52. &myConf,
  53. &sizeOfConf
  54. )) {
  55. FAILURE;
  56. }
  57. if (memcmp(&myConf.dcb,&myDcb,sizeof(DCB))) {
  58. FAILURE;
  59. }
  60. if (myConf.dwSize != sizeof(COMMCONFIG)) {
  61. FAILURE;
  62. }
  63. if (myConf.wVersion != 0) {
  64. FAILURE;
  65. }
  66. if (myConf.pProviderSubType != 0) {
  67. FAILURE;
  68. }
  69. if (myConf.dwProviderOffset != 0) {
  70. FAILURE;
  71. }
  72. if (myConf.dwProviderSize != 0) {
  73. FAILURE;
  74. }
  75. if (myConf.wcProviderData[1]) {
  76. FAILURE;
  77. }
  78. //
  79. // Make sure the commconfig has not changed after a call to set
  80. // and that the comm state is also the same.
  81. //
  82. spareConf = myConf;
  83. spareDcb = myDcb;
  84. if (!SetCommConfig(
  85. hFile,
  86. (PVOID)&myConf,
  87. sizeOfConf
  88. )) {
  89. FAILURE;
  90. }
  91. if (memcmp(&spareConf,&myConf,sizeof(COMMCONFIG))) {
  92. FAILURE;
  93. }
  94. if (!GetCommState(
  95. hFile,
  96. &myDcb
  97. )) {
  98. FAILURE;
  99. }
  100. if (memcmp(&spareDcb,&myDcb,sizeof(DCB))) {
  101. FAILURE;
  102. }
  103. return 1;
  104. }