468,512 Members | 1,088 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 12228
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

Post your reply

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

Similar topics

1 post views Thread by Locke Nash Cole | last post: by
6 posts views Thread by saleemahmad70 | last post: by
10 posts views Thread by deciacco | last post: by
2 posts views Thread by houghi | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.