13 e = seprint(s, s+sizeof(s), "%s: ", argv0);
14 e = vseprint(e, s+sizeof(s), fmt, arg);
15 e = seprint(e, s+sizeof(s), "\n");
24 error("usage: %s -o ofile file\n\t%s file ...\n", argv0, argv0);
29 strip(char* file, char* out)
39 if((fd = open(file, OREAD)) < 0){
40 error("%s: open: %r", file);
44 if(!crackhdr(fd, &fhdr)){
45 error("%s: %r", file);
49 for(i = MIN_MAGIC; i <= MAX_MAGIC; i++){
50 if(fhdr.magic == _MAGIC(0, i) || fhdr.magic == _MAGIC(HDR_MAGIC, i))
54 error("%s: not a recognizeable binary", file);
59 if((dir = dirfstat(fd)) == nil){
60 error("%s: stat: %r", file);
65 length = fhdr.datoff+fhdr.datsz;
66 if(length == dir->length){
67 if(out == nil){ /* nothing to do */
68 error("%s: already stripped", file);
74 if(length > dir->length){
75 error("%s: strange length", file);
84 if((data = malloc(length)) == nil){
85 error("%s: malloc failure", file);
90 if(read(fd, data, length) != length){
91 error("%s: read: %r", file);
104 if(remove(file) < 0) {
105 error("%s: remove: %r", file);
111 if((fd = create(out, OWRITE, mode)) < 0){
112 error("%s: create: %r", out);
116 if(write(fd, data, length) != length){
117 error("%s: write: %r", out);
129 main(int argc, char* argv[])
160 r |= strip(*argv, nil);