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.

110 lines
2.3 KiB

  1. /*****************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1988-1991 **/
  4. /*****************************************************************/
  5. #include <stdio.h>
  6. #include <process.h>
  7. #include <setjmp.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. VOID __cdecl
  15. main (argc, argv)
  16. int argc;
  17. char *argv[];
  18. {
  19. LARGE_INTEGER SystemTime;
  20. LARGE_INTEGER DueTime;
  21. ULONG DueTimeInMin;
  22. ULONG i;
  23. HANDLE h;
  24. BOOLEAN Status;
  25. SYSTEMTIME TimeFields;
  26. BOOLEAN Absolute;
  27. PUCHAR p;
  28. h = CreateWaitableTimer (
  29. NULL,
  30. TRUE,
  31. "TestTimer"
  32. );
  33. printf ("usage: time [-a]\n");
  34. Absolute = FALSE;
  35. DueTimeInMin = 1;
  36. while (argc) {
  37. argc--;
  38. p = *argv;
  39. argv += 1;
  40. i = atol(p);
  41. if (i) {
  42. DueTimeInMin = i;
  43. }
  44. if (strcmp (p, "-a") == 0) {
  45. Absolute = TRUE;
  46. }
  47. }
  48. NtQuerySystemTime (&SystemTime);
  49. GetSystemTime (&TimeFields);
  50. printf ("Current time is: %d:%d:%d, ",
  51. TimeFields.wHour,
  52. TimeFields.wMinute,
  53. TimeFields.wSecond
  54. );
  55. TimeFields.wMinute += DueTimeInMin;
  56. while (TimeFields.wMinute > 59) {
  57. TimeFields.wMinute -= 60;
  58. TimeFields.wHour += 1;
  59. }
  60. printf ("timer set for %d:%d:%d (%d min) %s time\n",
  61. TimeFields.wHour,
  62. TimeFields.wMinute,
  63. TimeFields.wSecond,
  64. DueTimeInMin,
  65. Absolute ? "absolute" : "relative"
  66. );
  67. //
  68. // Set timer as relative
  69. //
  70. DueTime.QuadPart = (ULONGLONG) -600000000L * DueTimeInMin;
  71. if (Absolute) {
  72. DueTime.QuadPart = SystemTime.QuadPart - DueTime.QuadPart;
  73. }
  74. Status = SetWaitableTimer (
  75. h,
  76. &DueTime,
  77. 0,
  78. NULL,
  79. NULL,
  80. TRUE
  81. );
  82. if (!Status) {
  83. printf ("SetWaitableTimer failed with %x\n", GetLastError());
  84. }
  85. printf ("Waiting\n");
  86. WaitForSingleObject (h, -1);
  87. printf ("Done\n");
  88. }