home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / mdcopy / part02 / mdgetbuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-02  |  633 b   |  37 lines

  1. /*
  2.  * Created 1989 by greg yachuk.  Placed in the public domain.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <malloc.h>
  7.  
  8. #include "mdiskio.h"
  9.  
  10. /*
  11.  * _mdgetbuf -    allocate a buffer of given size.  if that fails,
  12.  *        allocate a buffer of standard size.  if *that*
  13.  *        fails, use a single characte buffer (in the struct).
  14.  *
  15.  * returns:    size of buffer allocated
  16.  */
  17. _mdgetbuf(mdp, blen)
  18. MDFILE *mdp;
  19. int    blen;
  20. {
  21.     mdp->flags |= _MDEMPTY;
  22.  
  23.     if ((mdp->buffer = malloc(blen)) == NULL && blen > BUFSIZ)
  24.     {
  25.         blen = BUFSIZ;
  26.         mdp->buffer = malloc(BUFSIZ);
  27.     }
  28.  
  29.     if (mdp->buffer == NULL)
  30.     {
  31.         mdp->buffer = &mdp->spare;
  32.         return (1);
  33.     }
  34.  
  35.     return (blen);
  36. }
  37.