1/* $OpenBSD: misc.h,v 1.12 2002/03/19 10:49:35 markus Exp $ */ 2 3/* 4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 5 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 6 * All rights reserved 7 * 8 * As far as I am concerned, the code I have written for this software 9 * can be used freely for any purpose. Any derived versions of this 10 * software must be clearly marked as such, and if the derived work is 11 * incompatible with the protocol description in the RFC file, it must be 12 * called by a name other than "ssh" or "Secure Shell". 13 */ 14 15/* actually from atomicio, but is only used in scp code */ 16#define vwrite (ssize_t (*)(int, void *, size_t))write 17 18char *chop(char *); 19char *strdelim(char **); 20void set_nonblock(int); 21void unset_nonblock(int); 22void set_nodelay(int); 23int a2port(const char *); 24char *cleanhostname(char *); 25char *colon(char *); 26long convtime(const char *); 27 28struct passwd *pwcopy(struct passwd *); 29 30typedef struct arglist arglist; 31struct arglist { 32 char **list; 33 int num; 34 int nalloc; 35}; 36void addargs(arglist *, char *, ...); 37void replacearg(arglist *, u_int, char *, ...); 38void freeargs(arglist *); 39 40/* from xmalloc.h */ 41void *xmalloc(size_t); 42void *xrealloc(void *, size_t); 43void xfree(void *); 44char *xstrdup(const char *); 45 46char *ssh_get_progname(char *); 47void fatal(char* fmt,...); 48void sanitise_stdfd(void); 49 50/* Required for non-BSD platforms, from OpenSSH's defines.h */ 51#ifndef timersub 52#define timersub(a, b, result) \ 53 do { \ 54 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 55 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 56 if ((result)->tv_usec < 0) { \ 57 --(result)->tv_sec; \ 58 (result)->tv_usec += 1000000; \ 59 } \ 60 } while (0) 61#endif 62 63#ifndef TIMEVAL_TO_TIMESPEC 64#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ 65 (ts)->tv_sec = (tv)->tv_sec; \ 66 (ts)->tv_nsec = (tv)->tv_usec * 1000; \ 67} 68#endif 69 70