linux fstat
时间:2009-06-16 来源:jazeltq
in the net i found some code, about the large file.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
struct stat filestat;
printf("file size: %lld bytes\n", fstat(argv[1], &filestat.st_size));
return 0;
}
it is said that it supported super large file, but i don't think so.
we can find the prototype of st_size is off_t and
typedef __kernel_off_t off_t
typedef long __kernel_off_t
then we can the off_t 's true color. i think the posix should improve it .
it should be like this :
typedef long long __kernel_off_t
but gnu has improved it
in the head of the source file define the _GNU_SOURCE can turn the features on
like thie
_GNU_SOURCE
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv) {
struct stat64 filestat;
printf("file size: %lld bytes\n", fstat64(argv[1], &filestat.st_size));
return 0;
}
gnu is more human, i think.hehe
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
struct stat filestat;
printf("file size: %lld bytes\n", fstat(argv[1], &filestat.st_size));
return 0;
}
it is said that it supported super large file, but i don't think so.
we can find the prototype of st_size is off_t and
typedef __kernel_off_t off_t
typedef long __kernel_off_t
then we can the off_t 's true color. i think the posix should improve it .
it should be like this :
typedef long long __kernel_off_t
but gnu has improved it
in the head of the source file define the _GNU_SOURCE can turn the features on
like thie
_GNU_SOURCE
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv) {
struct stat64 filestat;
printf("file size: %lld bytes\n", fstat64(argv[1], &filestat.st_size));
return 0;
}
gnu is more human, i think.hehe
相关阅读 更多 +