Windows NT 4.0 source code leak
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.

104 lines
2.1 KiB

4 years ago
  1. /*****************************************************************************
  2. * *
  3. * TF.C *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1990. *
  6. * All Rights reserved. *
  7. * *
  8. ******************************************************************************
  9. * *
  10. * Module Intent *
  11. * *
  12. * This is the Temporary File manager. It provides temporary *
  13. * files that may be written to using standard i/o calls. *
  14. * *
  15. *****************************************************************************/
  16. /*****************************************************************************
  17. *
  18. * Revision History:
  19. *
  20. * 7/25/90 LarryPo Created.
  21. *
  22. *****************************************************************************/
  23. #include "stdafx.h"
  24. #pragma hdrstop
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /*****************************************************************************
  30. * *
  31. * Prototypes *
  32. * *
  33. *****************************************************************************/
  34. PTF PtfNew(BOOL fOpen)
  35. {
  36. PTF ptf;
  37. ptf = (PTF) lcMalloc(sizeof(TF));
  38. ConfirmOrDie(ptf);
  39. memset(ptf, 0, sizeof(TF));
  40. // Theoretically, this can't fail and still return
  41. ptf->fm = FmNewTemp();
  42. ConfirmOrDie(ptf->fm);
  43. if (fOpen && !FOpenPtf(ptf, fTFWrite)) {
  44. FRemovePtf(&ptf);
  45. return NULL;
  46. }
  47. return ptf;
  48. }
  49. BOOL FOpenPtf(PTF ptf, const char* fTF)
  50. {
  51. ASSERT(ptf->fExists == TRUE || fTF == fTFWrite);
  52. ptf->pf = fopen(ptf->fm, fTF);
  53. if (!ptf->pf) {
  54. VReportError(HCERR_CANNOT_OPEN, &errHpj, ptf->fm);
  55. return FALSE;
  56. }
  57. return TRUE;
  58. }
  59. void STDCALL FRemovePtf(PTF* pptf)
  60. {
  61. PTF ptf = *pptf;
  62. if (ptf == NULL)
  63. return;
  64. if (ptf->pf)
  65. fclose(ptf->pf);
  66. if (ptf->fExists)
  67. RcUnlinkFm(ptf->fm);
  68. DisposeFm(ptf->fm);
  69. lcFree(ptf);
  70. pptf = NULL;
  71. }
  72. #ifdef _DEBUG
  73. void VerifyPtf(PTF ptf )
  74. {
  75. if (ptf == NULL)
  76. return;
  77. // Check ptf->pf
  78. if (ptf->fExists)
  79. ASSERT(FValidFm(ptf->fm));
  80. //VerifyFm(ptf->fm);
  81. }
  82. #endif /* DEBUG */