File Details.

Posted on 2000-02-28
Last Modified: 2010-04-02

I am running gcc under solaris, i need to know the details of a given file such as its size,  date on which the file was last updated/edited etc. Is there any inbuilt function or other.  responses very much appreciated.

Question by:gsbabu
  • 3
  • 3
LVL 22

Expert Comment

ID: 2566333
Unix has a file called fstat() or stat() or something like that.  If linux has it it should provide the info you want.

Accepted Solution

Marthi earned 35 total points
ID: 2566336
Yes. The function is fstat() or stat().
Here's a man page snippet

       stat, fstat, lstat - get file status

       #include <sys/stat.h>
       #include <unistd.h>

       int stat(const char *file_name, struct stat *buf);
       int fstat(int filedes, struct stat *buf);
       int lstat(const char *file_name, struct stat *buf);

       These  functions  return  information  about the specified
       file.  You do not need any access rights to  the  file  to
       get  this  information  but  you need search rights to all
       directories named in the path leading to the file.


Author Comment

ID: 2566492
i have used stat(), but i don't know the exact syntax of the second parameter, i get error for


please guide me where i am wrong.

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 22

Expert Comment

ID: 2566712
Its a pointer to a structure of type stat.  The function will fill in this structure with the information about the file.

Author Comment

ID: 2566758
Could you correct the second parameter as to how pass a pointer.

LVL 22

Expert Comment

ID: 2566765
struct stat Stat;


then use Stat.????

Author Comment

ID: 2566810
Thanks for your suggestions/comments.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Building cUrl in Windows v7.43.0 4 36
MSVCR80.dll crash 2 141
convert char array to number in c 5 86
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 39
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question