Changeset f4f4b95 in mainline
- Timestamp:
- 2018-12-15T18:33:04Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0feb39b
- Parents:
- c7afdf7a
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2018-12-15 18:30:35)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2018-12-15 18:33:04)
- Location:
- uspace/app/bdsh/cmds/modules/ls
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/ls/ls.c
rc7afdf7a rf4f4b95 66 66 /* Prototypes for the ls command, excluding entry points. */ 67 67 static unsigned int ls_start(ls_job_t *); 68 static voidls_print(struct dir_elem_t *);69 static voidls_print_single_column(struct dir_elem_t *);68 static bool ls_print(struct dir_elem_t *); 69 static bool ls_print_single_column(struct dir_elem_t *); 70 70 static int ls_cmp_type_name(const void *, const void *); 71 71 static int ls_cmp_name(const void *, const void *); … … 96 96 * @param de Directory element. 97 97 */ 98 static voidls_print(struct dir_elem_t *de)98 static bool ls_print(struct dir_elem_t *de) 99 99 { 100 100 int width = 13; 101 101 102 102 if (de->s.is_file) { 103 if (!ls.exact_size) { 103 if (ls.exact_size) { 104 printf("%-40s\t%*llu\n", de->name, width, (long long) de->s.size); 105 } else { 104 106 cap_spec_t cap; 105 107 … … 114 116 115 117 printf("%-40s\t%*s %2s\n", de->name, width - 3, bytes, suffix); 116 117 //if there is a failure with cap_format we simply print out an unformatted size 118 return; 119 } 120 121 } 122 123 printf("%-40s\t%*llu\n", de->name, width, (long long) de->s.size); 118 } else 119 return false; 120 } 124 121 } else if (de->s.is_directory) 125 122 printf("%-40s\t%*s\n", de->name, width, "<dir>"); 126 123 else 127 124 printf("%-40s\n", de->name); 128 } 129 130 static void ls_print_single_column(struct dir_elem_t *de) 125 126 return true; 127 } 128 129 static bool ls_print_single_column(struct dir_elem_t *de) 131 130 { 132 131 if (de->s.is_file) { … … 135 134 printf("%s/\n", de->name); 136 135 } 136 137 return true; 137 138 } 138 139 … … 251 252 } 252 253 253 for (i = 0; i < nbdirs; i++) 254 ls.printer(&tosort[i]); 254 for (i = 0; i < nbdirs; i++) { 255 if (!ls.printer(&tosort[i])) { 256 cli_error(CL_ENOMEM, "%s: Out of memory", cmdname); 257 goto out; 258 } 259 } 255 260 256 261 /* Populate the directory list. */ … … 465 470 switch (scope) { 466 471 case LS_FILE: 467 ls.printer(&de); 472 if (!ls.printer(&de)) { 473 cli_error(CL_ENOMEM, "%s: Out of memory", cmdname); 474 return CMD_FAILURE; 475 } 468 476 break; 469 477 case LS_DIR: -
uspace/app/bdsh/cmds/modules/ls/ls.h
rc7afdf7a rf4f4b95 27 27 bool exact_size; 28 28 29 void(*printer)(struct dir_elem_t *);29 bool (*printer)(struct dir_elem_t *); 30 30 } ls_job_t; 31 31
Note:
See TracChangeset
for help on using the changeset viewer.