Changeset f4f4b95 in mainline


Ignore:
Timestamp:
2018-12-15T18:33:04Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

improved error handling

Location:
uspace/app/bdsh/cmds/modules/ls
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rc7afdf7a rf4f4b95  
    6666/* Prototypes for the ls command, excluding entry points. */
    6767static unsigned int ls_start(ls_job_t *);
    68 static void ls_print(struct dir_elem_t *);
    69 static void ls_print_single_column(struct dir_elem_t *);
     68static bool ls_print(struct dir_elem_t *);
     69static bool ls_print_single_column(struct dir_elem_t *);
    7070static int ls_cmp_type_name(const void *, const void *);
    7171static int ls_cmp_name(const void *, const void *);
     
    9696 * @param de            Directory element.
    9797 */
    98 static void ls_print(struct dir_elem_t *de)
     98static bool ls_print(struct dir_elem_t *de)
    9999{
    100100        int width = 13;
    101101
    102102        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 {
    104106                        cap_spec_t cap;
    105107
     
    114116
    115117                                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                }
    124121        } else if (de->s.is_directory)
    125122                printf("%-40s\t%*s\n", de->name, width, "<dir>");
    126123        else
    127124                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
     129static bool ls_print_single_column(struct dir_elem_t *de)
    131130{
    132131        if (de->s.is_file) {
     
    135134                printf("%s/\n", de->name);
    136135        }
     136
     137        return true;
    137138}
    138139
     
    251252        }
    252253
    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        }
    255260
    256261        /* Populate the directory list. */
     
    465470        switch (scope) {
    466471        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                }
    468476                break;
    469477        case LS_DIR:
  • uspace/app/bdsh/cmds/modules/ls/ls.h

    rc7afdf7a rf4f4b95  
    2727        bool exact_size;
    2828
    29         void (*printer)(struct dir_elem_t *);
     29        bool (*printer)(struct dir_elem_t *);
    3030} ls_job_t;
    3131
Note: See TracChangeset for help on using the changeset viewer.