-/* $NetBSD: save.c,v 1.4 1997/10/12 11:45:58 lukem Exp $ */
+/* $NetBSD: save.c,v 1.7 1999/09/18 19:38:54 jsm Exp $ */
/*
* Copyright (c) 1988, 1993
#if 0
static char sccsid[] = "@(#)save.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: save.c,v 1.4 1997/10/12 11:45:58 lukem Exp $");
+__RCSID("$NetBSD: save.c,v 1.7 1999/09/18 19:38:54 jsm Exp $");
#endif
#endif /* not lint */
void
save_into_file(sfile)
- char *sfile;
+ const char *sfile;
{
FILE *fp;
int file_id;
- char name_buffer[80];
+ char *name_buffer;
+ size_t len;
char *hptr;
struct rogue_time rt_buf;
if (sfile[0] == '~') {
if ((hptr = md_getenv("HOME")) != NULL) {
- (void) strcpy(name_buffer, hptr);
- (void) strcat(name_buffer, sfile+1);
- sfile = name_buffer;
+ len = strlen(hptr) + strlen(sfile);
+ name_buffer = md_malloc(len);
+ if (name_buffer == NULL) {
+ message("out of memory for save file name", 0);
+ sfile = error_file;
+ } else {
+ (void) strcpy(name_buffer, hptr);
+ (void) strcat(name_buffer, sfile+1);
+ sfile = name_buffer;
+ }
}
}
if ( ((fp = fopen(sfile, "w")) == NULL) ||
void
restore(fname)
- char *fname;
+ const char *fname;
{
FILE *fp;
struct rogue_time saved_time, mod_time;
void
write_pack(pack, fp)
- object *pack;
+ const object *pack;
FILE *fp;
{
object t;
while ((pack = pack->next_object) != NULL) {
- r_write(fp, (char *) pack, sizeof(object));
+ r_write(fp, (const char *) pack, sizeof(object));
}
t.ichar = t.what_is = 0;
- r_write(fp, (char *) &t, sizeof(object));
+ r_write(fp, (const char *) &t, sizeof(object));
}
void
for (i = 0; i < n; i++) {
if (wr) {
- r_write(fp, (char *) &(id_table[i].value), sizeof(short));
- r_write(fp, (char *) &(id_table[i].id_status),
+ r_write(fp, (const char *) &(id_table[i].value), sizeof(short));
+ r_write(fp, (const char *) &(id_table[i].id_status),
sizeof(unsigned short));
write_string(id_table[i].title, fp);
} else {
char *buf;
int n;
{
- if (fread(buf, sizeof(char), n, fp) != n) {
+ if (fread(buf, sizeof(char), n, fp) != (size_t)n) {
clean_up("read() failed, don't know why");
}
}
void
r_write(fp, buf, n)
FILE *fp;
- char *buf;
+ const char *buf;
int n;
{
if (!write_failed) {
- if (fwrite(buf, sizeof(char), n, fp) != n) {
+ if (fwrite(buf, sizeof(char), n, fp) != (size_t)n) {
message("write() failed, don't know why", 0);
sound_bell();
write_failed = 1;
boolean
has_been_touched(saved_time, mod_time)
- struct rogue_time *saved_time, *mod_time;
+ const struct rogue_time *saved_time, *mod_time;
{
if (saved_time->year < mod_time->year) {
return(1);