Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/hp2graph/mem.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "hp2graph.h"

Token clone(SharedToken token)
{
 Token t = strdup(token);
 if(!t) {
   fprintf(stderr,"Out of memory when cloning a string at %d\n",lexline);
   abort();
 }
 return t;
}

char *append(char *s1, char *s2)
{
 char *r = malloc(strlen(s1) + strlen(s2) + 1);
 if(r) {
   strcpy(r,s1);
   strcat(r,s2);
 } else {
   fprintf(stderr,"Out of memory when appending %s and %s\n",s1,s2);
   abort();
 }
 return r;
}


void *new(int s)
{
  return malloc(s);
}

void *xmalloc(int s)
{
  void *vp =  malloc(s);
  if(!vp) {
    fprintf(stderr,"Out of memory.");
    abort();
  }
  return vp;
}

void *extend(void *p, int s)
{
  if(p) 
    return realloc(p, s);
  else
    return malloc(s);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.