1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: readfile.c 237 2006-11-16 04:08:15Z mikes@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
18
#include "../pith/headers.h"
20
#include "../pith/store.h"
25
/*----------------------------------------------------------------------
26
Read whole file into memory
28
Args: filename -- path name of file to read
30
Result: Returns pointer to malloced memory with the contents of the file
33
This won't work very well if the file has NULLs in it.
36
read_file(char *filename, int so_get_flags)
38
STORE_S *in_file = NULL, *out_store = NULL;
40
char *return_text = NULL;
42
if((in_file = so_get(FileStar, filename, so_get_flags | READ_ACCESS))){
45
if(!(out_store = so_get(CharStar, NULL, EDIT_ACCESS))){
51
* We're just using the READ_FROM_LOCALE flag to translate
54
while(so_readc(&c, in_file))
55
so_writec(c, out_store);
61
return_text = (char *) so_text(out_store);
62
/* avoid freeing this */
64
out_store->txt = NULL;