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:
-
struct stat {
-
mode_t st_mode; /* file type & mode (permissions) */
-
ino_t st_ino; /* i-node number (serial number) */
-
dev_t st_dev; /* device number (file system) */
-
dev_t st_rdev; /* device number for special files */
-
nlink_t st_nlink; /* number of links */
-
uid_t st_uid; /* user ID of owner */
-
gid_t st_gid; /* group ID of owner */
-
off_t st_size; /* size in bytes, for regular files */
-
time_t st_atime; /* time of last access */
-
time_t st_mtime; /* time of last modifications */
-
time_t st_ctime; /* time of last file status change */
-
blksize_t st_blksize; /* best I/O block size */
-
blkcnt_t st_blocks; /* number of disk blocks allocated */
-
}
-
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.
-
int stat(const char *pathname, struct stat *buf);
-
-
int fstat(int filedes, struct stat * buf);
-
-
int lstat(const char *pathname, struct stat *buf);
-
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.