本文整理汇总了C++中r_file_slurp函数的典型用法代码示例。如果您正苦于以下问题:C++ r_file_slurp函数的具体用法?C++ r_file_slurp怎么用?C++ r_file_slurp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_file_slurp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: free
R_API char *r_cons_editor (const char *file) {
char *line;
_n = 0;
free (path);
if (file) {
path = strdup (file);
lines = r_file_slurp (file, &bytes);
nlines = r_str_split (lines, '\n');
eprintf ("Loaded %d lines on %d bytes\n", nlines-1, bytes);
} else path = NULL;
r_cons_new ();
I->line->hist_up = up;
I->line->hist_down = down;
I->line->contents = I->line->buffer.data;
for (;;) {
setnewline (_n);
snprintf (prompt, sizeof (prompt), "%d: ", _n);
r_line_set_prompt (prompt);
line = r_line_readline ();
saveline (_n, line);
_n++;
if (!line) break;
}
filesave ();
return NULL;
}
示例2: r_egg_Cfile_parseCompiled
static bool r_egg_Cfile_parseCompiled(const char *file) {
char *fileExt = r_str_newf ("%s.tmp", file);
char *buffer = r_file_slurp (fileExt, NULL);
buffer = r_str_replace (buffer, "rdata", "text", false);
buffer = r_str_replace (buffer, "rodata", "text", false);
buffer = r_str_replace (buffer, "get_pc_thunk.bx", "__getesp__", true);
const char *words[] = {".cstring", "size", "___main", "section", "__alloca", "zero", "cfi"};
size_t i;
for (i = 0; i < 7; i++) {
r_str_stripLine (buffer, words[i]);
}
free (fileExt);
fileExt = r_str_newf ("%s.s", file);
if (!r_file_dump (fileExt, (const ut8*) buffer, strlen (buffer), true)) {
eprintf ("Error while opening %s.s\n", file);
goto fail;
}
free (buffer);
free (fileExt);
return true;
fail:
free (buffer);
free (fileExt);
return false;
}
示例3: R_NEW0
static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) {
char *out;
int rlen;
if (__plugin_open (io, pathname, 0)) {
RIOBind iob;
RIOBfdbg *mal = R_NEW0 (RIOBfdbg);
r_io_bind (io, &iob);
mal->fd = getmalfd (mal);
mal->bfvm = bfvm_new (&iob);
out = r_file_slurp (pathname+8, &rlen);
if (!out || rlen < 1) {
free (mal);
free (out);
return NULL;
}
mal->size = rlen;
mal->buf = malloc (mal->size+1);
if (mal->buf != NULL) {
memcpy (mal->buf, out, rlen);
free (out);
return r_io_desc_new (&r_io_plugin_bfdbg,
mal->fd, pathname, rw, mode, mal);
}
eprintf ("Cannot allocate (%s) %d bytes\n",
pathname+9, mal->size);
free (mal);
free (out);
}
return NULL;
}
示例4: strdup
static char *projectScriptPath(RCore *core, const char *file) {
const char *magic = "# r2 rdb project file";
char *data, *prjfile;
if (r_file_is_abspath (file)) {
prjfile = strdup (file);
} else {
if (!is_valid_project_name (file)) {
return NULL;
}
prjfile = r_file_abspath (r_config_get (core->config, "dir.projects"));
prjfile = r_str_append (prjfile, R_SYS_DIR);
prjfile = r_str_append (prjfile, file);
if (!r_file_exists (prjfile) || r_file_is_directory (prjfile)) {
prjfile = r_str_append (prjfile, R_SYS_DIR "rc");
}
}
data = r_file_slurp (prjfile, NULL);
if (data) {
if (strncmp (data, magic, strlen (magic))) {
R_FREE (prjfile);
}
}
free (data);
return prjfile;
}
示例5: r_io_open
static ut8 *slurp(RCore **c, const char *file, int *sz) {
RIODesc *d;
RIO *io;
if (c && file && strstr (file, "://")) {
ut8 *data = NULL;
ut64 size;
if (!*c) {
*c = opencore (NULL);
}
io = (*c)->io;
d = r_io_open (io, file, 0, 0);
if (!d) {
return NULL;
}
size = r_io_size (io);
if (size > 0 || size < ST32_MAX) {
data = calloc (1, size);
if (r_io_read_at (io, 0, data, size) == size) {
if (sz) {
*sz = size;
}
} else {
eprintf ("slurp: read error\n");
R_FREE (data);
}
} else {
eprintf ("slurp: File is too big\n");
}
r_io_close (io, d);
return data;
}
return (ut8*)r_file_slurp (file, sz);
}
示例6: r_buf_new
R_API RBuffer *r_buf_file (const char *file) {
RBuffer *b = r_buf_new ();
if (!b) return NULL;
b->buf = (ut8*)r_file_slurp (file, &b->length);
if (b->buf) return b;
r_buf_free (b);
return NULL; /* we just freed b, don't return it */
}
示例7: r_file_temp
static char *r_debug_rap_reg_profile(RDebug *dbg) {
char *out, *tf = r_file_temp ("/tmp/rap.XXXXXX");
int fd = r_cons_pipe_open (tf, 1, 0);
r_io_system (dbg->iob.io, "drp");
r_cons_pipe_close (fd);
out = r_file_slurp (tf, NULL);
r_file_rm (tf);
return out;
}
示例8: r_file_slurp
// Display the content of a file in the hud
R_API char *r_cons_hud_file(const char *f) {
char *s = r_file_slurp (f, NULL);
if (s) {
char *ret = r_cons_hud_string (s);
free (s);
return ret;
}
return NULL;
}
示例9: r_run_parsefile
R_API int r_run_parsefile(RRunProfile *p, const char *b) {
char *s = r_file_slurp (b, NULL);
if (s) {
int ret = r_run_parse (p, s);
free (s);
return ret;
}
return 0;
}
示例10: r_file_slurp
// Display the content of a file in the hud
R_API char *r_cons_hud_file(const char *f, const bool usecolor) {
char *s = r_file_slurp (f, NULL);
if (s) {
char *ret = r_cons_hud_string (s, usecolor);
free (s);
if (!ret)
ret = strdup ("");
return ret;
}
return NULL;
}
示例11: r_reg_set_profile
R_API int r_reg_set_profile(RReg *reg, const char *profile) {
int ret;
char *base, *file;
char *str = r_file_slurp (profile, NULL);
if (!str) {
base = r_sys_getenv (R_LIB_ENV);
if (base) {
file = r_str_append (base, profile);
str = r_file_slurp (file, NULL);
free (file);
}
}
if (!str) {
eprintf ("r_reg_set_profile: Cannot find '%s'\n", profile);
return false;
}
ret = r_reg_set_profile_string (reg, str);
free (str);
return ret;
}
示例12: r_buf_new
// TODO: rename to new_from_file ?
R_API RBuffer *r_buf_new_slurp(const char *file) {
int len;
RBuffer *b = r_buf_new ();
if (!b) return NULL;
b->buf = (ut8*)r_file_slurp (file, &len);
b->length = len;
if (b->buf) {
return b;
}
r_buf_free (b);
return NULL; /* we just freed b, don't return it */
}
示例13: switch
static char *getstr(const char *src) {
int len;
char *ret = NULL;
switch (*src) {
case '\'':
ret = strdup (src+1);
if (ret) {
len = strlen (ret);
if (len>0) {
len--;
if (ret[len]=='\'') {
ret[len] = 0;
return ret;
} else eprintf ("Missing \"\n");
}
free (ret);
}
return NULL;
case '"':
ret = strdup (src+1);
if (ret) {
len = strlen (ret);
if (len>0) {
len--;
if (ret[len]=='"') {
ret[len] = 0;
r_str_unescape (ret);
return ret;
} else eprintf ("Missing \"\n");
}
free (ret);
}
return NULL;
case '@':
// slurp file
return r_file_slurp (src+1, NULL);
case ':':
// hexpairs
ret = strdup (src);
len = r_hex_str2bin (src+1, (ut8*)ret);
if (len>0) {
ret[len] = 0;
return ret;
} else {
eprintf ("Invalid hexpair string\n");
free (ret);
return NULL;
}
}
r_str_unescape ((ret = strdup (src)));
return ret;
}
示例14: r_core_project_cat
R_API int r_core_project_cat(RCore *core, const char *name) {
char *path = r_core_project_file (core, name);
if (path) {
char *data = r_file_slurp (path, NULL);
if (data) {
r_cons_println (data);
free (data);
}
}
free (path);
return 0;
}
示例15: r_reg_set_profile
R_API int r_reg_set_profile(RReg *reg, const char *profile) {
int ret;
char *base, *file;
char *str = r_file_slurp (profile, NULL);
if (!str) {
// XXX we must define this varname in r_lib.h /compiletime/
base = r_sys_getenv ("LIBR_PLUGINS");
if (base) {
file = r_str_concat (base, profile);
str = r_file_slurp (file, NULL);
free (file);
}
}
if (!str) {
eprintf ("r_reg_set_profile: Cannot find '%s'\n", profile);
return false;
}
ret = r_reg_set_profile_string (reg, str);
free (str);
return ret;
}