Sorry for this totally amateur question, but I can't understand one difference between the native Linux stat program and the stat function in C
The point is, when I use a stat program in the example directory: "/ usr" its modification time is as follows:
File: /usr
Access: 2022-01-08 17:28:57.400521375 -0600
Modify: 2021-12-22 15:45:08.584831000 -0600
Change: 2021-12-22 15:45:08.584831000 -0600
But when I execute the following code
int getDirContent(){
DIR *dir;
struct dirent *entry;
struct stat pFilestat;
if ((dir = opendir("/")) == NULL)
perror("opendir() error");
else {
puts("contents of root:");
/* Read directory entries */
while ((entry = readdir(dir)) != NULL){
/* Extract Filename */
stat(entry->d_name, &pFilestat);
printf("%s\n", entry->d_name);
/* Extract Create time */
if (S_ISDIR(pFilestat.st_mode)){
printf("Access: %s",ctime(&pFilestat.st_atime));
printf("Modify: %s",ctime(&pFilestat.st_mtime));
printf("Change: %s",ctime(&pFilestat.st_ctime));
}
}
closedir(dir);
}
}
the result is as follows
contents of root:
[...]
usr
Access: Sun Jan 9 16:08:20 2022
Modify: Sun Jan 9 16:09:10 2022
Change: Sun Jan 9 16:09:10 2022
My system:
OS: Linux debian x86_64 GNU/Linux
compiler version:
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
[user@debia]:~$ timedatectl
Local time: Sun 2022-01-09 16:05:35 CET
Universal time: Sun 2022-01-09 15:05:35 UTC
RTC time: Sun 2022-01-09 15:05:36
Time zone: Europe/(CET, +0100)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
if the question has already been asked, please send me a link. Unfortunately, I tried to find the answer, but I can't ask a good question on google
EDIT:
Using of getDirContent: main.c
include <string.h>
#include <stdio.h>
#include "header/getDirContent.h"
int main() {
const char * pPath_array[] = {"/etc","/home", NULL}; // array of pointers
/*
For the sake of simplicity, the code removes the possibility for functions to accept arguments in the form of an array. Everything happens from inside the getDirContent function*/
getDirContent();
return 0;
}
wants to go through the directories indicated in the pointer table