Changeset 58898d1d in mainline for uspace/app/bdsh/cmds


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

Location:
uspace/app/bdsh/cmds/modules
Files:
4 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
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    rc9e3692 r58898d1d  
    7979        char buffer[2][CMP_BUFLEN];
    8080        ssize_t offset[2];
     81        aoff64_t pos[2] = {};
    8182
    8283        for (int i = 0; i < 2; i++) {
     
    9495                        ssize_t size;
    9596                        do {
    96                                 size = read(fd[i], buffer[i] + offset[i],
     97                                size = read(fd[i], &pos[i],
     98                                    buffer[i] + offset[i],
    9799                                    CMP_BUFLEN - offset[i]);
    98100                                if (size < 0) {
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rc9e3692 r58898d1d  
    377377        int64_t copied = 0;
    378378        char *buff = NULL;
     379        aoff64_t posr = 0, posw = 0;
     380        struct stat st;
    379381
    380382        if (vb)
     
    392394        }
    393395
    394         total = lseek(fd1, 0, SEEK_END);
    395 
     396        if (fstat(fd1, &st) != EOK) {
     397                printf("Unable to fstat %d\n", fd1);
     398                close(fd1);
     399                close(fd2);
     400                return -1;     
     401        }
     402
     403        total = st.size;
    396404        if (vb)
    397405                printf("%" PRIu64 " bytes to copy\n", total);
    398 
    399         lseek(fd1, 0, SEEK_SET);
    400406
    401407        if (NULL == (buff = (char *) malloc(blen))) {
     
    406412        }
    407413
    408         while ((bytes = read(fd1, buff, blen)) > 0) {
    409                 if ((bytes = write(fd2, buff, bytes)) < 0)
     414        while ((bytes = read(fd1, &posr, buff, blen)) > 0) {
     415                if ((bytes = write(fd2, &posw, buff, bytes)) < 0)
    410416                        break;
    411417                copied += bytes;
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rc9e3692 r58898d1d  
    121121        void *buffer;
    122122        bool create_sparse = false;
     123        aoff64_t pos = 0;
    123124
    124125        file_size = 0;
     
    164165        if (create_sparse && file_size > 0) {
    165166                const char byte = 0x00;
    166 
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
    168                         close(fd);
    169                         goto error;
    170                 }
    171 
    172                 rc2 = write(fd, &byte, sizeof(char));
     167               
     168                pos = file_size - 1;
     169                rc2 = write(fd, &pos, &byte, sizeof(char));
    173170                if (rc2 < 0) {
    174171                        close(fd);
     
    187184        while (total_written < file_size) {
    188185                to_write = min(file_size - total_written, BUFFER_SIZE);
    189                 rc = write(fd, buffer, to_write);
     186                rc = write(fd, &pos, buffer, to_write);
    190187                if (rc <= 0) {
    191188                        printf("%s: Error writing file (%d).\n", cmdname, errno);
Note: See TracChangeset for help on using the changeset viewer.