Ignore:
Timestamp:
2017-03-24T20:31:54Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8e9b2534
Parents:
c9e3692
Message:

Remove VFS_IN_SEEK from VFS

File:
1 edited

Legend:

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

    rc9e3692 r58898d1d  
    3131#include <stdlib.h>
    3232#include <unistd.h>
     33#include <sys/stat.h>
    3334#include <getopt.h>
    3435#include <str.h>
     
    187188        size_t offset = 0, copied_bytes = 0;
    188189        off64_t file_size = 0, length = 0;
     190        aoff64_t pos = 0;
    189191
    190192        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
     
    205207                close(fd);
    206208                printf("Unable to allocate enough memory to read %s\n",
    207                         fname);
     209                    fname);
    208210                return 1;
    209211        }
    210212
    211213        if (tail != CAT_FULL_FILE) {
    212                 file_size = lseek(fd, 0, SEEK_END);
     214                struct stat st;
     215
     216                if (fstat(fd, &st) != EOK) {
     217                        close(fd);
     218                        free(buff);
     219                        printf("Unable to fstat %d\n", fd);
     220                        return 1;
     221                }
     222                file_size = st.size;
    213223                if (head == CAT_FULL_FILE) {
    214224                        head = file_size;
     
    223233
    224234                if (tail_first) {
    225                         lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);
     235                        pos = (tail >= file_size) ? 0 : (file_size - tail);
    226236                } else {
    227                         lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);
     237                        pos = ((head - tail) >= file_size) ? 0 : (head - tail);
    228238                }
    229239        } else
     
    243253                }
    244254               
    245                 bytes = read(fd, buff + copied_bytes, bytes_to_read);
     255                bytes = read(fd, &pos, buff + copied_bytes, bytes_to_read);
    246256                copied_bytes = 0;
    247257
Note: See TracChangeset for help on using the changeset viewer.