home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / telix / tlx3sort.zip / MISC.C next >
C/C++ Source or Header  |  1988-07-13  |  2KB  |  94 lines

  1. /**
  2.  *
  3.  *  Module:       misc.c
  4.  *  Version:      2.0
  5.  *  Description:  miscellaneous functions
  6.  *  Author:       Paul Roub
  7.  *
  8.  *  Revision History:
  9.  *     7-13-88 : created
  10.  *
  11.  *      This program and its sources are Copyright (C) 1988 by Paul Roub
  12.  *      and may not be sold for profit without the express written
  13.  *      consent of the author.  Redistribute them (in their entirety) as
  14.  *      you wish,  provided no fee is charged and all materials are
  15.  *      present and unmodified.
  16.  *
  17. **/
  18.  
  19. /*<f>*/
  20. #include  <malloc.h>
  21. #include  <stdarg.h>
  22. #include  <stdio.h>
  23. #include  <stdlib.h>
  24.  
  25. #include  "tlx30.h"
  26. #include  "tlxsort.h"
  27.  
  28.  
  29. /*<f>*/
  30. /**
  31.  *
  32.  *  Function:     FILE *ffopen()
  33.  *  Description:  open file - quit if it can't be opened
  34.  *  Returns:      FILE pointer
  35.  *
  36. **/
  37. FILE *ffopen(name, mode)
  38. char      *name;
  39. char      *mode;
  40. {
  41.   FILE      *res;
  42.  
  43.   res = fopen(name, mode);
  44.  
  45.   if (res == NULL)
  46.     quitf("can't open file %s", name);
  47.  
  48.   return(res);
  49. }
  50.  
  51.  
  52. /*<f>*/
  53. /**
  54.  *
  55.  *  Name:         quitf()
  56.  *  Description:  prints message to stderr,  exits with return code 1
  57.  *  Returns:      nothing
  58.  *
  59. **/
  60. void quitf(str, ...)
  61. char      *str;
  62. {
  63.   va_list   arg_ptr;
  64.  
  65.   va_start(arg_ptr, str);
  66.   vfprintf(stderr, str, arg_ptr);
  67.   va_end(arg_ptr);
  68.  
  69.   fputc('\n', stderr);
  70.  
  71.   exit(1);
  72. }
  73.  
  74.  
  75. /*<f>*/
  76. /**
  77.  *
  78.  *  Name:         void *mmalloc()
  79.  *  Description:  malloc() with memory check: aborts if insufficient memory
  80.  *  Returns:      pointer to allocated block
  81.  *
  82. **/
  83. void *mmalloc(size)
  84. size_t    size;
  85. {
  86.   void      *res;
  87.  
  88.   if ((res = malloc(size)) == NULL)
  89.     quitf("\n\nInsufficient memory");
  90.  
  91.   return(res);
  92. }
  93.  
  94.