Expland `mymalloc' with malloc + error checking.

This commit is contained in:
David E. O'Brien 2001-07-24 14:15:51 +00:00
parent 44974a7f49
commit a9be9be874
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=80294
4 changed files with 10 additions and 17 deletions

View File

@ -156,7 +156,8 @@ static char *cwdname(void)
static size_t size = SIZE;
if (ptr == NULL)
ptr = (char *) mymalloc(size);
if ((ptr = malloc(size)) == NULL)
errx(EXIT_FAILURE, "virtual memory exhausted");
while (1)
{
@ -171,7 +172,8 @@ static char *cwdname(void)
free (ptr);
size += SIZE;
ptr = (char *) mymalloc(size);
if ((ptr = malloc(size)) == NULL)
errx(EXIT_FAILURE, "virtual memory exhausted");
}
}
@ -586,17 +588,6 @@ process_jobs(int argc, char **argv, int what)
}
} /* delete_jobs */
/* Global functions */
void *
mymalloc(size_t n)
{
void *p;
if ((p=malloc(n))==(void *)0)
errx(EXIT_FAILURE, "virtual memory exhausted");
return p;
}
int
main(int argc, char **argv)
{

View File

@ -21,11 +21,11 @@
* THEORY OF LIABILITY, WETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
extern int fcreated;
extern char *namep;
extern char atfile[];
extern char atverify;
void *mymalloc(size_t n);

View File

@ -185,7 +185,8 @@ init_scanner(int argc, char **argv)
while (argc-- > 0)
sc_len += strlen(*argv++);
sc_token = (char *) mymalloc(sc_len);
if ((sc_token = malloc(sc_len)) == NULL)
errx(EXIT_FAILURE, "virtual memory exhausted");
} /* init_scanner */
/*

View File

@ -64,7 +64,8 @@ static int check_for_user(FILE *fp,const char *name)
int found = 0;
len = strlen(name);
buffer = mymalloc(len+2);
if ((buffer = malloc(len+2)) == NULL)
errx(EXIT_FAILURE, "virtual memory exhausted");
while(fgets(buffer, len+2, fp) != NULL)
{