stat 函数 取得的stat结构里面st_ctime字段为什么是个负值啊?
时间:2008-07-24 14:55:12
来源:论坛整理 作者: 编辑:chinaitzhe
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 modification */
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 */
};
#include <sys/stat.h>
#include <iostream>
using namespace std;
int main()
{
struct stat buf;
stat("main.cpp", &buf);
time_t buf.st_ctime < <endl;
return 0;
}
得到的是个负值 -1209766741,为什么?
网友回复:stat("main.cpp", &buf);
time_t buf.st_ctime < <endl; ??????????
网友回复:检查一下函数调用得结果,参照MSDN的示例:
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ int result = _stat("main.cpp", &buf); if( result != 0 ) { perror( "Problem getting information" ); switch (errno) { case ENOENT: printf("File %s not found.\n", filename); break; case EINVAL: printf("Invalid parameter to _stat.\n"); break; default: /* Should never be reached. */ printf("Unexpected error in _stat.\n"); } } else { // Output some of the statistics: printf( "File size : %ld\n", buf.st_size ); printf( "Drive : %c:\n", buf.st_dev 'A' ); err = ctime_s(timebuf, 26, &buf.st_mtime); if (err) { printf("Invalid arguments to ctime_s."); exit(1); } printf( "Time modified : %s", timebuf ); }
网友回复:
cout < <buf.st_ctime < <endl;
buf.st_ctime 是一个长整型time_t,cout应该可以输出啊,输出一个长整型。
网友回复:
并且应该是一个正数,不该溢出。
关键字:stat,函数,取得,stat,结构,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面