aboutsummaryrefslogtreecommitdiff
path: root/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c
diff options
context:
space:
mode:
Diffstat (limited to 'riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c')
-rw-r--r--riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c
new file mode 100644
index 0000000..b7e497a
--- /dev/null
+++ b/riemann.fmi.uni-sofia.bg/programs/nlogin-0.3-pre/nv_ctime.c
@@ -0,0 +1,41 @@
+#include <time.h>
+#include "time_defs.h"
+
+void num2str(char *c,int i) /*EXTRACT_INCL*/{c[0]=i/10+'0'; c[1]=i%10+'0';}
+
+unsigned int nv_ctime(char *p, time_t now, int len) /*EXTRACT_INCL*/{
+ char days[] = "SunMonTueWedThuFriSat";
+ char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ unsigned long day, mon, year, tod;
+
+ now += get_tz(&now, 1);
+
+ tod = (unsigned long)(now) % 86400;
+ day = (unsigned long)(now) / 86400;
+ byte_set(p, len, ' ');
+ str_add(p, days +3*((day+4) % 7), 3);
+
+ year = 4*day + 2;
+ year /= 1461;
+ day += 671;
+ day %= 1461; /* day 0 is march 1, 1972 */
+ if (day == 1460) { day = 365; }
+ else { day %= 365; }
+
+ day *= 10;
+ mon = (day + 5) / 306;
+ day = day + 5 - 306 * mon;
+ day /= 10;
+ if (mon >= 10) mon -= 10;
+ else mon += 2; /* day 0,1,30, mon 0..11, year 1970=0,1,2 */
+ /* 4 8 11 14 17 20 */
+ /* "Fri Jan 7 21:08:30 2005\n" */
+ str_add(p+4, months+3*mon, 3);
+ num2str(p+8, day+1); if (p[8]=='0') p[8]=' ';
+ num2str(p+17, tod%60); tod /= 60;
+ num2str(p+11, tod/60);
+ num2str(p+14, tod%60);
+ p[20 + fmt_ulong(p+20, 1970 + year)] = '\n';
+ p[13] = ':'; p[16] = ':';
+ return len;
+}