home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / zc.lzh / ZC / ZCSRC.LZH / top / util.c < prev   
Encoding:
C/C++ Source or Header  |  1989-05-27  |  1.2 KB  |  63 lines

  1. /* Copyright (c) 1988 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. /*
  13.  * Changes for Amgia version by Jeff Lydiatt marked with Jal.
  14.  */
  15.  
  16. #include <stdio.h>
  17.  
  18. /*
  19.  * strsave(s) - copy s to dynamically allocated space
  20.  */
  21. char *
  22. strsave(s)
  23. register char    *s;
  24. {
  25.     char    *malloc(), *strcpy();
  26.  
  27.     return strcpy(malloc((unsigned) (strlen(s) + 1)), s);
  28. }
  29.  
  30. /*
  31.  * alloc() - malloc with error checking
  32.  */
  33. char *
  34. alloc(n)
  35. int    n;
  36. {
  37.     extern    char    *malloc();
  38.     char    *p;
  39.  
  40.     if ((p = malloc(n)) == NULL) {
  41.         fprintf(stderr, "top: out of memory\n");
  42.         exit(1);
  43.     }
  44.     return p;
  45. }
  46.  
  47. /*
  48.  * Jal - added case insensitive compare.
  49.  */
  50.  
  51. #include <ctype.h>
  52.  
  53. int stricmp(str1, str2)
  54.     register char *str1, *str2;
  55.     {
  56.     register char c1, c2;
  57.  
  58.     while((c1 = _toupper(*str1++)) == (c2 = _toupper(*str2++)))
  59.         if(c1 == '\0')
  60.             return(0);
  61.     return(c1 - c2);
  62.     }
  63.