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.

188 lines
4.6 KiB

  1. /*
  2. * caldos.c
  3. *
  4. * Copyright (c) 1991, Microsoft Corporation
  5. *
  6. * DESCRIPTION
  7. *
  8. * This file is/was ported from ..\..\progman\pmdos.c
  9. * It contains two routines used by
  10. *
  11. * MODIFICATION HISTORY
  12. * Initial Version: x/x/90 Author Unknown, since he didn't feel
  13. * like commenting the code...
  14. *
  15. * NT 32b Version: 1/9/91 Jeff Pack
  16. * Intitial port to begin.
  17. *
  18. * WARNING: since this is NOT for DOS, I'm making it soley 32bit aware.
  19. * Following functions not ported
  20. * IsRemovable() is in pmcomman.c (already ifdef'd in asm code)
  21. * IsRemote() is in pmcomman.c (ditto!)
  22. *
  23. */
  24. #include "cal.h"
  25. #include <string.h>
  26. #include <time.h>
  27. /*** GetCurDrive -- get current drive number.
  28. *
  29. *
  30. *
  31. * INT GetCurDrive(VOID)
  32. *
  33. * ENTRY - VOID
  34. *
  35. * EXIT - INT CurrentDrive - drive number of current drive (0=a, etc).
  36. *
  37. * SYNOPSIS - calls GetCurrentDirectory, must parse returned string
  38. * for either drive letter, or UNC path. If UNC I gotta
  39. * somehow, covert UNC path to drive letter to drive number.
  40. * WARNINGS - not DBCS aware!
  41. * EFFECTS -
  42. *
  43. */
  44. INT GetCurDrive(VOID)
  45. {
  46. DWORD nBufferLength = 128;
  47. DWORD dwReturnCode;
  48. LPSTR lpszLocalBuffer;
  49. INT iDriveNumber;
  50. /* alloc local, non-moveable, zero filled buffer */
  51. lpszLocalBuffer = (LPSTR) LocalAlloc(LMEM_ZEROINIT, nBufferLength);
  52. if(lpszLocalBuffer == NULL){
  53. OutputDebugStringA("<GetCurDrive> LocalAlloc FAILed\n");
  54. }
  55. GetCurDrive1:
  56. dwReturnCode = GetCurrentDirectory(nBufferLength, lpszLocalBuffer);
  57. /*
  58. * Failed for reason other than bufferlength too small
  59. */
  60. if(dwReturnCode == 0){
  61. OutputDebugStringA("<GetCurDrive> GetCurrentDirectory() FAILed\n");
  62. }
  63. /*
  64. * test for success, if dwReturnCode is > buffer, then need
  65. * increase buffer
  66. */
  67. if(dwReturnCode > nBufferLength){
  68. lpszLocalBuffer = (LPSTR) LocalReAlloc(lpszLocalBuffer,
  69. nBufferLength + 128,
  70. LMEM_ZEROINIT | LMEM_MOVEABLE);
  71. if(lpszLocalBuffer == NULL){
  72. OutputDebugStringA("<GetCurDrive> LocalAlloc FAILed\n");
  73. }
  74. else{
  75. nBufferLength += 128;
  76. }
  77. goto GetCurDrive1;
  78. }
  79. /*
  80. * Finally lpszLocalBuffer has string containing current directory.
  81. * Now must parse string for ":" or "\\" for drive letter or UNC
  82. * If : then get drive letter, and convert to number a=0, b=1, etc.
  83. * If \\ then gotta enumerate net drives, to learn what drive letter
  84. * corresponds to that UNC path.
  85. */
  86. /* check for drive letter */
  87. if(lpszLocalBuffer[1] == ':'){
  88. /* is drive letter, proceed */
  89. iDriveNumber = lpszLocalBuffer[1] - 'A'; /* convert letter > number */
  90. }
  91. else{
  92. /* must be UNC path */
  93. /* BUG BUG need write code to convert UNC path */
  94. OutputDebugStringA("<GetCurDrive> Got UNC path, didnt expect, and no code!\n");
  95. }
  96. LocalFree(lpszLocalBuffer);
  97. return(iDriveNumber);
  98. }
  99. /*** FDosDelete -- Delete named file.
  100. *
  101. * INT FDosDelete(LPSTR lpszFileToDelete)
  102. *
  103. * ENTRY - LPSTR lpszFileToDelete - filename to delete.
  104. *
  105. * EXIT - INT xxx - returns (0) if success
  106. *
  107. * SYNOPSIS - calls win32 DeleteFile.
  108. * WARNINGS -
  109. * EFFECTS -
  110. *
  111. */
  112. INT FDosDelete(LPSTR lpszFileToDelete)
  113. {
  114. BOOL bReturnCode;
  115. bReturnCode = DeleteFile(lpszFileToDelete);
  116. if(bReturnCode){
  117. return(0);
  118. }
  119. else{
  120. return(1);
  121. }
  122. }
  123. /*** FDosRename -- Rename file.
  124. *
  125. * INT FDosRename(LPSTR lpszOrgFileName, LPSTR lpszNewFileName)
  126. *
  127. * ENTRY - LPSTR lpszOrgFileName - origianl filename.
  128. * LPSTR lpszNewFileName - New filename.
  129. *
  130. * EXIT - INT xxx - returns (0) if success
  131. *
  132. * SYNOPSIS - calls win32 MoveFile.
  133. * WARNINGS -
  134. * EFFECTS -
  135. *
  136. */
  137. INT FDosRename(LPSTR lpszOrgFileName, LPSTR lpszNewFileName)
  138. {
  139. BOOL bReturnCode;
  140. /* rename file */
  141. bReturnCode = MoveFile(lpszOrgFileName, lpszNewFileName);
  142. if(bReturnCode){
  143. return(0); /* success */
  144. }
  145. else{
  146. return(1);
  147. }
  148. }
  149. VOID ReadClock(D3*pd3, TM*pmin)
  150. {
  151. time_t t;
  152. struct tm *ptm;
  153. time(&t);
  154. ptm = localtime(&t);
  155. *pmin = (TM)(ptm->tm_min + ptm->tm_hour * 60);
  156. pd3->wMonth = (WORD)ptm->tm_mon;
  157. //- ReadClock: fixed to be day of month 0-30.
  158. pd3->wDay = ptm->tm_mday - 1;
  159. //- ReadClock: fixed to be years since 1980 instead of since 0.
  160. pd3->wYear = ptm->tm_year - 80;
  161. }