Ignore:
File:
1 edited

Legend:

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

    r6afc9d7 rce04ea44  
    3333#include <getopt.h>
    3434#include <str.h>
    35 #include <fcntl.h>
    3635#include <io/console.h>
    3736#include <io/color.h>
     
    187186        size_t offset = 0, copied_bytes = 0;
    188187        off64_t file_size = 0, length = 0;
     188        aoff64_t pos = 0;
    189189
    190190        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
     
    195195                blen = STR_BOUNDS(1);
    196196        } else
    197                 fd = open(fname, O_RDONLY);
     197                fd = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
    198198       
    199199        if (fd < 0) {
     
    203203
    204204        if (NULL == (buff = (char *) malloc(blen + 1))) {
    205                 close(fd);
     205                vfs_put(fd);
    206206                printf("Unable to allocate enough memory to read %s\n",
    207                         fname);
     207                    fname);
    208208                return 1;
    209209        }
    210210
    211211        if (tail != CAT_FULL_FILE) {
    212                 file_size = lseek(fd, 0, SEEK_END);
     212                struct stat st;
     213
     214                if (vfs_stat(fd, &st) != EOK) {
     215                        vfs_put(fd);
     216                        free(buff);
     217                        printf("Unable to vfs_stat %d\n", fd);
     218                        return 1;
     219                }
     220                file_size = st.size;
    213221                if (head == CAT_FULL_FILE) {
    214222                        head = file_size;
     
    223231
    224232                if (tail_first) {
    225                         lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);
     233                        pos = (tail >= file_size) ? 0 : (file_size - tail);
    226234                } else {
    227                         lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);
     235                        pos = ((head - tail) >= file_size) ? 0 : (head - tail);
    228236                }
    229237        } else
     
    243251                }
    244252               
    245                 bytes = read(fd, buff + copied_bytes, bytes_to_read);
     253                bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);
    246254                copied_bytes = 0;
    247255
     
    279287        } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
    280288
    281         close(fd);
     289        vfs_put(fd);
    282290        if (bytes == -1) {
    283291                printf("Error reading %s\n", fname);
Note: See TracChangeset for help on using the changeset viewer.