public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Neil Booth <neil@daikokuya.co.uk> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: preprocessor/7988: POSIX broken in gcc Date: Fri, 04 Oct 2002 11:56:00 -0000 [thread overview] Message-ID: <20021004185601.27480.qmail@sources.redhat.com> (raw) The following reply was made to PR target/7988; it has been noted by GNATS. From: Neil Booth <neil@daikokuya.co.uk> To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: preprocessor/7988: POSIX broken in gcc Date: Fri, 4 Oct 2002 19:47:19 +0100 ----- Forwarded message from cs720 Administrator <cs720@cisunix.unh.edu> ----- Subject: Re: preprocessor/7988: POSIX broken in gcc From: cs720 Administrator <cs720@cisunix.unh.edu> To: Neil Booth <neil@daikokuya.co.uk> Date: Fri, 4 Oct 2002 11:00:26 -0400 (EDT) Neil: I have some further information that should help to narrow the search for the cause of this bug. The problem seems to appear only when the stat() function is called with its second parameter, of type struct stat, allocated locally, on the stack, as in the first attachment above. If it is allocated globally, as in the second attachment, or is allocated dynamically, using malloc(), as in the third attachment, everything works fine. I hope this extra information helps locate the bug. If nothing else, it may help to to categorize it better. To me it now looks like it may be a code generator problem. Thanks, Bob Russell On Fri, 20 Sep 2002, Neil Booth wrote: > cs720 Administrator wrote:- > > > Neil: > > > > I wasn't sure how to categorize it -- > > _POSIX_C_SOURCE is a preprocessor symbol and it > > is used to select header files, define other symbols > > and structures, etc. Defining it selects one set > > of headers, etc. while not defining it selects > > another set. Perhaps the error is in the > > organization of the header files themselves, > > and the use of _POSIX_C_SOURCE within those header files. > > I doubt it is in the preprocessor itself, but > > what other category would be better? > > Um, I'll re-assign it to target. > > Neil. > /* 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; } /* 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> struct stat statbuf; int main( int argc, char *argv[] ) { int i; char *ptr; 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; } /* 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); } if( (statbuf = malloc(sizeof(struct stat))) == NULL ) { fprintf(stderr, "No space for stat buffer\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; } ----- End forwarded message -----
next reply other threads:[~2002-10-04 18:56 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-10-04 11:56 Neil Booth [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-09-20 12:06 cs720 Administrator 2002-09-20 10:26 Neil Booth 2002-09-20 8:06 cs720
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=20021004185601.27480.qmail@sources.redhat.com \ --to=neil@daikokuya.co.uk \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /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).