Subversion Repositories HelenOS

Compare Revisions

Regard whitespace Rev 3649 → Rev 3650

/trunk/uspace/app/bdsh/cmds/modules/cp/cp.c
34,6 → 34,7
#include <getopt.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include "config.h"
#include "util.h"
#include "errors.h"
73,7 → 74,7
{
int fd1, fd2, bytes = 0;
off_t total = 0;
int64_t copied = -1;
int64_t copied = 0;
char *buff = NULL;
 
if (vb)
86,6 → 87,7
 
if (-1 == (fd2 = open(dest, O_CREAT))) {
printf("Unable to open destination file %s\n", dest);
close(fd1);
return copied;
}
 
96,28 → 98,39
 
lseek(fd1, 0, SEEK_SET);
 
if (NULL == (buff = (char *) malloc(blen + 1))) {
if (NULL == (buff = (char *) malloc(blen))) {
printf("Unable to allocate enough memory to read %s\n",
src);
copied = -1;
goto out;
}
 
for (;;) {
ssize_t res;
 
bytes = read(fd1, buff, blen);
if (bytes <= 0)
break;
copied += bytes;
res = bytes;
do {
if (-1 == (bytes = read(fd1, buff, blen)))
break;
/* We read a terminating NULL */
if (0 == bytes) {
copied ++;
break;
/*
* Theoretically, it may not be enough to call write()
* only once. Also the previous read() may have
* returned less data than requested.
*/
bytes = write(fd2, buff, res);
if (bytes < 0)
goto err;
res -= bytes;
} while (res > 0);
assert(res == 0);
}
copied += bytes;
write(fd2, buff, blen);
} while (bytes > 0);
 
if (bytes == -1) {
printf("Error copying %s\n", src);
if (bytes < 0) {
err:
printf("Error copying %s, (%d)\n", src, bytes);
copied = bytes;
goto out;
}
 
out:
130,11 → 143,7
 
void help_cmd_cp(unsigned int level)
{
if (level == HELP_SHORT) {
printf("`%s' copies files and directories\n", cmdname);
} else {
help_cmd_cp(HELP_SHORT);
printf(
static char helpfmt[] =
"Usage: %s [options] <source> <dest>\n"
"Options: (* indicates not yet implemented)\n"
" -h, --help A short option summary\n"
143,8 → 152,12
"* -f, --force Do not complain when <dest> exists\n"
"* -r, --recursive Copy entire directories\n"
" -b, --buffer ## Set the read buffer size to ##\n"
"Currently, %s is under development, some options might not work.\n",
cmdname, cmdname);
"Currently, %s is under development, some options may not work.\n";
if (level == HELP_SHORT) {
printf("`%s' copies files and directories\n", cmdname);
} else {
help_cmd_cp(HELP_SHORT);
printf(helpfmt, cmdname, cmdname);
}
 
return;
203,7 → 216,7
if (verbose)
printf("%d bytes copied\n", ret);
 
if (ret <= 0)
if (ret >= 0)
return CMD_SUCCESS;
else
return CMD_FAILURE;