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 
24 #ifndef HAVE_SETSID
25 #define setsid() setpgrp(0, getpid())
26 #endif /* !HAVE_SETSID */
27 
28 #ifndef HAVE_SETENV
29 int setenv(const char *, const char *, int);
30 #endif /* !HAVE_SETENV */
31 
32 #ifndef HAVE_SETLOGIN
33 int setlogin(const char *);
34 #endif /* !HAVE_SETLOGIN */
35 
36 #ifndef HAVE_INNETGR
37 int innetgr(const char *, const char *, const char *, const char *);
38 #endif /* HAVE_INNETGR */
39 
40 #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
41 int seteuid(uid_t);
42 #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
43 
44 #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
45 int setegid(uid_t);
46 #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
47 
48 #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR)
49 const char *strerror(int);
50 #endif
51 
52 #if !defined(HAVE_SETLINEBUF)
53 #define setlinebuf(a)	(setvbuf((a), NULL, _IOLBF, 0))
54 #endif
55 
56 #ifndef HAVE_UTIMES
57 #ifndef HAVE_STRUCT_TIMEVAL
58 struct timeval {
59 	long tv_sec;
60 	long tv_usec;
61 }
62 #endif /* HAVE_STRUCT_TIMEVAL */
63 
64 int utimes(char *, struct timeval *);
65 #endif /* HAVE_UTIMES */
66 
67 #ifndef HAVE_UTIMENSAT
68 /* start with the high bits and work down to minimise risk of overlap */
69 # ifndef AT_SYMLINK_NOFOLLOW
70 #  define AT_SYMLINK_NOFOLLOW 0x80000000
71 # endif
72 int utimensat(int, const char *, const struct timespec[2], int);
73 #endif
74 
75 #ifndef AT_FDCWD
76 # define AT_FDCWD (-2)
77 #endif
78 
79 #ifndef HAVE_FCHMODAT
80 int fchmodat(int, const char *, mode_t, int);
81 #endif
82 
83 #ifndef HAVE_FCHOWNAT
84 int fchownat(int, const char *, uid_t, gid_t, int);
85 #endif
86 
87 #ifndef HAVE_TRUNCATE
88 int truncate (const char *, off_t);
89 #endif /* HAVE_TRUNCATE */
90 
91 #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
92 #ifndef HAVE_STRUCT_TIMESPEC
93 struct timespec {
94 	time_t	tv_sec;
95 	long	tv_nsec;
96 };
97 #endif
98 int nanosleep(const struct timespec *, struct timespec *);
99 #endif
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_ENDGRENT
126 # define endgrent() do { } while(0)
127 #endif
128 
129 #ifndef HAVE_KRB5_GET_ERROR_MESSAGE
130 # define krb5_get_error_message krb5_get_err_text
131 #endif
132 
133 #ifndef HAVE_KRB5_FREE_ERROR_MESSAGE
134 # define krb5_free_error_message(a,b) do { } while(0)
135 #endif
136 
137 #ifndef HAVE_PLEDGE
138 int pledge(const char *promises, const char *paths[]);
139 #endif
140 
141 /* bsd-err.h */
142 #ifndef HAVE_ERR
143 void err(int, const char *, ...) __attribute__((format(printf, 2, 3)));
144 #endif
145 #ifndef HAVE_ERRX
146 void errx(int, const char *, ...) __attribute__((format(printf, 2, 3)));
147 #endif
148 #ifndef HAVE_WARN
149 void warn(const char *, ...) __attribute__((format(printf, 1, 2)));
150 #endif
151 
152 #ifndef HAVE_LLABS
153 long long llabs(long long);
154 #endif
155 
156 #if defined(HAVE_DECL_BZERO) && HAVE_DECL_BZERO == 0
157 void bzero(void *, size_t);
158 #endif
159 
160 #ifndef HAVE_RAISE
161 int raise(int);
162 #endif
163 
164 #ifndef HAVE_GETSID
165 pid_t getsid(pid_t);
166 #endif
167 
168 #ifndef HAVE_FLOCK
169 # define LOCK_SH		0x01
170 # define LOCK_EX		0x02
171 # define LOCK_NB		0x04
172 # define LOCK_UN		0x08
173 int flock(int, int);
174 #endif
175 
176 #ifdef FFLUSH_NULL_BUG
177 # define fflush(x)	(_ssh_compat_fflush(x))
178 #endif
179 
180 #endif /* _BSD_MISC_H */
181