home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / stdlib / rcs / atexit.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  2.1 KB  |  93 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.17.01.06;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*-
  26.  * Copyright (c) 1990 The Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * This code is derived from software contributed to Berkeley by
  30.  * Chris Torek.
  31.  *
  32.  * Redistribution and use in source and binary forms are permitted
  33.  * provided that: (1) source distributions retain this entire copyright
  34.  * notice and comment, and (2) distributions including binaries display
  35.  * the following acknowledgement:  ``This product includes software
  36.  * developed by the University of California, Berkeley and its contributors''
  37.  * in the documentation or other materials provided with the distribution
  38.  * and in all advertising materials mentioning features or use of this
  39.  * software. Neither the name of the University nor the names of its
  40.  * contributors may be used to endorse or promote products derived
  41.  * from this software without specific prior written permission.
  42.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  43.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  44.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  45.  */
  46.  
  47. #if defined(LIBC_SCCS) && !defined(lint)
  48. static char sccsid[] = "@@(#)atexit.c    5.1 (Berkeley) 5/15/90";
  49. #endif /* LIBC_SCCS and not lint */
  50.  
  51. #define KERNEL
  52. #include "ixemul.h"
  53.  
  54. #include <stddef.h>
  55. #include <stdlib.h>
  56. #include "atexit.h"
  57.  
  58. #define __atexit (u.u_atexit)
  59.  
  60. /*
  61.  * Register a function to be performed at exit.
  62.  */
  63. int
  64. atexit(void (*fn)())
  65. {
  66.     register struct atexit *p;
  67.  
  68.     if ((p = __atexit) == 0)
  69.       {
  70.         /* don't need a static table anymore, since OpenLibrary() comes
  71.          * before ix_startup() */
  72.         __atexit = p = syscall (SYS_malloc, sizeof (struct atexit));
  73.         bzero (p, sizeof (*p));
  74.       }
  75.  
  76.     if (p->ind >= ATEXIT_SIZE) {
  77.         if ((p = syscall (SYS_malloc, sizeof(*p))) == NULL)
  78.             return (-1);
  79. #if 0
  80.         /* this was in the original source */
  81.         __atexit->next = p;
  82.         __atexit = p;
  83. #else
  84.         p->next = __atexit;
  85.         __atexit = p;
  86.         p->ind = 0;
  87. #endif
  88.     }
  89.     p->fns[p->ind++] = fn;
  90.     return (0);
  91. }
  92. @
  93.