Adds the cp command
git-svn-id: file:///home/svn/framework3/trunk@5168 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
ca55f84b70
commit
492d286157
|
@ -42,8 +42,9 @@
|
|||
void cmd_chroot(int, char * []);
|
||||
void cmd_link(int, char * []);
|
||||
void cmd_symlink(int, char * []);
|
||||
|
||||
/* Privilges */
|
||||
void cmd_cp(int, char * []);
|
||||
|
||||
/* Privileges */
|
||||
/* XXX: Print groups */
|
||||
void cmd_getid(int, char * []);
|
||||
void cmd_setuid(int, char * []);
|
||||
|
|
|
@ -51,6 +51,7 @@ void cmd_help(int argc, char * argv[])
|
|||
" chroot <path> Change root directory to <path>\n"
|
||||
" link <file> <reference> Hard link <reference> to <file>\n"
|
||||
" symlink <file> <reference> Symbolically link <reference> to <file>\n"
|
||||
" cp <file> <file> Copy a file from one directory to another\n"
|
||||
|
||||
"\n"
|
||||
" getid Print information about [e][ug]id\n"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
|
@ -252,3 +253,31 @@ void cmd_symlink(int argc, char * argv[])
|
|||
if(symlink(argv[1], argv[2]) == -1)
|
||||
perror("symlink");
|
||||
}
|
||||
|
||||
void cmd_cp(int argc, char * argv[])
|
||||
{
|
||||
int src, dst, len;
|
||||
char buff[4096];
|
||||
|
||||
src = open(argv[1], O_RDONLY);
|
||||
if(src == -1)
|
||||
perror("open(src)");
|
||||
|
||||
dst = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, S_IRWXU);
|
||||
if (dst == -1) {
|
||||
close(src);
|
||||
perror("open(dst)");
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
len = read(src, buff, sizeof(buff));
|
||||
if (len == -1) break;
|
||||
if (len == 0) break;
|
||||
|
||||
write(dst, buff, len);
|
||||
if (len < sizeof(buff)) break;
|
||||
}
|
||||
close(src);
|
||||
close(dst);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ struct __cmdhandler handlerlist[] =
|
|||
{ "chroot", &cmd_chroot, 1, 1, 1 },
|
||||
{ "link", &cmd_link, 1, 2, 2 },
|
||||
{ "symlink", &cmd_symlink, 1, 2, 2 },
|
||||
{ "cp", &cmd_cp, 1, 2, 2 },
|
||||
|
||||
{ "getid", &cmd_getid, 1, 0, 0 },
|
||||
{ "setuid", &cmd_setuid, 1, 1, 1 },
|
||||
|
|
Loading…
Reference in New Issue