mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-19 09:32:33 +00:00
Properly use RAII to reduce complication
This commit is contained in:
@@ -19,9 +19,8 @@ static fpos_t strm_seek(void *v, fpos_t off, int whence) {
|
||||
|
||||
static int strm_close(void *v) {
|
||||
auto strm = reinterpret_cast<stream *>(v);
|
||||
int ret = strm->close();
|
||||
delete strm;
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *open_stream(stream *strm) {
|
||||
@@ -46,8 +45,8 @@ off_t stream::seek(off_t off, int whence) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stream::close() {
|
||||
return 0;
|
||||
filter_stream::~filter_stream() {
|
||||
if (fp) fclose(fp);
|
||||
}
|
||||
|
||||
int filter_stream::read(void *buf, size_t len) {
|
||||
@@ -58,12 +57,6 @@ int filter_stream::write(const void *buf, size_t len) {
|
||||
return fwrite(buf, 1, len, fp);
|
||||
}
|
||||
|
||||
int filter_stream::close() {
|
||||
int ret = fclose(fp);
|
||||
fp = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void filter_stream::set_base(FILE *f) {
|
||||
if (fp) fclose(fp);
|
||||
fp = f;
|
||||
|
Reference in New Issue
Block a user