1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Copyright (c) 1999-2000 Damien Miller. All rights reserved.
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
5*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions
6*0Sstevel@tonic-gate * are met:
7*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
8*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
9*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
10*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
11*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
12*0Sstevel@tonic-gate *
13*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14*0Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15*0Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16*0Sstevel@tonic-gate * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17*0Sstevel@tonic-gate * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18*0Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19*0Sstevel@tonic-gate * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20*0Sstevel@tonic-gate * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21*0Sstevel@tonic-gate * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22*0Sstevel@tonic-gate * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*0Sstevel@tonic-gate */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate #include "includes.h"
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate RCSID("$Id: bsd-misc.c,v 1.10 2002/07/08 21:09:41 mouring Exp $");
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
30*0Sstevel@tonic-gate
get_progname(char * argv0)31*0Sstevel@tonic-gate char *get_progname(char *argv0)
32*0Sstevel@tonic-gate {
33*0Sstevel@tonic-gate #ifdef HAVE___PROGNAME
34*0Sstevel@tonic-gate extern char *__progname;
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate return __progname;
37*0Sstevel@tonic-gate #else
38*0Sstevel@tonic-gate char *p;
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate if (argv0 == NULL)
41*0Sstevel@tonic-gate return "unknown"; /* XXX */
42*0Sstevel@tonic-gate p = strrchr(argv0, '/');
43*0Sstevel@tonic-gate if (p == NULL)
44*0Sstevel@tonic-gate p = argv0;
45*0Sstevel@tonic-gate else
46*0Sstevel@tonic-gate p++;
47*0Sstevel@tonic-gate return p;
48*0Sstevel@tonic-gate #endif
49*0Sstevel@tonic-gate }
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate #ifndef HAVE_SETLOGIN
setlogin(const char * name)52*0Sstevel@tonic-gate int setlogin(const char *name)
53*0Sstevel@tonic-gate {
54*0Sstevel@tonic-gate return(0);
55*0Sstevel@tonic-gate }
56*0Sstevel@tonic-gate #endif /* !HAVE_SETLOGIN */
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gate #ifndef HAVE_INNETGR
innetgr(const char * netgroup,const char * host,const char * user,const char * domain)59*0Sstevel@tonic-gate int innetgr(const char *netgroup, const char *host,
60*0Sstevel@tonic-gate const char *user, const char *domain)
61*0Sstevel@tonic-gate {
62*0Sstevel@tonic-gate return(0);
63*0Sstevel@tonic-gate }
64*0Sstevel@tonic-gate #endif /* HAVE_INNETGR */
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
seteuid(uid_t euid)67*0Sstevel@tonic-gate int seteuid(uid_t euid)
68*0Sstevel@tonic-gate {
69*0Sstevel@tonic-gate return(setreuid(-1,euid));
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
setegid(uid_t egid)74*0Sstevel@tonic-gate int setegid(uid_t egid)
75*0Sstevel@tonic-gate {
76*0Sstevel@tonic-gate return(setresgid(-1,egid,-1));
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR)
strerror(int e)81*0Sstevel@tonic-gate const char *strerror(int e)
82*0Sstevel@tonic-gate {
83*0Sstevel@tonic-gate extern int sys_nerr;
84*0Sstevel@tonic-gate extern char *sys_errlist[];
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate if ((e >= 0) && (e < sys_nerr))
87*0Sstevel@tonic-gate return(sys_errlist[e]);
88*0Sstevel@tonic-gate else
89*0Sstevel@tonic-gate return("unlisted error");
90*0Sstevel@tonic-gate }
91*0Sstevel@tonic-gate #endif
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate #ifndef HAVE_UTIMES
utimes(char * filename,struct timeval * tvp)94*0Sstevel@tonic-gate int utimes(char *filename, struct timeval *tvp)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate struct utimbuf ub;
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate ub.actime = tvp[0].tv_sec;
99*0Sstevel@tonic-gate ub.modtime = tvp[1].tv_sec;
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate return(utime(filename, &ub));
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate #endif
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate #ifndef HAVE_TRUNCATE
truncate(const char * path,off_t length)106*0Sstevel@tonic-gate int truncate (const char *path, off_t length)
107*0Sstevel@tonic-gate {
108*0Sstevel@tonic-gate int fd, ret, saverrno;
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate fd = open(path, O_WRONLY);
111*0Sstevel@tonic-gate if (fd < 0)
112*0Sstevel@tonic-gate return -1;
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate ret = ftruncate(fd, length);
115*0Sstevel@tonic-gate saverrno = errno;
116*0Sstevel@tonic-gate (void) close (fd);
117*0Sstevel@tonic-gate if (ret == -1)
118*0Sstevel@tonic-gate errno = saverrno;
119*0Sstevel@tonic-gate return(ret);
120*0Sstevel@tonic-gate }
121*0Sstevel@tonic-gate #endif /* HAVE_TRUNCATE */
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate #if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
124*0Sstevel@tonic-gate /*
125*0Sstevel@tonic-gate * Cygwin setgroups should be a noop.
126*0Sstevel@tonic-gate */
127*0Sstevel@tonic-gate int
setgroups(size_t size,const gid_t * list)128*0Sstevel@tonic-gate setgroups(size_t size, const gid_t *list)
129*0Sstevel@tonic-gate {
130*0Sstevel@tonic-gate return 0;
131*0Sstevel@tonic-gate }
132*0Sstevel@tonic-gate #endif
133*0Sstevel@tonic-gate
134