Subject: pine 3.91 - fix to read .pinerc files
To: netbsd-general <macbsd-general@NetBSD.ORG>
From: Paul R. Goyette <paul@pgoyette.bdt.com>
List: macbsd-general
Date: 06/30/1995 19:37:26
Here's the change needed to make pine 3.91 read files successfully on
MacBSD (and any other big-endian machine, I'd imagine). Replace the
file .../pine3.91/pine/osdep/readfile with the following (and please
don't rag on me for the ugly looking c code).
/*----------------------------------------------------------------------
Read whole file into memory
Args: filename -- path name of file to read
Result: Returns pointer to malloced memory with the contents of the file
or NULL
This won't work very well if the file has NULLs in it and is mostly
intended for fairly small text files.
----*/
char *
read_file(filename)
char *filename;
{
int fd;
struct stat statbuf;
char *buf;
#ifdef __netbsd__
long *size_p;
#endif
fd = open(filename, O_RDONLY);
if(fd < 0)
return((char *)NULL);
fstat(fd, &statbuf);
size_p = &statbuf.st_size;
#ifdef __netbsd__
#if BYTE_ORDER == BIG_ENDIAN
size_p++;
#endif
buf = fs_get(*size_p+1);
#else
buf = fs_get(statbuf.st_size + 1);
#endif
/*
* On some systems might have to loop here, if one read isn't guaranteed
* to get the whole thing.
*/
#ifdef __netbsd__
if(read(fd, buf, *size_p+1) != *size_p) {
#else
if(read(fd, buf, statbuf.st_size) != statbuf.st_size) {
#endif
close(fd);
return((char *)NULL);
}
close(fd);
/* buf[statbuf.st_size]= '\0'; /* PRG */
buf[*size_p]= '\0'; /* PRG */
return(buf);
}
--------------------------------------------------------------------
| Paul Goyette | Key available via finger or key server |
| Paul@pgoyette.bdt.com | Fingerprint: 0E 40 D2 FC 2A 13 74 A0 |
| | E4 69 D5 BE 65 E4 56 C6 |
--------------------------------------------------------------------