summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index 625a34368..8b303f16f 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.65 2006/11/23 01:35:11 ray Exp $ */ 1/* $OpenBSD: misc.c,v 1.69 2008/06/13 01:38:23 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -42,6 +42,7 @@
42 42
43#include <errno.h> 43#include <errno.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <netdb.h>
45#ifdef HAVE_PATHS_H 46#ifdef HAVE_PATHS_H
46# include <paths.h> 47# include <paths.h>
47#include <pwd.h> 48#include <pwd.h>
@@ -120,6 +121,14 @@ unset_nonblock(int fd)
120 return (0); 121 return (0);
121} 122}
122 123
124const char *
125ssh_gai_strerror(int gaierr)
126{
127 if (gaierr == EAI_SYSTEM)
128 return strerror(errno);
129 return gai_strerror(gaierr);
130}
131
123/* disable nagle on socket */ 132/* disable nagle on socket */
124void 133void
125set_nodelay(int fd) 134set_nodelay(int fd)
@@ -525,7 +534,7 @@ tilde_expand_filename(const char *filename, uid_t uid)
525 if ((pw = getpwnam(user)) == NULL) 534 if ((pw = getpwnam(user)) == NULL)
526 fatal("tilde_expand_filename: No such user %s", user); 535 fatal("tilde_expand_filename: No such user %s", user);
527 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */ 536 } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */
528 fatal("tilde_expand_filename: No such uid %d", uid); 537 fatal("tilde_expand_filename: No such uid %ld", (long)uid);
529 538
530 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret)) 539 if (strlcpy(ret, pw->pw_dir, sizeof(ret)) >= sizeof(ret))
531 fatal("tilde_expand_filename: Path too long"); 540 fatal("tilde_expand_filename: Path too long");
@@ -823,3 +832,23 @@ put_u16(void *vp, u_int16_t v)
823 p[0] = (u_char)(v >> 8) & 0xff; 832 p[0] = (u_char)(v >> 8) & 0xff;
824 p[1] = (u_char)v & 0xff; 833 p[1] = (u_char)v & 0xff;
825} 834}
835
836void
837ms_subtract_diff(struct timeval *start, int *ms)
838{
839 struct timeval diff, finish;
840
841 gettimeofday(&finish, NULL);
842 timersub(&finish, start, &diff);
843 *ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000);
844}
845
846void
847ms_to_timeval(struct timeval *tv, int ms)
848{
849 if (ms < 0)
850 ms = 0;
851 tv->tv_sec = ms / 1000;
852 tv->tv_usec = (ms % 1000) * 1000;
853}
854