From: roman@songdog.eskimo.com (Bill Roman)
To: axp-list@redhat.com
Subject: Re: stat() broken under RH 5.0??
Date: Tue, 2 Jun 1998 06:20:13 -0700 (PDT) [thread overview]
Message-ID: <m0ygqz8-0000aLC@songdog> (raw)
In-Reply-To: <199806012145.XAA01256@stefan.sime.com> from "Quant-X Alpha Linux Support" at Jun 1, 98 11:45:43 pm
Quant-X Alpha Linux Support wrote:
>
> 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.
>> [original code deleted]
> This cannot work, because you must allocate buf !
> try something like:
>
> [working example deleted]
>
> 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 ;-}).
Almost right! But you wanted sizeof *buf; sizeof buf is the size of a
*pointer* to struct stat, not of a struct stat.
--
Bill Roman (roman@songdog.eskimo.com / roman@songdog.uucp) running linux
next prev parent reply other threads:[~1998-06-02 13:30 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
1998-06-02 13:20 ` Bill Roman [this message]
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