summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index b0fdbe03c..208819cd2 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $ */ 1/* $OpenBSD: misc.c,v 1.9 2001/05/19 19:43:57 stevesk Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 4 * Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -25,7 +25,7 @@
25 */ 25 */
26 26
27#include "includes.h" 27#include "includes.h"
28RCSID("$OpenBSD: misc.c,v 1.8 2001/05/11 14:59:56 markus Exp $"); 28RCSID("$OpenBSD: misc.c,v 1.9 2001/05/19 19:43:57 stevesk Exp $");
29 29
30#include "misc.h" 30#include "misc.h"
31#include "log.h" 31#include "log.h"
@@ -154,6 +154,66 @@ int a2port(const char *s)
154 return port; 154 return port;
155} 155}
156 156
157#define SECONDS 1
158#define MINUTES (SECONDS * 60)
159#define HOURS (MINUTES * 60)
160#define DAYS (HOURS * 24)
161#define WEEKS (DAYS * 7)
162
163long convtime(const char *s)
164{
165 long total, secs;
166 const char *p;
167 char *endp;
168
169 errno = 0;
170 total = 0;
171 p = s;
172
173 if (p == NULL || *p == '\0')
174 return -1;
175
176 while (*p) {
177 secs = strtol(p, &endp, 10);
178 if (p == endp ||
179 (errno == ERANGE && (secs == LONG_MIN || secs == LONG_MAX)) ||
180 secs < 0)
181 return -1;
182
183 switch (*endp++) {
184 case '\0':
185 endp--;
186 case 's':
187 case 'S':
188 break;
189 case 'm':
190 case 'M':
191 secs *= MINUTES;
192 break;
193 case 'h':
194 case 'H':
195 secs *= HOURS;
196 break;
197 case 'd':
198 case 'D':
199 secs *= DAYS;
200 break;
201 case 'w':
202 case 'W':
203 secs *= WEEKS;
204 break;
205 default:
206 return -1;
207 }
208 total += secs;
209 if (total < 0)
210 return -1;
211 p = endp;
212 }
213
214 return total;
215}
216
157char * 217char *
158cleanhostname(char *host) 218cleanhostname(char *host)
159{ 219{