radare2/libr/bin/open.c
Riccardo Schirone 64d16fc506 Some code cleanup and asserts in RBin ##refactor
* libr/bin: no need to allocate RBinOptions on the heap
* bin: start using r_return_* around, that's just the beginning
* bin: remove io_owned since it's not used anywhere
* io: make r_io_bind return nothing
* bin: remove unused functions and simplify r_bin_load_io
r_bin_load_io was calling r_bin_load_io2 with UT64_MAX as sz parameter,
but r_bin_load_io2 just returns false if (st64)sz is less than 0, so
that call is actually useless and can be removed.
* bin/bin: fix some preconditions
* bin/open: fix precondition to check for bin and filename too
2018-10-21 01:27:15 +02:00

37 lines
911 B
C

/* radare2 - LGPL - Copyright 2018 - pancake */
#include <r_bin.h>
R_API int r_bin_open(RBin *bin, const char *filename, RBinOptions *bo) {
ut64 baddr = 0LL, laddr = 0LL;
int iofd = -1, rawstr = 0, xtr_idx = 0;
r_return_val_if_fail (bin && filename && bo, -1);
baddr = bo->baseaddr;
laddr = bo->loadaddr;
xtr_idx = bo->xtr_idx;
iofd = bo->iofd;
rawstr = bo->rawstr;
if (r_bin_load (bin, filename, baddr, laddr, xtr_idx, iofd, rawstr)) {
int id = bin->cur->id; // TODO rename to bd?
r_id_storage_set (bin->ids, bin->cur, id);
return id;
}
return -1;
}
R_API RBinFile *r_bin_get_file(RBin *bin, int bd) {
return r_id_storage_take (bin->ids, bd);
}
R_API bool r_bin_close(RBin *bin, int bd) {
RBinFile *bf = r_bin_get_file (bin, bd);
if (bf) {
// file_free removes the fd already.. maybe its unnecessary
r_id_storage_delete (bin->ids, bd);
r_bin_file_free (bf);
}
return false;
}