A representative program illustrating the problem:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(void)
{
        FILE *fp;
        int fd;

        fd = open("foo.c", O_RDONLY);
        if (fd < 0) {
                perror("foo.c: open");
                exit(EXIT_FAILURE);
        } else 
                fp = fdopen(fd, "r");

        if(file == NULL) {
                perror("foo.c: fdopen");
                close(fd);
                exit(EXIT_FAILURE);
        } else {
                fclose(fp);
                close(fd);
        }
        exit(EXIT_SUCCESS);
}

gcc (2.91) complains about implicitly declared function fdopen
and an uncast pointer:

$ gcc -ansi -Wall foo.c
foo.c: In function `main':
foo.c:18: warning: implicit declaration of function `fdopen'
foo.c:18: warning: assignment makes pointer from integer without a cast

I'm a touch stumped: fdopen is declared in <stdio.h> and most certainly
returns FILE *.  If I don't use `-ansi', I get no warnings, so I'm
guessing the issue is that fdopen is POSIX.1 compliant, but not ANSI
compliant.

Thanks,

Kurt

Reply via email to