Ignore:
File:
1 edited

Legend:

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

    r582a0b8 r4cca9a9  
    180180    off64_t head, off64_t tail, bool tail_first)
    181181{
    182         int fd, bytes = 0, count = 0, reads = 0;
     182        int fd, count = 0, reads = 0;
     183        size_t bytes;
    183184        char *buff = NULL;
    184         int i;
     185        size_t i;
    185186        size_t offset = 0, copied_bytes = 0;
    186187        off64_t file_size = 0, length = 0;
    187188        aoff64_t pos = 0;
     189        int rc;
    188190
    189191        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
     
    193195                /* Allow storing the whole UTF-8 character. */
    194196                blen = STR_BOUNDS(1);
    195         } else
    196                 fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
     197        } else {
     198                int rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd);
     199                if (rc != EOK) {
     200                        fd = -1;
     201                }
     202        }
    197203       
    198204        if (fd < 0) {
     
    250256                }
    251257               
    252                 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);
     258                rc = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read,
     259                    &bytes);
    253260                copied_bytes = 0;
    254261
    255                 if (bytes > 0) {
     262                if (rc == EOK && bytes > 0) {
    256263                        buff[bytes] = '\0';
    257264                        offset = 0;
     
    284291                if (reading_stdin)
    285292                        fflush(stdout);
    286         } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
     293        } while (rc == EOK && bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
    287294
    288295        vfs_put(fd);
    289         if (bytes == -1) {
     296        if (rc != EOK) {
    290297                printf("Error reading %s\n", fname);
    291298                free(buff);
     
    321328        console_rows = 0;
    322329        should_quit = false;
     330        dash_represents_stdin = false;
    323331        console = console_init(stdin, stdout);
    324332        number = false;
     
    331339
    332340        for (c = 0, optreset = 1, optind = 0, opt_ind = 0; c != -1;) {
    333                 c = getopt_long(argc, argv, "xhvmH:t:b:s:n", long_options, &opt_ind);
     341                c = getopt_long(argc, argv, "xhvmH:t:b:sn", long_options, &opt_ind);
    334342                switch (c) {
    335343                case 'h':
Note: See TracChangeset for help on using the changeset viewer.