Subversion Repositories HelenOS

Rev

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

Rev 3675 Rev 4377
Line 32... Line 32...
32
#include <stdlib.h>
32
#include <stdlib.h>
33
#include <unistd.h>
33
#include <unistd.h>
34
#include <getopt.h>
34
#include <getopt.h>
35
#include <string.h>
35
#include <string.h>
36
#include <fcntl.h>
36
#include <fcntl.h>
37
#include <assert.h>
-
 
38
#include "config.h"
37
#include "config.h"
39
#include "util.h"
38
#include "util.h"
40
#include "errors.h"
39
#include "errors.h"
41
#include "entry.h"
40
#include "entry.h"
42
#include "cp.h"
41
#include "cp.h"
Line 68... Line 67...
68
        return -1;
67
        return -1;
69
 
68
 
70
    return (int) t1;
69
    return (int) t1;
71
}
70
}
72
 
71
 
73
static int64_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,
-
 
73
    size_t blen, int vb)
74
{
74
{
75
    int fd1, fd2, bytes = 0;
75
    int fd1, fd2, bytes = 0;
76
    off_t total = 0;
76
    off_t total = 0;
77
    int64_t copied = 0;
77
    int64_t copied = 0;
78
    char *buff = NULL;
78
    char *buff = NULL;
Line 122... Line 122...
122
            bytes = write(fd2, buff, res);
122
            bytes = write(fd2, buff, res);
123
            if (bytes < 0)
123
            if (bytes < 0)
124
                goto err;
124
                goto err;
125
            res -= bytes;
125
            res -= bytes;
126
        } while (res > 0);
126
        } while (res > 0);
-
 
127
 
-
 
128
        /* TODO: re-insert assert() once this is stand alone,
-
 
129
         * removed as abort() exits the entire shell
-
 
130
         */
127
        assert(res == 0);
131
        if (res != 0) {
-
 
132
            printf("\n%d more bytes than actually exist were copied\n", res);
-
 
133
            goto err;
-
 
134
        }
128
    }
135
    }
129
 
136
 
130
    if (bytes < 0) {
137
    if (bytes < 0) {
131
err:
138
err:
132
        printf("Error copying %s, (%d)\n", src, bytes);
139
        printf("\nError copying %s, (%d)\n", src, bytes);
133
        copied = bytes;
140
        copied = bytes;
134
    }
141
    }
135
 
142
 
136
out:
143
out:
137
    close(fd1);
144
    close(fd1);