1 /* 2 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef _BSD_MISC_H 18 #define _BSD_MISC_H 19 20 #include "includes.h" 21 22 char *ssh_get_progname(char *); 23 int seed_from_prngd(unsigned char *, size_t); 24 25 #ifndef HAVE_SETSID 26 #define setsid() setpgrp(0, getpid()) 27 #endif /* !HAVE_SETSID */ 28 29 #ifndef HAVE_SETENV 30 int setenv(const char *, const char *, int); 31 #endif /* !HAVE_SETENV */ 32 33 #ifndef HAVE_SETLOGIN 34 int setlogin(const char *); 35 #endif /* !HAVE_SETLOGIN */ 36 37 #ifndef HAVE_INNETGR 38 int innetgr(const char *, const char *, const char *, const char *); 39 #endif /* HAVE_INNETGR */ 40 41 #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) 42 int seteuid(uid_t); 43 #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ 44 45 #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) 46 int setegid(uid_t); 47 #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ 48 49 #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) 50 const char *strerror(int); 51 #endif 52 53 #if !defined(HAVE_SETLINEBUF) 54 #define setlinebuf(a) (setvbuf((a), NULL, _IOLBF, 0)) 55 #endif 56 57 #ifndef HAVE_UTIMES 58 #ifndef HAVE_STRUCT_TIMEVAL 59 struct timeval { 60 long tv_sec; 61 long tv_usec; 62 } 63 #endif /* HAVE_STRUCT_TIMEVAL */ 64 65 int utimes(const char *, struct timeval *); 66 #endif /* HAVE_UTIMES */ 67 68 #ifndef HAVE_FCHMODAT 69 int fchmodat(int, const char *, mode_t, int); 70 #endif 71 72 #ifndef HAVE_FCHOWNAT 73 int fchownat(int, const char *, uid_t, gid_t, int); 74 #endif 75 76 #ifndef HAVE_TRUNCATE 77 int truncate (const char *, off_t); 78 #endif /* HAVE_TRUNCATE */ 79 80 #ifndef HAVE_STRUCT_TIMESPEC 81 struct timespec { 82 time_t tv_sec; 83 long tv_nsec; 84 }; 85 #endif /* !HAVE_STRUCT_TIMESPEC */ 86 87 #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) 88 # include <time.h> 89 int nanosleep(const struct timespec *, struct timespec *); 90 #endif 91 92 #ifndef HAVE_UTIMENSAT 93 # include <time.h> 94 /* start with the high bits and work down to minimise risk of overlap */ 95 # ifndef AT_SYMLINK_NOFOLLOW 96 # define AT_SYMLINK_NOFOLLOW 0x80000000 97 # endif 98 int utimensat(int, const char *, const struct timespec[2], int); 99 #endif /* !HAVE_UTIMENSAT */ 100 101 #ifndef HAVE_USLEEP 102 int usleep(unsigned int useconds); 103 #endif 104 105 #ifndef HAVE_TCGETPGRP 106 pid_t tcgetpgrp(int); 107 #endif 108 109 #ifndef HAVE_TCSENDBREAK 110 int tcsendbreak(int, int); 111 #endif 112 113 #ifndef HAVE_UNSETENV 114 int unsetenv(const char *); 115 #endif 116 117 #ifndef HAVE_ISBLANK 118 int isblank(int); 119 #endif 120 121 #ifndef HAVE_GETPGID 122 pid_t getpgid(pid_t); 123 #endif 124 125 #ifndef HAVE_PSELECT 126 int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *, 127 const sigset_t *); 128 #endif 129 130 #ifndef HAVE_ENDGRENT 131 # define endgrent() do { } while(0) 132 #endif 133 134 #ifndef HAVE_KRB5_GET_ERROR_MESSAGE 135 # define krb5_get_error_message krb5_get_err_text 136 #endif 137 138 #ifndef HAVE_KRB5_FREE_ERROR_MESSAGE 139 # define krb5_free_error_message(a,b) do { } while(0) 140 #endif 141 142 #ifndef HAVE_PLEDGE 143 int pledge(const char *promises, const char *paths[]); 144 #endif 145 146 /* bsd-err.h */ 147 #ifndef HAVE_ERR 148 void err(int, const char *, ...) __attribute__((format(printf, 2, 3))); 149 #endif 150 #ifndef HAVE_ERRX 151 void errx(int, const char *, ...) __attribute__((format(printf, 2, 3))); 152 #endif 153 #ifndef HAVE_WARN 154 void warn(const char *, ...) __attribute__((format(printf, 1, 2))); 155 #endif 156 157 #ifndef HAVE_LLABS 158 long long llabs(long long); 159 #endif 160 161 #if defined(HAVE_DECL_BZERO) && HAVE_DECL_BZERO == 0 162 void bzero(void *, size_t); 163 #endif 164 165 #ifndef HAVE_RAISE 166 int raise(int); 167 #endif 168 169 #ifndef HAVE_GETSID 170 pid_t getsid(pid_t); 171 #endif 172 173 #ifndef HAVE_FLOCK 174 # define LOCK_SH 0x01 175 # define LOCK_EX 0x02 176 # define LOCK_NB 0x04 177 # define LOCK_UN 0x08 178 int flock(int, int); 179 #endif 180 181 #ifdef FFLUSH_NULL_BUG 182 # define fflush(x) (_ssh_compat_fflush(x)) 183 #endif 184 185 #ifndef HAVE_LOCALTIME_R 186 struct tm *localtime_r(const time_t *, struct tm *); 187 #endif 188 189 #ifndef HAVE_REALPATH 190 #define realpath(x, y) (sftp_realpath((x), (y))) 191 #endif 192 193 #endif /* _BSD_MISC_H */ 194