2
0

FILECHNG.CPP 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Library - File functions. *
  23. * *
  24. * File Name : FILECHNG.CPP *
  25. * *
  26. * Programmer : Scott K. Bowen *
  27. * *
  28. * Start Date : September 13, 1993 *
  29. * *
  30. * Last Update : September 13, 1993 [SKB] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * Delete_File -- Deletes the file from the disk. *
  35. * Create_File -- Creates an empty file on disk. *
  36. * Change_File_Size -- Change the size of a writting file. *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #ifndef WWSTD_H
  39. #include "wwstd.h"
  40. #endif
  41. #ifndef _FILE_H
  42. #include "_file.h"
  43. #endif
  44. #ifndef WWMEM_H
  45. #include <wwmem.h>
  46. #endif
  47. #include <io.h>
  48. /*=========================================================================*/
  49. /* The following PRIVATE functions are in this file: */
  50. /*=========================================================================*/
  51. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  52. /***************************************************************************
  53. * CREATE_FILE -- Creates an empty file on disk. *
  54. * *
  55. * *
  56. * *
  57. * INPUT: *
  58. * *
  59. * OUTPUT: *
  60. * *
  61. * WARNINGS: *
  62. * *
  63. * HISTORY: *
  64. * 05/24/1992 JLB : Created. *
  65. *=========================================================================*/
  66. WORD cdecl Create_File(BYTE const *file_name)
  67. {
  68. WORD fd;
  69. if (!file_name) return(FALSE);
  70. fd = Open_File(file_name, WRITE);
  71. if (fd != ERROR) {
  72. Close_File(fd);
  73. return(TRUE);
  74. }
  75. return(FALSE);
  76. }
  77. /***************************************************************************
  78. * DELETE_FILE -- Deletes the file from the disk. *
  79. * *
  80. * *
  81. * *
  82. * INPUT: *
  83. * *
  84. * OUTPUT: *
  85. * *
  86. * WARNINGS: *
  87. * *
  88. * HISTORY: *
  89. * 05/24/1992 JLB : Created. *
  90. *=========================================================================*/
  91. WORD cdecl Delete_File(BYTE const *file_name)
  92. {
  93. WORD index;
  94. FileDataType *filedata; // Pointer to the current FileData.
  95. FileDataType hold; // Hold buffer for record (DO NOT ACCESS DIRECTLY)
  96. if (!file_name) return(FALSE);
  97. CallingDOSInt++;
  98. ibm_setdisk(*StartPath - 'A');
  99. index = Find_File_Index(file_name);
  100. filedata = &FileDataPtr[index];
  101. if (index != ERROR && filedata->Ptr) {
  102. Mem_Free(FileCacheHeap, filedata->Ptr);
  103. filedata->Ptr = NULL;
  104. }
  105. index = !FILEDELETE(file_name);
  106. CallingDOSInt--;
  107. return(index);
  108. }
  109. /***************************************************************************
  110. * CHANGE_FILE_SIZE -- Change the size of a writting file. *
  111. * *
  112. * INPUT: WORD handle - handle of file. *
  113. * ULONG new_size - size of new handle. *
  114. * *
  115. * OUTPUT: *
  116. * *
  117. * WARNINGS: *
  118. * *
  119. * HISTORY: *
  120. * 09/13/1993 SKB : Created. *
  121. *=========================================================================*/
  122. BOOL cdecl Change_File_Size(WORD handle, ULONG new_size)
  123. {
  124. WORD entry;
  125. if (Is_Handle_Valid(handle, WRITING_NON_HANDLE, NULL)) {
  126. entry = Get_DOS_Handle(handle);
  127. if (entry != ERROR) {
  128. return(chsize(entry, new_size) != ERROR);
  129. }
  130. }
  131. return(FALSE);
  132. }