Commits

Anonymous committed 42c1371

Common Gateway Interface library

Comments (0)

Files changed (1)

+/*
+    CGI uptime in C, written for Windows NT
+    Copyright (C) 2000 David Duncan Ross Palmer, Daybo Logic.
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+Contact me: Overlord@DayboLogic.co.uk
+Get updates: http://daybologic.com
+My official site: http://daybologic.com/overlord
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <windows.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+/* We get to use small types luckily */
+typedef unsigned char bool;
+#define true  ('\x1')
+#define false ('\x0')
+
+#define MINUTE (60)
+#define HOUR (3600)
+#define DAY (HOUR*24)
+#define YEAR (DAY*365)
+
+#define DO_S(timefactor) \
+          if ((timefactor) > 1) printf("s"); \
+          printf(", ")
+/*-------------------------------------------------------------------------*/
+static void PrintTime(DWORD TimeTaken);
+/*-------------------------------------------------------------------------*/
+int main()
+{
+  DWORD timeup = GetTickCount() / 1000;
+  puts("Content-type: text/html\n");
+  PrintTime(timeup);
+  return EXIT_SUCCESS;
+}
+/*-------------------------------------------------------------------------*/
+static void PrintTime(DWORD TimeTaken)
+{
+  unsigned short years, days, hours, mins, secs;
+
+  printf("Up ");
+
+  if (TimeTaken)
+  {
+    years = TimeTaken / YEAR;
+    TimeTaken -= YEAR * years;
+    days = TimeTaken / DAY;
+    TimeTaken -= DAY * days;
+    hours = TimeTaken / HOUR;
+    TimeTaken -= HOUR * hours;
+    mins = TimeTaken / MINUTE;
+    TimeTaken -= MINUTE * mins;
+    secs = TimeTaken; /* Remaining must be seconds */
+
+    if (years)
+    {
+      printf("%u year", years);
+      DO_S(years);
+    }
+    if (days)
+    {
+      printf("%u day", days);
+      DO_S(days);
+    }
+    if (hours)
+    {
+      printf("%u hour", hours);
+      DO_S(hours);
+    }
+    if (mins)
+    {
+      printf("%u min", mins);
+      DO_S(mins);
+    }
+    if (secs)
+    {
+      printf("%u sec", secs);
+      DO_S(secs);
+    }
+  }
+  else /* No time taken at all */
+  {
+    printf("less than a second, ");
+  }
+
+  printf("%s\n", "coded by DDRP");
+  return;
+}
+/*-------------------------------------------------------------------------*/