Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : BUFALLOC.C

 
Output of file : BUFALLOC.C contained in archive : STLTH22.ZIP
/*
bufalloc.c
Stealth Bomber Version 2.2

Kevin Dean
Fairview Mall P.O. Box 55074
1800 Sheppard Avenue East
Willowdale, Ontario
CANADA M2J 5B9
CompuServe ID: 76336,3114

February 10, 1992

This module allocates a simple memory buffer whose size depends on the
amount of memory available. The size of the buffer is halved each time the
allocation fails until memory is successfully allocated or the size goes below
the minimum size requested.

This code is public domain.
*/


#include

#include "vircheck.h"


/***/
/* Allocate a buffer of flexible size. */
void *bufalloc(size_t *size, size_t minsize)
{
void *buffer; /* Buffer allocated. */
size_t bufsize; /* Size of buffer allocated. */

/* Allocate as big a buffer as possible (at least minsize). */
for (bufsize = *size; bufsize >= minsize && !(buffer = malloc(bufsize)); bufsize /= 2);

/* Save buffer size. */
*size = bufsize;

return (buffer);
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : STLTH22.ZIP
Filename : BUFALLOC.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/