On 10/13/2013 12:20:35 AM, [email protected] wrote:
Here's a revised cpio.
I've reduced the use of malloc(), dropped an extra function call, and
-at least in theory- allowed proper handling of non-regular files.
(If we have a file we can't read, we still should record it when it's
of a type where file content is ignored).

I missed a curve, the diff between this and the previuos version was the following, and I don't see how that matches up with the above description? (Reduce use of malloc?)

Rob

diff -r 960462460639 toys/pending/cpio.c
--- a/toys/pending/cpio.c       Sat Oct 26 12:59:28 2013 -0500
+++ b/toys/pending/cpio.c       Sat Oct 26 15:14:22 2013 -0500
@@ -27,9 +27,10 @@
 /* Iterate through a list of files, read from stdin.
  * No users need rw.
  */
-void loopfiles_stdin(void (*function)(int fd, char *name))
+void loopfiles_stdin(void (*function)(int fd, char *name, struct stat st))
 {
   int fd;
+  struct stat st;
   char *name = toybuf;

   while (name != NULL){
@@ -39,9 +40,10 @@
     if (name != NULL) {
       if (toybuf[strlen(name) - 1] == '\n' ) {
         toybuf[strlen(name) - 1 ] = '\0';
+        if (lstat(name, &st) == -1) continue;
        fd = open(name, O_RDONLY);
-       if (fd > 0) {
-          function(fd, name);
+       if (fd > 0 || !S_ISREG(st.st_mode)) {
+          function(fd, name, st);
          close(fd);
        }
        errno = 0;
@@ -105,13 +107,6 @@
   if (buf.st_size % 4) write(1, &n, 4 - (buf.st_size % 4));
 }

-void write_cpio_call(int fd, char *name)
-{
-  struct stat buf;
-  if (lstat(name, &buf) == -1) return;
-  write_cpio_member(fd, name, buf);
-}
-
//convert hex to uint; mostly to allow using bits of non-terminated strings
 unsigned int htou(char * hex)
 {
@@ -224,7 +219,7 @@
 {
   switch (toys.optflags & (FLAG_i | FLAG_o | FLAG_t)) {
     case FLAG_o:
-      loopfiles_stdin(write_cpio_call);
+      loopfiles_stdin(write_cpio_member);
write(1, "07070100000000000000000000000000000000000000010000000000000000" "000000000000000000000000000000000000000B00000000TRAILER!!!\0\0\0", 124);
       break;

Rob
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to