2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3
Copyright (C) 2005- The University of Notre Dame
4
This software is distributed under the GNU General Public License.
5
See the file COPYING for details.
8
#include "hash_table.h"
9
#include "copy_stream.h"
10
#include "ftsh_error.h"
21
static struct hash_table *table=0;
23
static int buffer_init()
26
table = hash_table_create( 127, hash_string );
32
int buffer_open_input( const char *tag )
36
if(!buffer_init()) return 0;
38
fd = (PTRINT_T) hash_table_lookup(table,tag);
49
static int buffer_open( const char *tag, int do_truncate )
55
if(!buffer_init()) return 0;
58
fd = (long) hash_table_lookup(table,tag);
65
strcpy(path,"/tmp/ftsh.XXXXXX");
72
old = (PTRINT_T) hash_table_remove(table,tag);
75
if(!hash_table_insert(table,tag,(void*)fd)) {
76
ftsh_fatal(0,"out of memory");
84
int buffer_open_output( const char *tag )
86
return buffer_open(tag,1);
89
int buffer_open_append( const char *tag )
91
return buffer_open(tag,0);
94
char * buffer_load( const char *tag )
101
fd = buffer_open_input(tag);
102
if(fd<0) goto failure;
105
if(nfd<0) goto failure;
107
stream = fdopen(nfd,"r");
108
if(!stream) goto failure;
109
if(!copy_stream_to_buffer(stream,&buffer)) goto failure;
119
if(nfd>=0) close(nfd);
125
int buffer_save( const char *tag, const char *data )
129
fd = buffer_open_output(tag);
132
if(full_write(fd,data,strlen(data))==strlen(data)) {
139
int buffer_delete( const char *tag )
143
if(!buffer_init()) return 0;
145
fd = (long) hash_table_remove(table,tag);