mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 04:05:06 +00:00
* Return "" instead of NULL when possible in core input
- myfgets returns length(str)+1 - r_line fix for empty lines interpreted as EOF * RAPIfication in io.c * Fix the way to build the tests programs in io/t/{cat|read4}
This commit is contained in:
parent
3cfdaff55f
commit
624f5c68ea
@ -1741,7 +1741,7 @@ R_API char *r_core_cmd_str(struct r_core_t *core, const char *cmd)
|
||||
retstr = strdup("");
|
||||
} else {
|
||||
const char *static_str = r_cons_get_buffer();
|
||||
if (retstr==NULL)
|
||||
if (retstr==NULL || static_str==NULL)
|
||||
retstr = strdup("");
|
||||
else retstr = strdup(static_str);
|
||||
r_cons_reset();
|
||||
|
@ -69,7 +69,7 @@ R_API int r_core_config_init(struct r_core_t *core)
|
||||
r_parse_set(&core->parser, "parse_x86_pseudo");
|
||||
r_config_set_cb(cfg, "asm.parser", "x86_pseudo",
|
||||
&config_asm_parser_callback);
|
||||
r_config_set(cfg, "dir.plugins", LIBDIR"/radare/");
|
||||
r_config_set(cfg, "dir.plugins", LIBDIR"/radare2/");
|
||||
r_config_set(cfg, "asm.syntax", "intel");
|
||||
r_config_set_i_cb(cfg, "asm.bits", 32,
|
||||
&config_asm_bits_callback);
|
||||
|
@ -89,7 +89,7 @@ static int myfgets(char *buf, int len)
|
||||
return -1;
|
||||
strncpy(buf, ptr, len);
|
||||
//free(ptr);
|
||||
return strlen(buf);
|
||||
return strlen(buf)+1;
|
||||
}
|
||||
/*-----------------------------------*/
|
||||
|
||||
|
@ -150,7 +150,7 @@ R_API ut64 r_io_section_align(struct r_io_t *io, ut64 addr, ut64 vaddr, ut64 pad
|
||||
R_API int r_io_hook(struct r_io_t *io, CB_IO);
|
||||
#endif
|
||||
/* plugins */
|
||||
struct r_io_handle_t r_io_plugin_dbg;
|
||||
struct r_io_handle_t r_io_plugin_ptrace;
|
||||
extern struct r_io_handle_t r_io_plugin_dbg;
|
||||
extern struct r_io_handle_t r_io_plugin_ptrace;
|
||||
|
||||
#endif
|
||||
|
@ -10,16 +10,8 @@
|
||||
static struct r_io_handle_t *io_static_plugins[] =
|
||||
{ R_IO_STATIC_PLUGINS };
|
||||
|
||||
int r_io_handle_init(struct r_io_t *io)
|
||||
{
|
||||
int i;
|
||||
INIT_LIST_HEAD(&io->io_list);
|
||||
for(i=0;io_static_plugins[i];i++)
|
||||
r_io_handle_add (io, io_static_plugins[i]);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin)
|
||||
R_API int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin)
|
||||
{
|
||||
int i;
|
||||
struct r_io_list_t *li;
|
||||
@ -35,7 +27,16 @@ int r_io_handle_add(struct r_io_t *io, struct r_io_handle_t *plugin)
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filename)
|
||||
R_API int r_io_handle_init(struct r_io_t *io)
|
||||
{
|
||||
int i;
|
||||
INIT_LIST_HEAD(&io->io_list);
|
||||
for(i=0;io_static_plugins[i];i++)
|
||||
r_io_handle_add (io, io_static_plugins[i]);
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filename)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &io->io_list) {
|
||||
@ -50,7 +51,7 @@ struct r_io_handle_t *r_io_handle_resolve(struct r_io_t *io, const char *filenam
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd)
|
||||
R_API struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd)
|
||||
{
|
||||
int i;
|
||||
struct list_head *pos;
|
||||
@ -64,13 +65,13 @@ struct r_io_handle_t *r_io_handle_resolve_fd(struct r_io_t *io, int fd)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int r_io_handle_generate(struct r_io_t *io)
|
||||
R_API int r_io_handle_generate(struct r_io_t *io)
|
||||
{
|
||||
// TODO: ensure srand here (( implement in r_util a decent random helper
|
||||
return (rand()%666)+1024;
|
||||
}
|
||||
|
||||
int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
R_API int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
{
|
||||
int i=0;
|
||||
struct list_head *pos;
|
||||
@ -89,7 +90,7 @@ int r_io_handle_open(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
R_API int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
{
|
||||
int i=0;
|
||||
struct list_head *pos;
|
||||
@ -108,7 +109,7 @@ int r_io_handle_close(struct r_io_t *io, int fd, struct r_io_handle_t *plugin)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int r_io_handle_list(struct r_io_t *io)
|
||||
R_API int r_io_handle_list(struct r_io_t *io)
|
||||
{
|
||||
int n = 0;
|
||||
struct list_head *pos;
|
||||
|
@ -268,4 +268,3 @@ struct r_lib_struct_t radare_plugin = {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
all: cat read4
|
||||
|
||||
cat:
|
||||
${CC} -I ../../include cat.c ../*.o -lr_util -g -o cat
|
||||
${CC} -I ../../include cat.c -Wl,-R.. -lr_io -g -o cat
|
||||
|
||||
read4:
|
||||
${CC} -I ../../include read4.c ../*.o -lr_util -g -o read4
|
||||
${CC} -I ../../include read4.c -Wl,-R.. -lr_io -g -o read4
|
||||
|
||||
clean:
|
||||
rm -f cat read4
|
||||
|
@ -384,7 +384,7 @@ R_API char *r_line_readline(int argc, const char **argv)
|
||||
r_line_buffer[0]='\0';
|
||||
fgets(r_line_buffer, R_LINE_BUFSIZE-1, stdin);
|
||||
r_line_buffer[strlen(r_line_buffer)] = '\0';
|
||||
return (*r_line_buffer)? r_line_buffer : NULL;
|
||||
return (*r_line_buffer)? r_line_buffer : r_line_nullstr;
|
||||
}
|
||||
|
||||
memset(&buf,0,sizeof buf);
|
||||
@ -426,10 +426,9 @@ R_API char *r_line_readline(int argc, const char **argv)
|
||||
if (r_line_echo)
|
||||
printf("\r%*c\r", columns, ' ');
|
||||
|
||||
|
||||
switch(buf[0]) {
|
||||
case -1:
|
||||
return NULL;
|
||||
// case -1:
|
||||
// return NULL;
|
||||
case 0: // control-space
|
||||
/* ignore atm */
|
||||
break;
|
||||
@ -654,5 +653,7 @@ _end:
|
||||
r_line_hist_list();
|
||||
return r_line_nullstr;
|
||||
}
|
||||
if (r_line_buffer == NULL)
|
||||
return r_line_nullstr;
|
||||
return r_line_buffer;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user