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 2013-2021 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "../pith/headers.h"
21 #include "../pith/store.h"
26 /*----------------------------------------------------------------------
27 Read whole file into memory
29 Args: filename -- path name of file to read
31 Result: Returns pointer to malloced memory with the contents of the file
34 This won't work very well if the file has NULLs in it.
37 read_file(char *filename
, int so_get_flags
)
39 STORE_S
*in_file
= NULL
, *out_store
= NULL
;
41 char *return_text
= NULL
;
43 if((in_file
= so_get(FileStar
, filename
, so_get_flags
| READ_ACCESS
))){
46 if(!(out_store
= so_get(CharStar
, NULL
, EDIT_ACCESS
))){
52 * We're just using the READ_FROM_LOCALE flag to translate
55 while(so_readc(&c
, in_file
))
56 so_writec(c
, out_store
);
62 return_text
= (char *) so_text(out_store
);
63 /* avoid freeing this */
65 out_store
->txt
= NULL
;
74 /* our copy, to_file and from_file must be full paths. from_file
78 our_copy(char *to_file
, char *from_file
)
80 STORE_S
*in_cert
, *out_cert
;
83 in_cert
= so_get(FileStar
, from_file
, READ_ACCESS
| READ_FROM_LOCALE
);
87 out_cert
= so_get(FileStar
, to_file
, WRITE_ACCESS
| WRITE_TO_LOCALE
);
88 if (out_cert
== NULL
){
93 so_seek(out_cert
, 0L, 0);
94 so_truncate(out_cert
, 0);
96 while(so_readc(&c
, in_cert
) > 0)
97 so_writec(c
, out_cert
);