-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.c
24 lines (21 loc) · 797 Bytes
/
new.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <time.h>
#include <utmp.h>
int main() {
FILE *file;
struct utmp currentRecord;
file = fopen("/var/log/wtmp", "rb");
if (file) {
while (fread(¤tRecord, sizeof(currentRecord), 1, file) == 1) { // fread function returns the number of elements that were successfully read .
// Since we requested only 1 to be read, this condition must hold true
if (currentRecord.ut_type == USER_PROCESS) {
time_t loginTime = currentRecord.ut_tv.tv_sec;
printf("Login time: %s", ctime(&loginTime));
}
}
fclose(file);
} else {
printf("Failed to open /var/log/wtmp\n");
}
return 0;
}