public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: cs720@unh.edu To: gcc-gnats@gcc.gnu.org Cc: rdr@unh.edu, pas@unh.edu Subject: preprocessor/7988: POSIX broken in gcc Date: Fri, 20 Sep 2002 08:06:00 -0000 [thread overview] Message-ID: <200209201503.g8KF3e1v518556@hypatia.unh.edu> (raw) >Number: 7988 >Category: preprocessor >Synopsis: Programs defining _POSIX_C_SOURCE compile but won't run >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Fri Sep 20 08:06:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: cs720 Administrator >Release: 3.2 >Organization: University of New Hampshire >Environment: System: OSF1 hypatia.unh.edu V5.1 1885 alpha Machine: alpha host: alphaev56-dec-osf5.1 build: alphaev56-dec-osf5.1 target: alphaev56-dec-osf5.1 configured with: ../gcc-3.2/configure >Description: Many of my programs contain the line #define _POSIX_C_SOURCE 199506L before all #include lines. These used to work (over 1 year ago). Now they compile but give Segmentation faults or wrong answers when run. >How-To-Repeat: Attached below is a sample program called ftype.c If I compile it with "gcc ftype.c" and then run it with "a.out /dev/tty" it gives me a segmentation fault. If I compile it with "gcc -O ftype.c" and then run it with "a.out /dev/tty" it produces the output "/dev/tty: UNKNOWN FILE TYPE" which is the wrong answer. If I delete the line defining _POSIX_C_SOURCE and compile it with "gcc ftype.c" or "gcc -O ftype.c" and then run it with "a.out /dev/tty" it procudes the output "/dev/ttyp: character special file" which is the correct answer. /***********************************************************************/ /* ftype.c - program to demonstrate POSIX stat() and file-type macros */ #define _POSIX_C_SOURCE 199506L #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> int main( int argc, char *argv[] ) { int i; char *ptr; struct stat statbuf; if( argc < 2 ) { fprintf(stderr, "Usage: ftype file1 [file2 ...]\n"); exit(EXIT_FAILURE); } for( i = 1; i < argc; i++ ) { if( stat(argv[i], &statbuf) < 0 ) perror(argv[i]); else { if( S_ISREG(statbuf.st_mode) ) ptr ="regular file"; else if( S_ISDIR(statbuf.st_mode) ) ptr ="directory"; else if( S_ISCHR(statbuf.st_mode) ) ptr ="character special file"; else if( S_ISBLK(statbuf.st_mode) ) ptr ="block special file"; else if( S_ISFIFO(statbuf.st_mode)) ptr ="FIFO file"; else ptr ="UNKNOWN FILE TYPE"; printf("%s: %s\n", argv[i], ptr); } } return EXIT_SUCCESS; } /***********************************************************************/ >Fix: Just delete the line defining _POSIX_C_SOURCE. However, this worked in previous versions of gcc on OSF systems, and continues to work in current versions of gcc on Linux and Solaris systems. >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2002-09-20 15:06 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-09-20 8:06 cs720 [this message] 2002-09-20 10:26 Neil Booth 2002-09-20 12:06 cs720 Administrator 2002-10-04 11:56 Neil Booth
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200209201503.g8KF3e1v518556@hypatia.unh.edu \ --to=cs720@unh.edu \ --cc=gcc-gnats@gcc.gnu.org \ --cc=pas@unh.edu \ --cc=rdr@unh.edu \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).