473,756 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Jul 23 '05 #1
3 9541
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)
Jul 23 '05 #2
On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <pe********@acm .org>
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.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #3
Jack Klein wrote:
On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <pe********@acm .org>
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)
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1680
by: Matthias Käppler | last post by:
Hi, I'm using a glibc system header <sys/stat.h> which defines a C struct 'stat'. Furthermore, I'm using the struct 'dirent', defined in <dirent.h>. Now, at one point in my code I'm holding an std::list of dirents: std::list< dirent > mylist; This works.
10
5277
by: David Farning | last post by:
I am new to c and not yet sure of the boundary between c and it's implementations. So please redirect me if this should be asked elsewhere. I am working on a function to determine if a directory exists. The idea comes from a snippet I found in a samba source file. bool dirExist(char *dname) { struct stat *stbuf; //stbuf = (struct stat*)malloc(sizeof(struct stat));
11
3416
by: J Wang | last post by:
dear, I debug the program recently as follows. #include <sys/stat.h> int main(int argc, char *argv) { struct stat buf;
5
3164
by: diadia | last post by:
#include <sys/types.h> #include <sys/stat.h> #include "ctype.h" #include <stdio.h> int estimateLen(struct stat buf, FILE *fp) { size_t _size = buf.st_size / 4;
3
3947
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
6
1368
by: one2001boy | last post by:
Hello, I tried to find the access time of a file using stat() function. but the following C code in windows vc.net 2003 always give the same access time. the same code works correctly in linux gcc. do I miss something? #include <stdio.h> #include <sys/stat.h> int main() {
3
5265
by: Magesh | last post by:
How date-time attributes of a file are represented in the structure "struct stat"? Coz as I noted they found to be unsigned integers and I donno how they are interpreted as date & time in the members st_atime, st_mtime, and st_ctime. I don't want any lib fun that returns the corresponding time formatted string coz what I want to know is the interpretation of date-time in those members so that I could extract them and use it for some...
2
2596
by: Rolf =?UTF-8?B?S3LDvGdlcg==?= | last post by:
Hi I´m about learning C/C++ and after covering the language basics I´m now heading for my first "real" application where I need to use the POSIX stuff for directory operations. Here´s my problem: The following code compiles and runs as it should inside a linux g++ environment using code::blocks IDE. But when I drop the "struct" prefix from line 12 "struct stat st;" It doesn´t compile any
4
4414
by: dissectcode2 | last post by:
Does anyone know about this problem? I tried using the "old" _stat for Cygwin/Windows but that doesn't help. The problem I am having is st_size is ALWAYS 16777216 for any file I am stat'ing and that value is incorrect anyway. Here is an example of the code: char *filename = "C:\\Program Files\\Somedir\\medfile.txt"; int ret; #if OS == LINUX struct stat sbuf;
0
9462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.