sltar

a simple tar implementation
git clone git://git.suckless.org/sltar
Log | Files | Refs | LICENSE

commit 936d41a3c62a6e644002499b2cc6df9225e0f88b
parent c0036d8d64220a64679f86e480dc86df486741e3
Author: gottox@rootkit.lan <unknown>
Date:   Wed, 19 Dec 2007 10:41:03 +0100

Trailing \0 are not written anymore; Reformating.
Diffstat:
sltar.c | 72++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/sltar.c b/sltar.c @@ -27,50 +27,50 @@ int main(int argc, char *argv[]) { USAGE; lname[100] = fname[100] = '\0'; for(l = 0, f = NULL; fread(b,END,1,stdin); l -= END) { - if(l <= 0) { + if(l <= 0) { if(*b == '\0') break; memcpy(fname,b,100); memcpy(lname,b+LINK,100); - switch(a) { - case 't': + l = strtoull(b + SIZE,0,8) + END; + if(a == 't') { puts(fname); + continue; + } + if(f) { + fclose(f); + f = NULL; + } + unlink(fname); + switch(b[TYPE]) { + case '0': /* file */ + if(!(f = fopen(b,"w"))) + perror(fname); + break; + case '1': /* hardlink */ + if(!link(lname,fname)) + perror(fname); + break; + case '2': /* symlink */ + if(!symlink(lname,fname)) + perror(fname); + break; + case '5': /* directory */ + if(mkdir(fname,(mode_t) strtoull(b + MODE,0,8))) + perror(fname); + break; + case '4': /* block device */ + case '3': /* char device */ + /* TODO */ + break; + case '6': /* fifo */ + /* TODO */ break; - case 'x': - if(f) { - fclose(f); - f = NULL; - } - unlink(b); - switch(b[TYPE]) { - case '0': /* file */ - if(!(f = fopen(b,"w"))) - perror(fname); - break; - case '1': /* hardlink */ - if(!link(lname,fname)) - perror(fname); - break; - case '2': /* symlink */ - if(!symlink(lname,fname)) - perror(fname); - break; - case '5': /* directory */ - if(mkdir(fname,(mode_t) strtoull(b+MODE,0,8))) - perror(fname); - break; - case '4': /* block device */ - case '3': /* char device */ - break; - case '6': /* fifo */ - break; - default: - puts("not supported filetype"); - } + default: + puts("not supported filetype"); } - l = strtoull(b+SIZE,0,8)+END; } - else if(a == 'x' && f && !fwrite(b,END,1,f)) { + else if(a == 'x' && f && !fwrite(b,l > 512 ? END : l,1,f)) { perror(fname); break; }