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.

103 lines
1.5 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. crt.c
  5. Abstract:
  6. This file implements certain crt apis that are not present in
  7. libcntpr.lib. This implementation is NOT multi-thread safe.
  8. Author:
  9. Wesley Witt (wesw) 23-May-1994
  10. Environment:
  11. User Mode
  12. --*/
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <windows.h>
  20. #include <time.h>
  21. #include <stdio.h>
  22. void * __cdecl
  23. malloc(
  24. size_t sz
  25. )
  26. {
  27. return RtlAllocateHeap( RtlProcessHeap(), 0, sz );
  28. }
  29. void __cdecl
  30. free(
  31. void * ptr
  32. )
  33. {
  34. RtlFreeHeap( RtlProcessHeap(), 0, ptr );
  35. }
  36. char * __cdecl
  37. ctime(
  38. const time_t *timp
  39. )
  40. {
  41. static char mnames[] = { "JanFebMarAprMayJunJulAugSepOctNovDec" };
  42. static char buf[32];
  43. LARGE_INTEGER MyTime;
  44. TIME_FIELDS TimeFields;
  45. RtlSecondsSince1970ToTime( (ULONG)*timp, &MyTime );
  46. RtlSystemTimeToLocalTime( &MyTime, &MyTime );
  47. RtlTimeToTimeFields( &MyTime, &TimeFields );
  48. strncpy( buf, &mnames[(TimeFields.Month - 1) * 3], 3 );
  49. sprintf( &buf[3], " %02d %02d:%02d:%02d %04d",
  50. TimeFields.Day, TimeFields.Hour, TimeFields.Minute,
  51. TimeFields.Second, TimeFields.Year );
  52. return buf;
  53. }
  54. time_t __cdecl
  55. time(
  56. time_t *timp
  57. )
  58. {
  59. time_t tm;
  60. LARGE_INTEGER MyTime;
  61. NtQuerySystemTime( &MyTime );
  62. RtlTimeToSecondsSince1970( &MyTime, (PULONG)&tm );
  63. if (timp) {
  64. *timp = tm;
  65. }
  66. return tm;
  67. }
  68. #ifdef __cplusplus
  69. }
  70. #endif