473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

File Information

1
I am just a newbie in Linux OS. I used to program in Windows.
How to make this C++ compatible with Linux????


#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>

int main()
{
struct _stat64 buff; /*aggregate '_stat64 buf' has incomplete type and cannot be defined */

/* other codes for retrieving file's size, location, accessed date, etc.
:
:
*/
}


Please help to have an equivalent this in Linux....Thanks!
Sep 18 '06 #1
1 13005
tyreld
144 100+
I am just a newbie in Linux OS. I used to program in Windows.
How to make this C++ compatible with Linux????


#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>

int main()
{
struct _stat64 buff; /*aggregate '_stat64 buf' has incomplete type and cannot be defined */

/* other codes for retrieving file's size, location, accessed date, etc.
:
:
*/
}


Please help to have an equivalent this in Linux....Thanks!

The manual page for stat.h is a valuable source of information. Type "man stat.h" at the command line. Basically, the stat structure defined in stat.h should have the following members:

Expand|Select|Wrap|Line Numbers
  1. struct stat {
  2.    mode_t   st_mode;      /* file type & mode (permissions) */
  3.    ino_t       st_ino;          /* i-node number (serial number) */
  4.    dev_t      st_dev;         /* device number (file system) */
  5.    dev_t      st_rdev;        /* device number for special files */
  6.    nlink_t     st_nlink;        /* number of links */
  7.    uid_t       st_uid;          /* user ID of owner */
  8.    gid_t       st_gid;         /* group ID of owner */
  9.    off_t        st_size;       /* size in bytes, for regular files */
  10.    time_t      st_atime;    /* time of last access */
  11.    time_t      st_mtime;   /* time of last modifications */
  12.    time_t      st_ctime;    /* time of last file status change */
  13.    blksize_t  st_blksize; /* best I/O block size */
  14.    blkcnt_t    st_blocks; /* number of disk blocks allocated */
  15. }
  16.  
There are a variety of macros defined for testing file types and file permissions. These are all outlined in the stat.h man page.

There are three functions for populating the stat structure with file information.

Expand|Select|Wrap|Line Numbers
  1. int stat(const char *pathname, struct stat *buf);
  2.  
  3. int fstat(int filedes, struct stat * buf);
  4.  
  5. int lstat(const char *pathname, struct stat *buf);
  6.  
The fstat function obtains information about an already open file. Given a pathname the stat and lstat functions return information about the named files. The difference between the two functions is that lstat will resolve a symbolic link to the actual file, while stat will only get information about the symbolic link.

If you need to operate on large files (ie 2GB+) then you need to use the struct stat64 data type and stat64() functions. To access these you need to define __USE_LARGEFILE64 at compile time.
Sep 18 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Crystal | last post by:
Hi there, I need to retrieve multi files information. Instead of creating my own file brower, I think I can use Windows Explore to navigate these files. Can someone tell me how I can get the file...
2
by: Craig | last post by:
I've seen many examples of how to call SHGetFileInfo in shell32.dll to get a files associated icon, but I can't find anywhere how to get the file information (size, last date modified, etc, etc)...
1
by: sonu | last post by:
how to retrive client side file information through .NET Any link or information please ?
1
by: Locke Nash Cole | last post by:
Can someone point me in the right direction? I'm looking to get extended file information on .exe or .dlls such as File Version Description Copyright Language Internal Name Product Name...
2
by: Mamatha | last post by:
Hi I have a doubt,how to know the information of .pst file? I want to display the information of pst file (which is maintained by the outlook express) in VB.NET form.When i click a button in...
6
by: saleemahmad70 | last post by:
Hi.. I am stuck with a problem where I need to extract some information from a File in C++.e.g File size,date of creation, Location on the Disk etc. I haven't been able to find any particular...
10
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
1
by: deepthisoft | last post by:
Hi, I am creating site statistics tool.For that I have stored the log file information into Sql server database through ODBC Option in IIS. I got date, time, ip, port,target,status,error status...
2
by: houghi | last post by:
I am trying to do two things at a time. I want to give the user the opportunity to save a file and at the same time see new information on the screen. I can do it seperately, but not together....
7
Srijith B
by: Srijith B | last post by:
I am trying to print file information using ffmpeg tool in perl Here is my code use strict; use warnings; use IPC::Open3; # example
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.