Merge change 22835 into eclair

* changes:
  init: builtins: Add 'copy' command to init.rc parser
This commit is contained in:
Android (Google) Code Review 2009-08-26 17:11:18 -07:00
commit fc279227ec
3 changed files with 65 additions and 0 deletions

View File

@ -427,6 +427,68 @@ int do_write(int nargs, char **args)
return write_file(args[1], args[2]);
}
int do_copy(int nargs, char **args)
{
char *buffer = NULL;
int rc = 0;
int fd1 = -1, fd2 = -1;
struct stat info;
int brtw, brtr;
char *p;
if (nargs != 3)
return -1;
if (stat(args[1], &info) < 0)
return -1;
if ((fd1 = open(args[1], O_RDONLY)) < 0)
goto out_err;
if ((fd2 = open(args[2], O_WRONLY|O_CREAT, 0660)) < 0)
goto out_err;
if (!(buffer = malloc(info.st_size)))
goto out_err;
p = buffer;
brtr = info.st_size;
while(brtr) {
rc = read(fd1, p, brtr);
if (rc < 0)
goto out_err;
if (rc == 0)
break;
p += rc;
brtr -= rc;
}
p = buffer;
brtw = info.st_size;
while(brtw) {
rc = write(fd2, p, brtw);
if (rc < 0)
goto out_err;
if (rc == 0)
break;
p += rc;
brtw -= rc;
}
rc = 0;
goto out;
out_err:
rc = -1;
out:
if (buffer)
free(buffer);
if (fd1 >= 0)
close(fd1);
if (fd2 >= 0)
close(fd2);
return rc;
}
int do_chown(int nargs, char **args) {
/* GID is optional. */
if (nargs == 3) {

View File

@ -21,6 +21,7 @@ int do_trigger(int nargs, char **args);
int do_symlink(int nargs, char **args);
int do_sysclktz(int nargs, char **args);
int do_write(int nargs, char **args);
int do_copy(int nargs, char **args);
int do_chown(int nargs, char **args);
int do_chmod(int nargs, char **args);
int do_loglevel(int nargs, char **args);
@ -65,6 +66,7 @@ enum {
KEYWORD(sysclktz, COMMAND, 1, do_sysclktz)
KEYWORD(user, OPTION, 0, 0)
KEYWORD(write, COMMAND, 2, do_write)
KEYWORD(copy, COMMAND, 2, do_copy)
KEYWORD(chown, COMMAND, 2, do_chown)
KEYWORD(chmod, COMMAND, 2, do_chmod)
KEYWORD(loglevel, COMMAND, 1, do_loglevel)

View File

@ -127,6 +127,7 @@ int lookup_keyword(const char *s)
{
switch (*s++) {
case 'c':
if (!strcmp(s, "opy")) return K_copy;
if (!strcmp(s, "apability")) return K_capability;
if (!strcmp(s, "lass")) return K_class;
if (!strcmp(s, "lass_start")) return K_class_start;