From: Quant-X Alpha Linux Support <stefan@sime.com>
To: axp-list@redhat.com
Cc: joeyen@alpha.nmrlab.hscsyr.edu
Subject: Re: stat() broken under RH 5.0??
Date: Mon, 1 Jun 1998 23:45:43 +0200 [thread overview]
Message-ID: <199806012145.XAA01256@stefan.sime.com> (raw)
In-Reply-To: <199806011552.LAA07657@alpha.nmrlab.hscsyr.edu> (message from Mike on Mon, 1 Jun 1998 11:52:37 -0400)
Hi !
> We cannot get stat (in a C program, not the shell command) to work
> correctly under RedHat 5.0 running on an alpha (kernel 2.0.30). Any help
Ouups, your example is simply broken; it can't work.
> #include <sys/stat.h>
> #include <dirent.h>
> #include <unistd.h>
>
> main()
> {
> struct stat *buf;
> stat("teststat.c",buf);
> printf("%d\n",buf->st_mode);
> }
This cannot work, because you must allocate buf !
try something like:
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
main()
{
struct stat buf;
stat("teststat.c", &buf);
printf("%d\n",buf.st_mode);
}
or
#include <stdlib.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
main()
{
struct stat *buf;
/* blah */
buf = malloc(sizeof(buf));
stat("teststat.c", buf);
printf("%d\n",buf->st_mode);
free(buf);
/*blah*/
}
and it should work (untested, but may work if stat isn't broken ;-}).
BTW, what you really want is maybe:
printf("%o\n",buf->st_mode & ~S_IFMT);
--
Quant-X Service & Ph: (+43) 4212 6004-0
Consulting Ges.m.b.H. Fax: (+43) 4212 600420
http://www.quant-x.com Email: support@quant-x.com
next prev parent reply other threads:[~1998-06-01 21:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-06-01 15:52 stat() broken under RH 5.0?? Mike
1998-06-01 21:45 ` Quant-X Alpha Linux Support [this message]
1998-06-02 13:20 ` Bill Roman
1998-06-02 15:07 ` Michal Jaegermann
[not found] <Pine.SOL.3.96.980601182010.13382A-100000@tarkovsky.npac.syr.edu>
1998-06-02 0:37 ` Quant-X Alpha Linux Support
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox