#include <linux/elf.h>
 #include <linux/types.h>
 
+const char *outfilename;
+
 /* Symbols that we need in vdso2c. */
 enum {
        sym_vvar_page,
        va_start(ap, format);
        fprintf(stderr, "Error: ");
        vfprintf(stderr, format, ap);
+       unlink(outfilename);
        exit(1);
        va_end(ap);
 }
 #undef Elf_Sym
 #undef Elf_Dyn
 
-static int go(void *addr, size_t len, FILE *outfile, const char *name)
+static void go(void *addr, size_t len, FILE *outfile, const char *name)
 {
        Elf64_Ehdr *hdr = (Elf64_Ehdr *)addr;
 
        if (hdr->e_ident[EI_CLASS] == ELFCLASS64) {
-               return go64(addr, len, outfile, name);
+               go64(addr, len, outfile, name);
        } else if (hdr->e_ident[EI_CLASS] == ELFCLASS32) {
-               return go32(addr, len, outfile, name);
+               go32(addr, len, outfile, name);
        } else {
-               fprintf(stderr, "Error: unknown ELF class\n");
-               return 1;
+               fail("unknown ELF class\n");
        }
 }
 
        off_t len;
        void *addr;
        FILE *outfile;
-       int ret;
        char *name, *tmp;
        int namelen;
 
        if (addr == MAP_FAILED)
                err(1, "mmap");
 
-       outfile = fopen(argv[2], "w");
+       outfilename = argv[2];
+       outfile = fopen(outfilename, "w");
        if (!outfile)
                err(1, "%s", argv[2]);
 
-       ret = go(addr, (size_t)len, outfile, name);
+       go(addr, (size_t)len, outfile, name);
 
        munmap(addr, len);
        fclose(outfile);
 
-       return ret;
+       return 0;
 }
 
  * are built for 32-bit userspace.
  */
 
-static int GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
+static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
 {
        int found_load = 0;
        unsigned long load_size = -1;  /* Work around bogus warning */
                        alt_sec = sh;
        }
 
-       if (!symtab_hdr) {
+       if (!symtab_hdr)
                fail("no symbol table\n");
-               return 1;
-       }
 
        strtab_hdr = addr + hdr->e_shoff +
                hdr->e_shentsize * symtab_hdr->sh_link;
 
        if (!name) {
                fwrite(addr, load_size, 1, outfile);
-               return 0;
+               return;
        }
 
        fprintf(outfile, "/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n\n");
                                required_syms[i], syms[i]);
        }
        fprintf(outfile, "};\n");
-
-       return 0;
 }