Subversion Repositories HelenOS

Rev

Rev 3641 | Rev 3643 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3641 Rev 3642
Line 67... Line 67...
67
        return -1;
67
        return -1;
68
 
68
 
69
    return (int) t1;
69
    return (int) t1;
70
}
70
}
71
 
71
 
72
static size_t copy_file(const char *src, const char *dest, size_t blen, int vb)
72
static int64_t copy_file(const char *src, const char *dest, size_t blen, int vb)
73
{
73
{
74
    int fd1, fd2, bytes = 0;
74
    int fd1, fd2, bytes = 0;
75
    off_t total = 0;
75
    off_t total = 0;
76
    size_t copied = 0;
76
    int copied = -1;
77
    char *buff = NULL;
77
    char *buff = NULL;
78
 
78
 
79
    if (vb)
79
    if (vb)
80
        printf("Copying %s to %s\n", src, dest);
80
        printf("Copying %s to %s\n", src, dest);
81
 
81
 
82
    if (-1 == (fd1 = open(src, O_RDONLY))) {
82
    if (-1 == (fd1 = open(src, O_RDONLY))) {
83
        printf("Unable to open source file %s\n", src);
83
        printf("Unable to open source file %s\n", src);
84
        return 0;
84
        return copied;
85
    }
85
    }
86
 
86
 
87
    if (-1 == (fd2 = open(dest, O_CREAT))) {
87
    if (-1 == (fd2 = open(dest, O_CREAT))) {
88
        printf("Unable to open destination file %s\n", dest);
88
        printf("Unable to open destination file %s\n", dest);
89
        return 0;
89
        return copied;
90
    }
90
    }
91
 
91
 
92
    total = lseek(fd1, 0, SEEK_END);
92
    total = lseek(fd1, 0, SEEK_END);
93
 
93
 
94
    if (vb)
94
    if (vb)
Line 109... Line 109...
109
        write(fd2, buff, blen);
109
        write(fd2, buff, blen);
110
    } while (bytes > 0);
110
    } while (bytes > 0);
111
 
111
 
112
    if (bytes == -1) {
112
    if (bytes == -1) {
113
        printf("Error copying %s\n", src);
113
        printf("Error copying %s\n", src);
114
        copied = 0;
114
        copied = bytes;
115
        goto out;
115
        goto out;
116
    }
116
    }
117
 
117
 
118
out:
118
out:
119
    close(fd1);
119
    close(fd1);
Line 146... Line 146...
146
}
146
}
147
 
147
 
148
int cmd_cp(char **argv)
148
int cmd_cp(char **argv)
149
{
149
{
150
    unsigned int argc, buffer = CP_DEFAULT_BUFLEN, verbose = 0;
150
    unsigned int argc, buffer = CP_DEFAULT_BUFLEN, verbose = 0;
151
    int c, opt_ind, ret = 0;
151
    int c, opt_ind;
-
 
152
    int64_t ret;
152
 
153
 
153
    argc = cli_count_args(argv);
154
    argc = cli_count_args(argv);
154
 
155
 
155
    for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
156
    for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
156
        c = getopt_long(argc, argv, "hvVfrb:", long_options, &opt_ind);
157
        c = getopt_long(argc, argv, "hvVfrb:", long_options, &opt_ind);