Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > struct stat st; stat(fileName.c_str(), &st); hu?

Reply
Thread Tools

struct stat st; stat(fileName.c_str(), &st); hu?

 
 
Steven T. Hatton
Guest
Posts: n/a
 
      06-01-2005
I found the following two statements in the file linked below:

struct stat st;
stat(fileName.c_str(), &st);

http://websvn.kde.org/branches/work/...47&view=markup

This is from /usr/include/sys/stat.h which I'm pretty sure is what #include
<sys/stat.h> is pulling in. I plain and simply do not understand what the
above two lines of code do. Can someone please explain?

extern int stat (__const char *__restrict __file,
struct stat *__restrict __buf) __THROW;

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      06-01-2005
Steven T. Hatton wrote:
> I found the following two statements in the file linked below:
>
> struct stat st;
> stat(fileName.c_str(), &st);
>
> http://websvn.kde.org/branches/work/...47&view=markup
>
> This is from /usr/include/sys/stat.h which I'm pretty sure is what #include
> <sys/stat.h> is pulling in. I plain and simply do not understand what the
> above two lines of code do. Can someone please explain?
>
> extern int stat (__const char *__restrict __file,
> struct stat *__restrict __buf) __THROW;
>


Pretend it says this:

struct stat
{
// whatever...
};

extern int STAT(const char *, struct stat *);

struct stat st; // defines object of type struct stat
STAT(fileName.c_str(), &st); // call STAT

This is a quirk in the standard C library: there's a struct named 'stat'
and a function named 'stat'. When you say "struct stat" you're talking
about the struct; when you say "stat" you're talking about the function.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      06-02-2005
On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <(E-Mail Removed)>
wrote in comp.lang.c++:

> Pretend it says this:
>
> struct stat
> {
> // whatever...
> };
>
> extern int STAT(const char *, struct stat *);
>
> struct stat st; // defines object of type struct stat
> STAT(fileName.c_str(), &st); // call STAT
>
> This is a quirk in the standard C library: there's a struct named 'stat'
> and a function named 'stat'. When you say "struct stat" you're talking
> about the struct; when you say "stat" you're talking about the function.


If it was anyone who didn't work for Dinkumware, I'd have to point
that the problem is not with the "standard C" library.

Oh, what the heck, I just did that anyway.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      06-02-2005
Jack Klein wrote:
> On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <(E-Mail Removed)>
> wrote in comp.lang.c++:
>
>
>>Pretend it says this:
>>
>>struct stat
>>{
>>// whatever...
>>};
>>
>>extern int STAT(const char *, struct stat *);
>>
>>struct stat st; // defines object of type struct stat
>>STAT(fileName.c_str(), &st); // call STAT
>>
>>This is a quirk in the standard C library: there's a struct named 'stat'
>>and a function named 'stat'. When you say "struct stat" you're talking
>>about the struct; when you say "stat" you're talking about the function.

>
>
> If it was anyone who didn't work for Dinkumware, I'd have to point
> that the problem is not with the "standard C" library.
>
> Oh, what the heck, I just did that anyway.
>


Good point. It's not the standard C library; it's the usual C library,
i.e., a UNIXism incorporated into POSIX and into most C libraries. I
don't know of any other code that does this, and it required a change to
the original grammar in C++ to make it work.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
os.stat() distorts filenames that end with period (nt.stat()) ruck Python 10 09-07-2012 05:54 AM
Why do I have to prefix stat from <sys/stat.h> with the keyword struct? Rolf Krüger C++ 2 03-12-2008 10:38 PM
Date & Time representation in "struct stat" - <sys/stat.h> Magesh C Programming 3 10-05-2007 12:13 PM
os.stat('<filename>')[stat.ST_INO] on Windows Patrick Useldinger Python 6 03-03-2005 09:21 AM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments