Changeset 6afc9d7 in mainline for uspace/app/bdsh/cmds/modules/ls/ls.c


Ignore:
Timestamp:
2015-10-06T19:01:36Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0328987
Parents:
f1f7584
Message:

UNIX-like I/O functions should use errno to return error code for many reasons.

File:
1 edited

Legend:

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

    rf1f7584 r6afc9d7  
    3131 * As more stuff is completed and exposed in libc, this will improve */
    3232
     33#include <errno.h>
    3334#include <stdio.h>
    3435#include <stdlib.h>
     
    187188                if (rc != 0) {
    188189                        printf("ls: skipping bogus node %s\n", buff);
    189                         printf("rc=%d\n", rc);
     190                        printf("error=%d\n", errno);
    190191                        goto out;
    191192                }
     
    314315static unsigned int ls_scope(const char *path, struct dir_elem_t *de)
    315316{
    316         if (stat(path, &de->s)) {
     317        if (stat(path, &de->s) != 0) {
    317318                cli_error(CL_ENOENT, "%s", path);
    318319                return LS_BOGUS;
     
    376377                }
    377378        }
    378        
     379
    379380        argc -= optind;
    380        
     381
    381382        de.name = (char *) malloc(PATH_MAX);
    382383        if (!de.name) {
    383                 cli_error(CL_ENOMEM, "%s: ", cmdname);
     384                cli_error(CL_ENOMEM, "%s: Out of memory", cmdname);
    384385                return CMD_FAILURE;
    385386        }
    386387        memset(de.name, 0, PATH_MAX);
    387        
    388         if (argc == 0)
    389                 getcwd(de.name, PATH_MAX);
    390         else
     388
     389        if (argc == 0) {
     390                if (getcwd(de.name, PATH_MAX) == NULL) {
     391                        cli_error(CL_EFAIL, "%s: Failed determining working "
     392                            "directory", cmdname);
     393                        return CMD_FAILURE;
     394                }
     395        } else {
    391396                str_cpy(de.name, PATH_MAX, argv[optind]);
     397        }
    392398
    393399        scope = ls_scope(de.name, &de);
Note: See TracChangeset for help on using the changeset viewer.