xref: /csrg-svn/old/awk/freeze.c (revision 48236)
1*48236Sbostic /*-
2*48236Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*48236Sbostic  * All rights reserved.
4*48236Sbostic  *
5*48236Sbostic  * %sccs.include.proprietary.c%
6*48236Sbostic  */
7*48236Sbostic 
814473Ssam #ifndef lint
9*48236Sbostic static char sccsid[] = "@(#)freeze.c	4.3 (Berkeley) 04/17/91";
10*48236Sbostic #endif /* not lint */
116670Smckusick 
126670Smckusick #include "stdio.h"
freeze(s)136670Smckusick freeze(s) char *s;
146670Smckusick {	int fd;
156670Smckusick 	unsigned int *len;
166670Smckusick 	len = (unsigned int *)sbrk(0);
176670Smckusick 	if((fd = creat(s, 0666)) < 0) {
186670Smckusick 		perror(s);
196670Smckusick 		return(1);
206670Smckusick 	}
216670Smckusick 	write(fd, &len, sizeof(len));
226670Smckusick 	write(fd, (char *)0, len);
236670Smckusick 	close(fd);
246670Smckusick 	return(0);
256670Smckusick }
266670Smckusick 
thaw(s)276670Smckusick thaw(s) char *s;
286670Smckusick {	int fd;
296670Smckusick 	unsigned int *len;
306670Smckusick 	if(*s == 0) {
316670Smckusick 		fprintf(stderr, "empty restore file\n");
326670Smckusick 		return(1);
336670Smckusick 	}
346670Smckusick 	if((fd = open(s, 0)) < 0) {
356670Smckusick 		perror(s);
366670Smckusick 		return(1);
376670Smckusick 	}
386670Smckusick 	read(fd, &len, sizeof(len));
396670Smckusick 	(void) brk(len);
406670Smckusick 	read(fd, (char *)0, len);
416670Smckusick 	close(fd);
426670Smckusick 	return(0);
436670Smckusick }
44