3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on filetime.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "lib/internal.h"
35 showHelp(char const *cmd)
37 WRITE_MSG(1, "Usage: ");
42 "Shows the relative age of <filename>\n"
44 "Please report bugs to " PACKAGE_BUGREPORT "\n");
52 "filetime " VERSION " -- shows age of a file\n"
53 "This program is part of " PACKAGE_STRING "\n\n"
54 "Copyright (C) 2004 Enrico Scholz\n"
55 VERSION_COPYRIGHT_DISCLAIMER);
59 int main (int argc, char *argv[])
65 if (strcmp(argv[1], "--help") ==0) showHelp(argv[0]);
66 if (strcmp(argv[1], "--version")==0) showVersion();
67 if (strcmp(argv[1], "--") ==0) ++idx;
70 WRITE_MSG(2, "No filename specified; use '--help' for more information\n");
71 else if (stat(argv[idx], &st)==-1)
72 PERROR_Q("stat", argv[idx]);
74 time_t now = time(NULL);
75 time_t since = now - st.st_mtime;
76 int days = since / (24*60*60);
77 int today = since % (24*60*60);
78 int hours = today / (60*60);
79 int minutes = (today % (60*60)) / 60;
81 char buf[3*sizeof(time_t)*3 + 128];
85 l = utilvserver_fmt_ulong(buf, days);
88 memcpy(buf+l, MSG, sizeof(MSG)-1); l += sizeof(MSG)-1;
91 if (hours<10) buf[l++] = '0';
92 l += utilvserver_fmt_ulong(buf+l, hours);
94 if (minutes<10) buf[l++] = '0';
95 l += utilvserver_fmt_ulong(buf+l, minutes);