]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/opercmds.c
c11817534d1c709a8b25882c9383e631e413fbac
2 * IRC - Internet Relay Chat, ircd/opercmds.c (formerly ircd/s_serv.c)
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * @brief Implementation of AsLL ping helper commands.
25 * @version $Id: opercmds.c,v 1.12 2004/10/03 16:34:03 entrope Exp $
33 #include "ircd_chattr.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
50 /** Calculate current time or elapsed time.
52 * If neither \a sec nor \a usec are NULL, calculate milliseconds
53 * elapsed since that time, and return a string containing that
56 * If either \a sec or \a usec are NULL, format a timestamp containing
57 * Unix timestamp and microseconds since that second (separated by
58 * spaces), and return a string containing that timestamp.
60 * @todo This should be made into two functions.
61 * @param[in] sec Either NULL or a Unix timestamp in seconds.
62 * @param[in] usec Either NULL or an offset to \a sec in microseconds.
63 * @return A static buffer with contents as described above.
65 char *militime(char* sec
, char* usec
)
68 static char timebuf
[18];
70 gettimeofday(&tv
, NULL
);
72 sprintf(timebuf
, "%ld",
73 (tv
.tv_sec
- atoi(sec
)) * 1000 + (tv
.tv_usec
- atoi(usec
)) / 1000);
75 sprintf(timebuf
, "%ld %ld", tv
.tv_sec
, tv
.tv_usec
);
79 /** Calculate current time or elapsed time.
81 * If \a start is NULL, create a timestamp containing Unix timestamp
82 * and microseconds since that second (separated by a period), and
83 * return a string containing that timestamp.
85 * Otherwise, if \a start does not contain a period, return a string
88 * Otherwise, calculate milliseconds elapsed since the Unix time
89 * described in \a start (in the format described above), and return a
90 * string containing that number.
92 * @todo This should be made into two functions.
93 * @param[in] start Either NULL or a Unix timestamp in
94 * pseudo-floating-point format.
95 * @return A static buffer with contents as described above.
97 char *militime_float(char* start
)
100 static char timebuf
[18];
103 gettimeofday(&tv
, NULL
);
106 if ((p
= strchr(start
, '.')))
109 sprintf(timebuf
, "%ld",
110 (tv
.tv_sec
- atoi(start
)) * 1000 + (tv
.tv_usec
- atoi(p
)) / 1000);
113 strcpy(timebuf
, "0");
116 sprintf(timebuf
, "%ld.%ld", tv
.tv_sec
, tv
.tv_usec
);