1 |
cebix |
1.1 |
/* |
2 |
|
|
* xpram_unix.cpp - XPRAM handling, Unix specific stuff |
3 |
|
|
* |
4 |
cebix |
1.3 |
* Basilisk II (C) 1997-2000 Christian Bauer |
5 |
cebix |
1.1 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "sysdeps.h" |
22 |
|
|
|
23 |
|
|
#include <stdlib.h> |
24 |
|
|
|
25 |
|
|
#include "xpram.h" |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
// XPRAM file name and path |
29 |
|
|
const char XPRAM_FILE_NAME[] = ".basilisk_ii_xpram"; |
30 |
|
|
static char xpram_path[1024]; |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* |
34 |
|
|
* Load XPRAM from settings file |
35 |
|
|
*/ |
36 |
|
|
|
37 |
|
|
void LoadXPRAM(void) |
38 |
|
|
{ |
39 |
|
|
// Construct XPRAM path |
40 |
|
|
xpram_path[0] = 0; |
41 |
|
|
char *home = getenv("HOME"); |
42 |
|
|
if (home != NULL && strlen(home) < 1000) { |
43 |
|
|
strncpy(xpram_path, home, 1000); |
44 |
|
|
strcat(xpram_path, "/"); |
45 |
|
|
} |
46 |
|
|
strcat(xpram_path, XPRAM_FILE_NAME); |
47 |
|
|
|
48 |
|
|
// Load XPRAM from settings file |
49 |
|
|
int fd; |
50 |
|
|
if ((fd = open(xpram_path, O_RDONLY)) >= 0) { |
51 |
|
|
read(fd, XPRAM, 256); |
52 |
|
|
close(fd); |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/* |
58 |
|
|
* Save XPRAM to settings file |
59 |
|
|
*/ |
60 |
|
|
|
61 |
|
|
void SaveXPRAM(void) |
62 |
|
|
{ |
63 |
|
|
int fd; |
64 |
cebix |
1.2 |
if ((fd = open(xpram_path, O_WRONLY | O_CREAT, 0666)) >= 0) { |
65 |
cebix |
1.1 |
write(fd, XPRAM, 256); |
66 |
|
|
close(fd); |
67 |
|
|
} |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/* |
72 |
|
|
* Delete PRAM file |
73 |
|
|
*/ |
74 |
|
|
|
75 |
|
|
void ZapPRAM(void) |
76 |
|
|
{ |
77 |
|
|
// Construct PRAM path |
78 |
|
|
xpram_path[0] = 0; |
79 |
|
|
char *home = getenv("HOME"); |
80 |
|
|
if (home != NULL && strlen(home) < 1000) { |
81 |
|
|
strncpy(xpram_path, home, 1000); |
82 |
|
|
strcat(xpram_path, "/"); |
83 |
|
|
} |
84 |
|
|
strcat(xpram_path, XPRAM_FILE_NAME); |
85 |
|
|
|
86 |
|
|
// Delete file |
87 |
|
|
unlink(xpram_path); |
88 |
|
|
} |