🦄 refactor(C13, C14, C115): 更新了linux系统开发部分的结构
This commit is contained in:
41
C14-文件系统/flen.c
Normal file
41
C14-文件系统/flen.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
// !!! 不是int
|
||||
static off_t flen(char *fname)
|
||||
{
|
||||
struct stat statres;
|
||||
|
||||
if (stat(fname, &statres) < 0)
|
||||
{
|
||||
perror("stat()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return statres.st_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取文件大小
|
||||
* @details
|
||||
* Usage: ./flen filename
|
||||
*
|
||||
* @param argc
|
||||
* @param argv
|
||||
* @return int
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "Usage:...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// !!! 通过makefile指定off_t 64位
|
||||
printf("%lld\n", flen(argv[1]));
|
||||
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user