Subject: Correction: the real fix for pine3.91 readfile
To: netbsd-general <macbsd-general@NetBSD.ORG>
From: Paul R. Goyette <paul@pgoyette.bdt.com>
List: macbsd-general
Date: 07/01/1995 05:28:14
Ooops - got the wrong copy of the file!  As some of you have probably 
already figured out, the #ifdef's shoud look for __NetBSD__ rather than 
__netbsd__

Here's the right replacement for pine3.91/pine/osdep/readfile .  Also, 
make sure you delete pine3.91/pine/osdep/os-neb.c - it doesn't always get 
rebuilt!

/*----------------------------------------------------------------------
    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);

#ifdef __NetBSD__
    size_p = &statbuf.st_size;
#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   |
--------------------------------------------------------------------