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("");
|
retstr = strdup("");
|
||||||
} else {
|
} else {
|
||||||
const char *static_str = r_cons_get_buffer();
|
const char *static_str = r_cons_get_buffer();
|
||||||
if (retstr==NULL)
|
if (retstr==NULL || static_str==NULL)
|
||||||
retstr = strdup("");
|
retstr = strdup("");
|
||||||
else retstr = strdup(static_str);
|
else retstr = strdup(static_str);
|
||||||
r_cons_reset();
|
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_parse_set(&core->parser, "parse_x86_pseudo");
|
||||||
r_config_set_cb(cfg, "asm.parser", "x86_pseudo",
|
r_config_set_cb(cfg, "asm.parser", "x86_pseudo",
|
||||||
&config_asm_parser_callback);
|
&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(cfg, "asm.syntax", "intel");
|
||||||
r_config_set_i_cb(cfg, "asm.bits", 32,
|
r_config_set_i_cb(cfg, "asm.bits", 32,
|
||||||
&config_asm_bits_callback);
|
&config_asm_bits_callback);
|
||||||
|
@ -89,7 +89,7 @@ static int myfgets(char *buf, int len)
|
|||||||
return -1;
|
return -1;
|
||||||
strncpy(buf, ptr, len);
|
strncpy(buf, ptr, len);
|
||||||
//free(ptr);
|
//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);
|
R_API int r_io_hook(struct r_io_t *io, CB_IO);
|
||||||
#endif
|
#endif
|
||||||
/* plugins */
|
/* plugins */
|
||||||
struct r_io_handle_t r_io_plugin_dbg;
|
extern 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_ptrace;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,16 +10,8 @@
|
|||||||
static struct r_io_handle_t *io_static_plugins[] =
|
static struct r_io_handle_t *io_static_plugins[] =
|
||||||
{ R_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;
|
int i;
|
||||||
struct r_io_list_t *li;
|
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;
|
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;
|
struct list_head *pos;
|
||||||
list_for_each_prev(pos, &io->io_list) {
|
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;
|
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;
|
int i;
|
||||||
struct list_head *pos;
|
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;
|
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
|
// TODO: ensure srand here (( implement in r_util a decent random helper
|
||||||
return (rand()%666)+1024;
|
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;
|
int i=0;
|
||||||
struct list_head *pos;
|
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;
|
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;
|
int i=0;
|
||||||
struct list_head *pos;
|
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;
|
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;
|
int n = 0;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
|
@ -268,4 +268,3 @@ struct r_lib_struct_t radare_plugin = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
all: cat read4
|
all: cat read4
|
||||||
|
|
||||||
cat:
|
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:
|
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:
|
clean:
|
||||||
rm -f cat read4
|
rm -f cat read4
|
||||||
|
@ -384,7 +384,7 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||||||
r_line_buffer[0]='\0';
|
r_line_buffer[0]='\0';
|
||||||
fgets(r_line_buffer, R_LINE_BUFSIZE-1, stdin);
|
fgets(r_line_buffer, R_LINE_BUFSIZE-1, stdin);
|
||||||
r_line_buffer[strlen(r_line_buffer)] = '\0';
|
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);
|
memset(&buf,0,sizeof buf);
|
||||||
@ -426,10 +426,9 @@ R_API char *r_line_readline(int argc, const char **argv)
|
|||||||
if (r_line_echo)
|
if (r_line_echo)
|
||||||
printf("\r%*c\r", columns, ' ');
|
printf("\r%*c\r", columns, ' ');
|
||||||
|
|
||||||
|
|
||||||
switch(buf[0]) {
|
switch(buf[0]) {
|
||||||
case -1:
|
// case -1:
|
||||||
return NULL;
|
// return NULL;
|
||||||
case 0: // control-space
|
case 0: // control-space
|
||||||
/* ignore atm */
|
/* ignore atm */
|
||||||
break;
|
break;
|
||||||
@ -654,5 +653,7 @@ _end:
|
|||||||
r_line_hist_list();
|
r_line_hist_list();
|
||||||
return r_line_nullstr;
|
return r_line_nullstr;
|
||||||
}
|
}
|
||||||
|
if (r_line_buffer == NULL)
|
||||||
|
return r_line_nullstr;
|
||||||
return r_line_buffer;
|
return r_line_buffer;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user