473,769 Members | 7,646 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 9542
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
5278
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
3419
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
3165
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
3948
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
1369
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
2597
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
9589
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
9423
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
10048
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
9996
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,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5304
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...
1
3963
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
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.