13 static char *
showfile(
char *res,
const int nth,
const char *fpath,
const char *
name,
int printfmt) {
17 const char *
n = fpath;
18 char *nn, *u_rwx =
NULL;
20 int perm, uid = 0, gid = 0;
22 if (!strncmp(fpath,
"./", 2)) {
35 perm = isdir ? 0755 : 0644;
46 if (lstat(
n, &
sb) != -1) {
47 ut32 ifmt =
sb.st_mode & S_IFMT;
50 perm =
sb.st_mode & 0777;
55 if (
sb.st_mode & S_ISUID) {
56 u_rwx[2] = (
sb.st_mode & S_IXUSR) ?
's' :
'S';
62 case S_IFCHR: fch =
'c';
break;
63 case S_IFBLK: fch =
'b';
break;
65 case S_IFIFO: fch =
'p';
break;
67 case S_IFSOCK: fch =
's';
break;
74 fch = isdir ?
'd' :
'-';
76 if (printfmt ==
'q') {
78 }
else if (printfmt ==
'e') {
79 const char *eDIR =
"📁";
80 const char *eIMG =
"🌅";
81 const char *eHID =
"👀";
82 const char *eANY =
" ";
84 const char *icon = eANY;
88 }
else if ((
sb.st_mode & S_IFMT) ==
S_IFLNK) {
89 const char *eLNK =
"📎";
91 }
else if (
sb.st_mode & S_ISUID) {
92 const char *eUID =
"🔼";
97 }
else if (*nn ==
'.') {
101 }
else if (printfmt ==
FMT_RAW) {
112 res =
rz_str_appendf(res,
"{\"name\":\"%s\",\"size\":%d,\"uid\":%d,"
113 "\"gid\":%d,\"perm\":%d,\"isdir\":%s}",
114 name, sz, uid, gid, perm, isdir ?
"true" :
"false");
123 const char *
path =
".";
126 char *homepath =
NULL;
127 char *pattern =
NULL;
146 if ((!strncmp(
input,
"-h", 2))) {
147 eprintf(
"Usage: ls ([-e,-l,-j,-q]) ([path]) # long, json, quiet\n");
148 }
else if ((!strncmp(
input,
"-e", 2))) {
151 }
else if ((!strncmp(
input,
"-q", 2))) {
154 }
else if ((!strncmp(
input,
"-l", 2)) || (!strncmp(
input,
"-j", 2))) {
174 path = (
const char *)homepath;
176 }
else if (*
path ==
'$') {
177 if (!strncmp(
path + 1,
"home", 4) || !strncmp(
path + 1,
"HOME", 4)) {
180 path = (
const char *)homepath;
185 p = strrchr(
path,
'/');
194 path = (
const char *)
d;
212 if (
path[strlen(
path) - 1] ==
'/') {
249 static int cmpstr(
const void *_a,
const void *_b) {
250 const char *
a = _a, *
b = _b;
251 return (
int)strcmp(
a,
b);
257 const char *
p =
NULL;
259 if ((
p = strchr(
file,
' '))) {
269 eprintf(
"No such file or directory\n");
279 eprintf(
"Usage: sort [file]\n");
287 const char *
p =
NULL;
288 if ((
p = strchr(
file,
' '))) {
298 eprintf(
"No such file or directory\n");
303 eprintf(
"Usage: head 7 [file]\n");
311 const char *
p =
NULL;
313 if ((
p = strchr(
file,
' '))) {
324 eprintf(
"No such file or directory\n");
329 eprintf(
"Usage: tail 7 [file]\n");
337 const char *
p =
NULL;
340 if ((
p = strchr(
file,
' '))) {
351 eprintf(
"No such file or directory\n");
362 eprintf(
"Usage: uniq [file]\n");
372 if ((p1 = strchr(file1,
' '))) {
379 if ((p2 = strchr(file2,
' '))) {
385 if (p1 && *p1 && p2 && *p2) {
386 char *filename1 =
strdup(p1);
387 char *filename2 =
strdup(p2);
393 if (!data1 && !data2) {
394 eprintf(
"No such files or directory\n");
399 if (!
list || !list1 || !list2) {
407 rz_list_foreach (list1, iter1, str1) {
408 char *field =
strdup(str1);
409 char *
end = strchr(field,
' ');
416 rz_list_foreach (list2, iter2, str2) {
419 char *first = strchr(str1,
' ');
420 char *second = strchr(str2,
' ');
437 eprintf(
"Usage: join file1 file2\n");
445 const char *
p =
NULL;
447 if ((
p = strchr(
file,
' '))) {
458 eprintf(
"No such file or directory\n");
463 eprintf(
"Usage: cat [file]\n");
476 char *dirname = (!strncmp(
suffix,
"-p ", 3))
482 char *res =
rz_str_newf(
"Cannot create \"%s\"\n", dirname);
const lzma_allocator const uint8_t size_t uint8_t * out
static static fork const void static count static fd const char const char static newpath const char static path const char path
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
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
unsigned char suffix[65536]
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_uniq(RZ_NONNULL const RzList *list, RZ_NONNULL RzListComparator cmp)
Returns a new RzList which contains only unique values.
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
RZ_API RZ_OWN char * rz_list_to_str(RZ_NONNULL RzList *list, char ch)
Casts a RzList containg strings into a concatenated string.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * calloc(size_t number, size_t size)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
#define rz_return_val_if_fail(expr, val)
RZ_API bool rz_file_is_directory(const char *str)
RZ_API RZ_OWN char * rz_file_slurp_lines_from_bottom(const char *file, int line)
RZ_API bool rz_file_is_regular(const char *str)
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
RZ_API ut64 rz_file_size(const char *str)
RZ_API char * rz_file_slurp_lines(const char *file, int line, int count)
RZ_API RZ_OWN char * rz_path_home_expand(RZ_NULLABLE const char *path)
Return a new path with the ~ char expanded to the home directory.
RZ_API const char * rz_str_rwx_i(int rwx)
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
RZ_API char * rz_str_new(const char *str)
RZ_API char * rz_str_dup(char *ptr, const char *string)
RZ_API char * rz_str_home(const char *str)
RZ_API bool rz_str_glob(const char *str, const char *glob)
RZ_API const char * rz_str_trim_head_ro(const char *str)
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
RZ_API const char * rz_str_casestr(const char *a, const char *b)
RZ_API RzList * rz_str_split_list(char *str, const char *c, int n)
Split the string str according to the substring c and returns a RzList with the result.
RZ_API bool rz_sys_mkdirp(const char *dir)
RZ_API RzList * rz_sys_dir(const char *path)
#define rz_sys_mkdir_failed()
RZ_API RZ_OWN char * rz_syscmd_join(RZ_NONNULL const char *file1, RZ_NONNULL const char *file2)
static int cmpstr(const void *_a, const void *_b)
RZ_API RZ_OWN char * rz_syscmd_cat(RZ_NONNULL const char *file)
RZ_API RZ_OWN char * rz_syscmd_sort(RZ_NONNULL const char *file)
static char * showfile(char *res, const int nth, const char *fpath, const char *name, int printfmt)
RZ_API RZ_OWN char * rz_syscmd_mkdir(RZ_NONNULL const char *dir)
RZ_API RZ_OWN char * rz_syscmd_tail(RZ_NONNULL const char *file, int count)
RZ_API RZ_OWN char * rz_syscmd_head(RZ_NONNULL const char *file, int count)
RZ_API RZ_OWN char * rz_syscmd_uniq(RZ_NONNULL const char *file)
RZ_API RZ_OWN char * rz_syscmd_ls(RZ_NONNULL const char *input)
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)