1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5 *
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
22 */
23 /*
24 * HISTORY
25 */
26 #ifdef REV_INFO
27 #ifndef lint
28 static char rcsid[] = "$XConsortium: file.c /main/6 1995/07/14 10:02:30 drk $"
29 #endif
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include "file.h"
35
36 #ifndef X_NOT_STDC_ENV
37 #include <unistd.h>
38 #endif
39
40 /* =====================================================================
41 * Open File
42 */
43
44 FILE * OpenFile(char *path)
45 {
46 return fopen(path, "r");
47 }
48
49 /* =====================================================================
50 * Close File
51 */
52
CloseFile(FILE * file)53 void CloseFile(FILE * file)
54 {
55 fclose (file);
56 }
57
58 /* =====================================================================
59 * Read File in buffer
60 */
61
ReadFile(FILE * file,int * filesize)62 char * ReadFile(FILE * file, int *filesize)
63 {
64 char * buffer;
65
66 fseek(file, 0L, SEEK_END);
67 * filesize = ftell(file);
68 /* fgetpos(file, (fpos_t *) filesize);*/
69 rewind(file);
70 buffer = (char *) XtMalloc(*filesize+1);
71 if (fread(buffer, 1, *filesize, file) == *filesize ) {
72 buffer[*filesize] = '\0';
73 return buffer;
74 }
75 XtFree(buffer);
76 return NULL;
77 }
78