home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / top / util.c < prev   
C/C++ Source or Header  |  1991-02-22  |  1KB  |  60 lines

  1. /* Copyright (c) 1988,1991 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. /*
  15.  * strsave(s) - copy s to dynamically allocated space
  16.  */
  17. char *
  18. strsave(s)
  19. register char    *s;
  20. {
  21.     char    *malloc(), *strcpy();
  22.  
  23.     return strcpy(malloc((unsigned) (strlen(s) + 1)), s);
  24. }
  25.  
  26. /*
  27.  * alloc() - malloc with error checking
  28.  */
  29. char *
  30. alloc(n)
  31. int    n;
  32. {
  33.     extern    char    *malloc();
  34.     char    *p;
  35.  
  36.     if ((p = malloc(n)) == NULL) {
  37.         fprintf(stderr, "top: out of memory\n");
  38.         exit(1);
  39.     }
  40.     return p;
  41. }
  42.  
  43. #if    MINIX || UNIX
  44.  
  45. remove(f)
  46. char    *f;
  47. {
  48.     unlink(f);
  49. }
  50.  
  51. rename(f1, f2)
  52. char    *f1, *f2;
  53. {
  54.     unlink(f2);
  55.     link(f1, f2);
  56.     unlink(f1);
  57. }
  58.  
  59. #endif
  60.