vsm2

exeprimental virtual stack machine for *nix
Log | Files | Refs

cell.c (411B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 
      4 #include "cell.h"
      5 
      6 Cell *
      7 createcell(int n, void *p)
      8 {
      9 	Cell *new = malloc(sizeof(Cell));
     10 	new->n = n;
     11 	new->p = p;
     12 	return new;
     13 }
     14 
     15 Cell *
     16 celldup(Cell *cell)
     17 {
     18 	Cell *dup = malloc(sizeof(Cell));
     19 	dup->n = cell->n;
     20 	dup->p = malloc(cell->n);
     21 	memcpy(dup->p, cell->p, cell->n);
     22 	return dup;
     23 }
     24 
     25 void
     26 freecell(Cell *cell)
     27 {
     28 	if (cell != NULL) free(cell->p);
     29 	free(cell);
     30 }