Rizin
unix-like reverse engineering framework and cli tools
rz_file.h
Go to the documentation of this file.
1 #ifndef RZ_FILE_H
2 #define RZ_FILE_H
3 
4 #include <rz_list.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 typedef struct rz_mmap_t {
11  ut8 *buf;
14  int perm;
15  int mode;
16  char *filename;
17  int fd;
18 #if __WINDOWS__
19  void *fm;
20 #endif
22 
23 /* is */
24 RZ_API bool rz_file_is_abspath(const char *file);
25 RZ_API bool rz_file_is_c(const char *file);
26 RZ_API bool rz_file_is_directory(const char *str);
27 RZ_API bool rz_file_is_regular(const char *str);
28 
29 RZ_API bool rz_file_truncate(const char *filename, ut64 newsize);
30 RZ_API ut64 rz_file_size(const char *str);
31 RZ_API char *rz_file_root(const char *root, const char *path);
32 RZ_API RzMmap *rz_file_mmap(const char *file, int perm, int mode, ut64 base);
33 RZ_API void *rz_file_mmap_resize(RzMmap *m, ut64 newsize);
35 RZ_API bool rz_file_chmod(const char *file, const char *mod, int recursive);
36 RZ_API char *rz_file_temp(const char *prefix);
37 RZ_API char *rz_file_path(const char *bin);
38 RZ_API RZ_OWN char *rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2);
39 RZ_API const char *rz_file_basename(const char *path);
40 RZ_API const char *rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path);
41 RZ_API char *rz_file_dirname(const char *path);
42 RZ_API char *rz_file_abspath_rel(const char *cwd, const char *file);
43 RZ_API char *rz_file_abspath(const char *file);
44 // make path relative to base
45 RZ_API char *rz_file_relpath(const char *base, const char *path);
46 RZ_API char *rz_file_path_local_to_unix(const char *path);
47 RZ_API char *rz_file_path_unix_to_local(const char *path);
48 RZ_API char *rz_file_binsh(void);
49 RZ_API ut8 *rz_inflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits);
50 RZ_API ut8 *rz_inflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen);
51 RZ_API ut8 *rz_inflate_ignore_header(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen);
52 RZ_API ut8 *rz_deflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits);
53 RZ_API ut8 *rz_deflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen);
54 RZ_API ut8 *rz_file_gzslurp(const char *str, int *outlen, int origonfail);
55 RZ_API char *rz_stdin_slurp(int *sz);
56 RZ_API RZ_OWN char *rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz);
57 RZ_API char *rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz);
58 RZ_API char *rz_file_slurp_random_line(const char *file);
59 RZ_API char *rz_file_slurp_random_line_count(const char *file, int *linecount);
60 RZ_API ut8 *rz_file_slurp_hexpairs(const char *str, int *usz);
61 RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append);
62 RZ_API bool rz_file_touch(const char *file);
63 RZ_API bool rz_file_hexdump(const char *file, const ut8 *buf, int len, int append);
64 RZ_API bool rz_file_rm(const char *file);
65 RZ_API bool rz_file_exists(const char *str);
66 RZ_API bool rz_file_fexists(const char *fmt, ...) RZ_PRINTF_CHECK(1, 2);
67 RZ_API char *rz_file_slurp_line(const char *file, int line, int context);
68 RZ_API char *rz_file_slurp_lines(const char *file, int line, int count);
70 RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname);
71 RZ_API char *rz_file_tmpdir(void);
72 RZ_API char *rz_file_readlink(const char *path);
73 RZ_API bool rz_file_copy(const char *src, const char *dst);
74 RZ_API RzList *rz_file_globsearch(const char *globbed_path, int maxdepth);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif // RZ_FILE_H
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
#define append(x, y)
Definition: cmd_print.c:1740
#define RZ_API
int mod(int a, int b)
Definition: crypto_rot.c:8
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
int root
Definition: enough.c:226
unsigned short prefix[65536]
Definition: gun.c:163
const char * filename
Definition: ioapi.h:137
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define const
Definition: ansidecl.h:240
char * dst
Definition: lz4.h:724
line
Definition: setup.py:34
int off
Definition: pal.c:13
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
RZ_API char * rz_file_tmpdir(void)
Definition: file.c:1132
RZ_API const char * rz_file_dos_basename(RZ_BORROW RZ_NONNULL const char *path)
Definition: file.c:102
RZ_API char * rz_file_temp(const char *prefix)
Definition: file.c:1048
RZ_API char * rz_file_slurp_random_line_count(const char *file, int *linecount)
Definition: file.c:630
RZ_API ut8 * rz_file_slurp_hexpairs(const char *str, int *usz)
Definition: file.c:552
RZ_API char * rz_file_binsh(void)
Definition: file.c:393
RZ_API bool rz_file_is_c(const char *file)
Definition: file.c:147
RZ_API ut8 * rz_deflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
deflate uncompressed data to zlib or gzipped, use MAX_WBITS as the window size logarithm.
Definition: compression.c:340
RZ_API bool rz_file_is_directory(const char *str)
Definition: file.c:167
RZ_API char * rz_file_readlink(const char *path)
Definition: file.c:892
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
RZ_API RZ_OWN char * rz_file_slurp_lines_from_bottom(const char *file, int line)
Definition: file.c:708
RZ_API char * rz_file_relpath(const char *base, const char *path)
Definition: file.c:278
RZ_API RzMmap * rz_file_mmap(const char *file, int perm, int mode, ut64 base)
Definition: file.c:972
RZ_API bool rz_file_touch(const char *file)
Definition: file.c:833
RZ_API bool rz_file_is_deflated(RZ_NONNULL const char *src)
check whether a file is a deflated (gzip) file
Definition: file.c:1392
RZ_API bool rz_file_is_abspath(const char *file)
Definition: file.c:214
RZ_API ut8 * rz_inflate_ignore_header(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped. The input must be a raw stream with no header or trailer.
Definition: compression.c:28
RZ_API bool rz_file_inflate(RZ_NONNULL const char *src, RZ_NONNULL const char *dst)
unzip the contents of src and store in dst
Definition: file.c:1361
RZ_API bool rz_file_is_regular(const char *str)
Definition: file.c:159
RZ_API char * rz_file_path_local_to_unix(const char *path)
Definition: file.c:332
RZ_API bool rz_file_fexists(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_stdin_slurp(int *sz)
Definition: file.c:408
RZ_API ut8 * rz_file_gzslurp(const char *str, int *outlen, int origonfail)
Definition: file.c:529
RZ_API bool rz_file_deflate(RZ_NONNULL const char *src, RZ_NONNULL const char *dst)
zip the contents of src and store in dst
Definition: file.c:1329
RZ_API char * rz_file_abspath(const char *file)
Definition: file.c:267
RZ_API bool rz_file_copy(const char *src, const char *dst)
Definition: file.c:1179
RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname)
Definition: file.c:1058
RZ_API char * rz_file_dirname(const char *path)
Definition: file.c:120
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RZ_API char * rz_file_root(const char *root, const char *path)
Definition: file.c:775
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
Definition: file.c:838
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
RZ_API char * rz_file_path(const char *bin)
Definition: file.c:354
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API ut64 rz_file_size(const char *str)
Definition: file.c:205
RZ_API char * rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz)
Definition: file.c:595
RZ_API bool rz_file_hexdump(const char *file, const ut8 *buf, int len, int append)
Definition: file.c:794
RZ_API char * rz_file_abspath_rel(const char *cwd, const char *file)
Definition: file.c:219
RZ_API char * rz_file_path_unix_to_local(const char *path)
Definition: file.c:343
RZ_API bool rz_file_chmod(const char *file, const char *mod, int recursive)
Definition: chmod.c:19
RZ_API void * rz_file_mmap_resize(RzMmap *m, ut64 newsize)
Definition: file.c:1017
RZ_API ut8 * rz_inflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
Definition: compression.c:319
RZ_API char * rz_file_slurp_random_line(const char *file)
Definition: file.c:624
RZ_API void rz_file_mmap_free(RzMmap *m)
Definition: file.c:995
struct rz_mmap_t RzMmap
RZ_API ut8 * rz_inflate(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen)
inflate zlib compressed or gzipped, automatically accepts either the zlib or gzip format,...
Definition: compression.c:18
RZ_API bool rz_file_truncate(const char *filename, ut64 newsize)
Definition: file.c:47
RZ_API bool RZ_API char * rz_file_slurp_line(const char *file, int line, int context)
Definition: file.c:673
RZ_API RzList * rz_file_globsearch(const char *globbed_path, int maxdepth)
Definition: file.c:1263
RZ_API ut8 * rz_deflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits)
Definition: compression.c:323
RZ_API char * rz_file_slurp_lines(const char *file, int line, int count)
Definition: file.c:736
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
#define RZ_BORROW
Definition: rz_types.h:63
#define s1(x)
Definition: sha256.c:60
Definition: malloc.c:26
Definition: gzappend.c:170
char * filename
Definition: rz_file.h:16
int mode
Definition: rz_file.h:15
ut8 * buf
Definition: rz_file.h:11
ut64 base
Definition: rz_file.h:12
int perm
Definition: rz_file.h:14
int fd
Definition: rz_file.h:17
ut64 len
Definition: rz_file.h:13
ut64(WINAPI *w32_GetEnabledXStateFeatures)()