laston.c - determine last time user has logged on
Dave Kraft
davek at lakesys.lakesys.com
Tue Jan 9 11:29:21 AEST 1990
Here's a little something I wrote to help me determine when I've last logged
on. It gets the current time/date from /dev/clock. If you aren't
familiar on how /dev/clock is broken down, here it is:
0108182790
Positions Meaning
1-2 month
3-4 day
5-6 hour (24-hour format)
7-8 minute
9-10 year
It gets the last time on from a file in the same format as /dev/clock in your
home directory.
If you have any questions, improvements, etc., please leave email.
Dave
---- cut here --
#include <stdio.h>
main()
{
struct {
char month[3];
char day[3];
char hour[3];
char minute[3];
char year[3];
} now, last;
int flag = 0;
char *fn;
FILE *f1, *fopen();
fn = getenv("HOME");
strcat(fn,"/.laston");
putchar('\n');
f1 = fopen("/dev/clock","r");
fread(now.month,2,1,f1);
fread(now.day,2,1,f1);
fread(now.hour,2,1,f1);
fread(now.minute,2,1,f1);
fread(now.year,2,1,f1);
fclose(f1);
add_null(now.month,2);
add_null(now.day,2);
add_null(now.hour,2);
add_null(now.minute,2);
add_null(now.year,2);
f1 = fopen(fn,"r");
if(f1 == NULL){
flag = 1;
printf("Could not determine last time on.\n");
}
if(flag == 0){
fread(last.month,2,1,f1);
fread(last.day,2,1,f1);
fread(last.hour,2,1,f1);
fread(last.minute,2,1,f1);
fread(last.year,2,1,f1);
add_null(last.month,2);
add_null(last.day,2);
add_null(last.hour,2);
add_null(last.minute,2);
add_null(last.year,2);
}
fclose(f1);
printf("Last on: ");
if(flag == 0)
printf("%s:%s\t%s/%s/%s\n",last.hour,last.minute,last.month,
last.day,last.year);
else
printf("%s:%s\t%s/%s/%s\n",now.hour,now.minute,now.month,
now.day,now.year);
f1 = fopen(fn,"w");
fwrite(now.month,2,1,f1);
fwrite(now.day,2,1,f1);
fwrite(now.hour,2,1,f1);
fwrite(now.minute,2,1,f1);
fwrite(now.year,2,1,f1);
fclose(f1);
putchar('\n');
}
add_null(s,pos)
char s[];
int pos;
{
s[pos] = '\0';
}
--
davek at lakesys.lakesys.com <OR> uunet!marque!lakesys!davek
-------------------------------------------------------------------------------
"Empathy is sort of like telepathy's kid brother"
-- taken from "Stardance" by Spider and Jeanne Robinson
More information about the Alt.sources
mailing list