Ignore:
File:
1 edited

Legend:

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

    rce04ea44 r6afc9d7  
    3333#include <getopt.h>
    3434#include <str.h>
     35#include <fcntl.h>
    3536#include <io/console.h>
    3637#include <io/color.h>
     
    186187        size_t offset = 0, copied_bytes = 0;
    187188        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 = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ);
     197                fd = open(fname, O_RDONLY);
    198198       
    199199        if (fd < 0) {
     
    203203
    204204        if (NULL == (buff = (char *) malloc(blen + 1))) {
    205                 vfs_put(fd);
     205                close(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                 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;
     212                file_size = lseek(fd, 0, SEEK_END);
    221213                if (head == CAT_FULL_FILE) {
    222214                        head = file_size;
     
    231223
    232224                if (tail_first) {
    233                         pos = (tail >= file_size) ? 0 : (file_size - tail);
     225                        lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);
    234226                } else {
    235                         pos = ((head - tail) >= file_size) ? 0 : (head - tail);
     227                        lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);
    236228                }
    237229        } else
     
    251243                }
    252244               
    253                 bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);
     245                bytes = read(fd, buff + copied_bytes, bytes_to_read);
    254246                copied_bytes = 0;
    255247
     
    287279        } while (bytes > 0 && !should_quit && (count < length || length == CAT_FULL_FILE));
    288280
    289         vfs_put(fd);
     281        close(fd);
    290282        if (bytes == -1) {
    291283                printf("Error reading %s\n", fname);
Note: See TracChangeset for help on using the changeset viewer.