... | ... |
@@ -93,7 +93,10 @@ static Uint8 |
93 | 93 |
datetime_dei(Device *d, Uint8 port) |
94 | 94 |
{ |
95 | 95 |
time_t seconds = time(NULL); |
96 |
+ struct tm zt = {0}; |
|
96 | 97 |
struct tm *t = localtime(&seconds); |
98 |
+ if(t == NULL) |
|
99 |
+ t = &zt; |
|
97 | 100 |
switch(port) { |
98 | 101 |
case 0x0: return (t->tm_year + 1900) >> 8; |
99 | 102 |
case 0x1: return (t->tm_year + 1900); |
... | ... |
@@ -155,9 +158,11 @@ static int |
155 | 158 |
load(Uxn *u, char *filepath) |
156 | 159 |
{ |
157 | 160 |
FILE *f; |
158 |
- if(!(f = fopen(filepath, "rb"))) |
|
159 |
- return 0; |
|
160 |
- fread(u->ram.dat + PAGE_PROGRAM, sizeof(u->ram.dat) - PAGE_PROGRAM, 1, f); |
|
161 |
+ int r; |
|
162 |
+ if(!(f = fopen(filepath, "rb"))) return 0; |
|
163 |
+ r = fread(u->ram.dat + PAGE_PROGRAM, 1, sizeof(u->ram.dat) - PAGE_PROGRAM, f); |
|
164 |
+ fclose(f); |
|
165 |
+ if(r < 1) return 0; |
|
161 | 166 |
fprintf(stderr, "Loaded %s\n", filepath); |
162 | 167 |
return 1; |
163 | 168 |
} |