[comp.os.minix] Getting rid of _cleanup

ast@cs.vu.nl (Andy Tanenbaum) (12/13/87)

There was a lot of discussion about how to get rid of my calls to _cleanup
earlier.  Here is the solution that I finally adopted.    The following commands
should do the job.
  cc -c -LIB exit.c putc.c
  ar r /usr/lib/libc.a exit.c putc.c
  ar x /usr/lib/libc.a cleanup.s
  ar d /usr/lib/libc.a cleanup.s
  ar bfork.s /usr/lib/libc.a cleanup.s

This requires the new archiver posted a while back (for the b option).
It also assumes that putting cleanup before fork.s will include cleanup.s
after exit.s and putc.s (check this).

Andy Tanenbaum (ast@cs.vu.nl)


: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
PATH=/bin:/usr/bin
echo Extracting \e\x\i\t\.\c
sed 's/^X//' > \e\x\i\t\.\c << '+ END-OF-FILE '\e\x\i\t\.\c
X#include "../include/lib.h"
X
XPUBLIC int (*__cleanup)();
X
XPUBLIC int exit(status)
Xint status;
X{
X  if (__cleanup) (*__cleanup)();
X  return callm1(MM, EXIT, status, 0, 0, NIL_PTR, NIL_PTR, NIL_PTR);
X}
+ END-OF-FILE exit.c
chmod 'u=rw,g=r,o=r' \e\x\i\t\.\c
set `sum \e\x\i\t\.\c`
sum=$1
case $sum in
11315)	:;;
*)	echo 'Bad sum in '\e\x\i\t\.\c >&2
esac
echo Extracting \p\u\t\c\.\c
sed 's/^X//' > \p\u\t\c\.\c << '+ END-OF-FILE '\p\u\t\c\.\c
X#include "../include/stdio.h"
X
Xextern int (*__cleanup)();
Xextern int _cleanup();
X
Xputc(ch, iop)
Xchar ch;
XFILE *iop;
X{
X	int n,
X	didwrite = 0;
X
X	if (testflag(iop, (_ERR | _EOF)))
X		return (EOF); 
X
X	if ( !testflag(iop,WRITEMODE))
X		return(EOF);
X
X	if ( testflag(iop,UNBUFF)){
X		n = write(iop->_fd,&ch,1);
X		iop->_count = 1;
X		didwrite++;
X	}
X	else{
X		__cleanup = _cleanup;
X		*iop->_ptr++ = ch;
X		if ((++iop->_count) >= BUFSIZ && !testflag(iop,STRINGS) ){
X			n = write(iop->_fd,iop->_buf,iop->_count);
X			iop->_ptr = iop->_buf;
X			didwrite++;
X		}
X	}
X
X	if (didwrite){
X		if (n<=0 || iop->_count != n){
X			if (n < 0)
X				iop->_flags |= _ERR;
X			else
X				iop->_flags |= _EOF;
X			return (EOF);
X		}
X		iop->_count=0;
X	}
X	return(ch & CMASK);
X}
X
+ END-OF-FILE putc.c
chmod 'u=rw,g=r,o=r' \p\u\t\c\.\c
set `sum \p\u\t\c\.\c`
sum=$1
case $sum in
49878)	:;;
*)	echo 'Bad sum in '\p\u\t\c\.\c >&2
esac
exit 0