[Toybox] [New Toy] cpio, cleaned up a little

ibid.ag at gmail.com ibid.ag at gmail.com
Tue Oct 29 23:08:55 PDT 2013


On Sat, Oct 26, 2013 at 03:16:25PM -0500, Rob Landley wrote:
> On 10/13/2013 12:20:35 AM, ibid.ag at gmail.com 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?)

It looks like the version I sent first was later than I thought.
Before that change, there was this:


diff --git a/toys/pending/cpio.c b/toys/pending/cpio.c
index 1af4c54..6830bc7 100644
--- a/toys/pending/cpio.c
+++ b/toys/pending/cpio.c
@@ -69,11 +69,11 @@ struct newc_header {
 
 void write_cpio_member(int fd, char *name, struct stat buf)
 {
-  struct newc_header *hdr;
+  char ahdr[sizeof(struct newc_header) + 1];
+  struct newc_header *hdr = (struct newc_header *)ahdr;
   size_t out = 0;
   unsigned int n = 0x00000000, nlen = strlen(name) + 1;
 
-  hdr = malloc(sizeof(struct newc_header) + 1);
   memset(hdr, '0', sizeof(struct newc_header));
   if (S_ISDIR(buf.st_mode) || S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)
      || S_ISFIFO(buf.st_mode) || S_ISSOCK(buf.st_mode)) 


Which I guess got included in the resend.

Hope that clears things up...

Thanks,
Isaac Dunham

 1383113335.0


More information about the Toybox mailing list