| 1 | // TODO/WIPcxx . . $ `<file>/mednafen/FileStream.cpp`/ |
| 2 | |
| 3 | /* Mednafen - Multi-system Emulator |
| 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 2 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, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include "mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/ |
| 22 | #include "Stream.h"cxx . . $ `<file>/mednafen/Stream.h`/ |
| 23 | #include "FileStream.h"cxx . . $ `<file>/mednafen/FileStream.h`/ |
| 24 | |
| 25 | #include <stdarg.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | FileStreamcxx . . $ FileStream#::FileStreamcxx . . $ FileStream#FileStream(34d26762b42c433a).(const char *path, const int mode): OpenedModecxx . . $ FileStream#OpenedMode.(mode) |
| 29 | { |
| 30 | fpcxx . . $ FileStream#fp. = filestream_open(path, (mode == MODE_WRITEcxx . . $ `mednafen/Stream.h:14:9`!) ? RFILE_MODE_WRITE : RFILE_MODE_READ, -1); |
| 31 | |
| 32 | if (!fpcxx . . $ FileStream#fp.) |
| 33 | { |
| 34 | ErrnoHoldercxx . . $ ErrnoHolder# enecxx . . $ ErrnoHolder#ErrnoHolder(d4f767463ce0a6b3).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 35 | |
| 36 | throw(MDFN_Errorcxx . . $ MDFN_Error#MDFN_Error(3021f9d48bee4f7).(ene.Errnocxx . . $ ErrnoHolder#Errno(455f465bc33b4cdf).(), "Error opening file %s", ene.StrErrorcxx . . $ ErrnoHolder#StrError(a9f41ea0e82d88cf).())); |
| 37 | } |
| 38 | |
| 39 | original_pathcxx . . $ FileStream#original_path. = strdup(path); |
| 40 | } |
| 41 | |
| 42 | FileStreamcxx . . $ FileStream#::~cxx . . $ FileStream#`~FileStream`(ced63f7c635d850d).FileStreamcxx . . $ FileStream#() |
| 43 | { |
| 44 | if (original_pathcxx . . $ FileStream#original_path.) |
| 45 | freecxx . . $ free(bd21765a0afc8e3c).(original_pathcxx . . $ FileStream#original_path.); |
| 46 | original_pathcxx . . $ FileStream#original_path. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 47 | } |
| 48 | |
| 49 | uint64_tcxx . . $ uint64_t# FileStreamcxx . . $ FileStream#::attributescxx . . $ FileStream#attributes(f708dce9a8856c70).(void) |
| 50 | { |
| 51 | uint64_tcxx . . $ uint64_t# ret = ATTRIBUTE_SEEKABLEcxx . . $ Stream#ATTRIBUTE_SEEKABLE.; |
| 52 | |
| 53 | switch(OpenedModecxx . . $ FileStream#OpenedMode.) |
| 54 | { |
| 55 | case MODE_READcxx . . $ `mednafen/Stream.h:13:9`!: |
| 56 | ret |= ATTRIBUTE_READABLEcxx . . $ Stream#ATTRIBUTE_READABLE.; |
| 57 | break; |
| 58 | case MODE_WRITE_SAFEcxx . . $ `mednafen/Stream.h:15:9`!: |
| 59 | case MODE_WRITEcxx . . $ `mednafen/Stream.h:14:9`!: |
| 60 | ret |= ATTRIBUTE_WRITEABLEcxx . . $ Stream#ATTRIBUTE_WRITEABLE.; |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | uint64_tcxx . . $ uint64_t# FileStreamcxx . . $ FileStream#::readcxx . . $ FileStream#read(a1f03d5c460544d4).(void *data, uint64_tcxx . . $ uint64_t# count, bool error_on_eos) |
| 68 | { |
| 69 | if (!fpcxx . . $ FileStream#fp.) |
| 70 | return 0; |
| 71 | return filestream_read(fpcxx . . $ FileStream#fp., data, count); |
| 72 | } |
| 73 | |
| 74 | void FileStreamcxx . . $ FileStream#::writecxx . . $ FileStream#write(8c7266571c1d65cc).(const void *data, uint64_tcxx . . $ uint64_t# count) |
| 75 | { |
| 76 | if (!fpcxx . . $ FileStream#fp.) |
| 77 | return; |
| 78 | filestream_write(fpcxx . . $ FileStream#fp., data, count); |
| 79 | } |
| 80 | |
| 81 | void FileStreamcxx . . $ FileStream#::seekcxx . . $ FileStream#seek(3b75d2d14f60ac6a).(int64_tcxx . . $ int64_t# offset, int whence) |
| 82 | { |
| 83 | if (!fpcxx . . $ FileStream#fp.) |
| 84 | return; |
| 85 | filestream_seek(fpcxx . . $ FileStream#fp., offset, whence); |
| 86 | } |
| 87 | |
| 88 | int64_tcxx . . $ int64_t# FileStreamcxx . . $ FileStream#::tellcxx . . $ FileStream#tell(da6335ded91d79c2).(void) |
| 89 | { |
| 90 | if (!fpcxx . . $ FileStream#fp.) |
| 91 | return -1; |
| 92 | return filestream_tell(fpcxx . . $ FileStream#fp.); |
| 93 | } |
| 94 | |
| 95 | int64_tcxx . . $ int64_t# FileStreamcxx . . $ FileStream#::sizecxx . . $ FileStream#size(da6335ded91d79c2).(void) |
| 96 | { |
| 97 | if (!original_pathcxx . . $ FileStream#original_path.) |
| 98 | return -1; |
| 99 | |
| 100 | return path_get_size(original_pathcxx . . $ FileStream#original_path.); |
| 101 | } |
| 102 | |
| 103 | void FileStreamcxx . . $ FileStream#::closecxx . . $ FileStream#close(49f6e7a06ebc5aa8).(void) |
| 104 | { |
| 105 | if (!fpcxx . . $ FileStream#fp.) |
| 106 | return; |
| 107 | filestream_close(fpcxx . . $ FileStream#fp.); |
| 108 | } |