The following code exits cleanly (exit status 0) on i386, but on macppc exits 4:
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <errno.h> int main() { int n; int fd; char *s; struct stat st; fd = open("./blah",O_RDONLY | O_NDELAY); if (fd == -1) { exit(1); } if (fstat(fd,&st) == -1) { close(fd); exit(2); } s = (char *) malloc(st.st_size); if (!s) { close(fd); exit(3); } n = read(fd, (char *) s, st.st_size); if (n == -1) { fprintf(stderr,"errno: %d\n", errno); } else { fprintf(stdout,"bytes: %d\n", n); } close(fd); if (n != st.st_size) { free(s); exit(4); } free(s); exit(0); } $ gcc -o blah blah.c i386: $ ./blah; echo $? bytes: 6843 0 macppc: $ ./blah; echo $? errno: 14 4 According to intro(2) errno 14 is: 14 EFAULT Bad address. The system detected an invalid address in at- tempting to use an argument of a call. Is there something wrong with the .c program?