/* * rl.c -- rl */ #include #include #include #include #include #include "obj.h" enum { RLENTSIZE = 4 + NNAME + 4, }; Sym *_sym; char *errs, *_filename, *libname, _firstname[NNAME], _symname[] = "__.SYMDEF"; int _nsym, /* number of symbols refed in current file */ verbose, vflag; /* verbose for reading of files */ Biobuf *_bin; Biobuf _bout; void readar(void), writerl(void), setoffsets(Sym *, int), fexec(char *, char *, ...); void main(int argc, char *argv[]) { int i, n; char magbuf[SARMAG]; Binit(&_bout, 1, OWRITE); argv0 = argv[0]; ARGBEGIN { case 'v': verbose = 1; break; } ARGEND _assure(CHUNK); for(i=0; i>8); Bputc(&b, off>>16); Bputc(&b, off>>24); n = Bwrite(&b, _sym[i].name, NNAME); if(n != NNAME) fprint(2, "%s: short write to %s\n", argv0, _symname); if(_sym[i].type == 'T') Bputc(&b, 0); else Bputc(&b, 1); /* padding */ Bputc(&b, 0); Bputc(&b, 0); Bputc(&b, 0); } Bclose(&b); close(fd); if(strcmp(_firstname, _symname) != 0) if(_symsize == 0) fexec("/bin/ar", "ar", "rb", _firstname, libname, _symname, 0); else{ fexec("/bin/ar", "ar", "mb", _firstname, libname, _symname, 0); fexec("/bin/ar", "ar", "r", libname, _symname, 0); } else fexec("/bin/ar", "ar", "r", libname, _symname, 0); remove(_symname); } void fexec(char *av0, char *av, ...) { int pid; Waitmsg w; switch(pid = fork()){ case -1: fprint(2, "%s: can't fork\n", argv0); exits("fork"); case 0: exec(av0, &av); fprint(2, "%s: can't exec\n", argv0); exits("exec"); } while(wait(&w) != -1 && atoi(w.pid) != pid) ; }