1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: readfile.c 761 2007-10-23 22:35:18Z hubert@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
;
73 /* our copy, to_file and from_file must be full paths. from_file
77 our_copy(char *to_file
, char *from_file
)
79 STORE_S
*in_cert
, *out_cert
;
82 in_cert
= so_get(FileStar
, from_file
, READ_ACCESS
| READ_FROM_LOCALE
);
86 out_cert
= so_get(FileStar
, to_file
, WRITE_ACCESS
| WRITE_TO_LOCALE
);
87 if (out_cert
== NULL
){
92 while(so_readc(&c
, in_cert
) > 0)
93 so_writec(c
, out_cert
);