aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2020-12-24 23:23:36 +0100
committerqorg11 <qorg@vxempire.xyz>2020-12-24 23:23:36 +0100
commit6922539f10f584cd856d1810294d0f0bdf57b10d (patch)
treec218d067995925b17619b5b786f219a85030972b
parent97e5f8eeef9475bf36b35448e3558c6daf2f7321 (diff)
downloadk9core-6922539f10f584cd856d1810294d0f0bdf57b10d.tar.gz
k9core-6922539f10f584cd856d1810294d0f0bdf57b10d.zip
Added stat.c
I was really drunk at the moment of writing this, so code can be *very* better i guess, i'll improve it some other day have a nice dinner tho
-rw-r--r--src/stat.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/stat.c b/src/stat.c
new file mode 100644
index 0000000..534c5b3
--- /dev/null
+++ b/src/stat.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+
+int
+main(int argc, char **argv)
+{
+ if (argc == 1) {
+ fprintf(stderr,"usage: stat FILE...\n");
+ return 1;
+ }
+ char mod_date[64], acc_date[64], creat_date[64];
+ struct stat file_data;
+ for(int i = 1; i <argc;i++)
+ {
+ if(stat(argv[i],&file_data) == -1) {
+ printf("Cannot stat '%s': %s\n",argv[i],strerror(errno));
+ continue;
+ }
+ /* About file size, location... */
+ printf("File: %s\nSize: %lu\t blocks: %li\t IO Block: %li\nDevice: %lu\t",
+ argv[i],
+ file_data.st_size,
+ file_data.st_blocks,
+ file_data.st_blksize,
+ file_data.st_dev);
+ /* File permisions
+ * TODO: Display only the permissions (644) instead of the whole mode (100644)
+ */
+ printf("Inode: %u\t Links: %lu\nAccess: %o\tUid: %u\tGid:%u\n",
+ file_data.st_gid,
+ file_data.st_nlink,
+ file_data.st_mode,
+ file_data.st_uid,
+ file_data.st_gid
+ );
+ /* Access, creation and modification date */
+ struct tm *timeinfo;
+ /* Modification time */
+ timeinfo = localtime(&file_data.st_mtim.tv_sec);
+ strftime(mod_date,64,"%F %H:%M:%S",timeinfo);
+ /* Creation time */
+
+ timeinfo = localtime(&file_data.st_ctim.tv_sec);
+ strftime(creat_date,64,"%F %H:%M:%S",timeinfo);
+
+ /* Access time */
+ timeinfo = localtime(&file_data.st_atim.tv_sec);
+ strftime(acc_date,64,"%F %H:%M:%S",timeinfo);
+
+ printf("Access: %s\nModify: %s\nCreation %s\n",
+ acc_date,
+ mod_date,
+ creat_date);
+ }
+
+ return 0;
+}