This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: preprocessor/7988: POSIX broken in gcc
- From: Neil Booth <neil at daikokuya dot co dot uk>
- To: nobody at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 4 Oct 2002 18:56:01 -0000
- Subject: Re: preprocessor/7988: POSIX broken in gcc
- Reply-to: Neil Booth <neil at daikokuya dot co dot uk>
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 -----