2 * Copyright (c) 1999-2000 Damien Miller. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * NB. duplicate __progname in case it is an alias for argv[0]
32 * Otherwise it may get clobbered by setproctitle()
34 char *get_progname(char *argv0)
36 #ifdef HAVE___PROGNAME
37 extern char *__progname;
39 return xstrdup(__progname);
44 return "unknown"; /* XXX */
45 p = strrchr(argv0, '/');
56 int setlogin(const char *name)
60 #endif /* !HAVE_SETLOGIN */
63 int innetgr(const char *netgroup, const char *host,
64 const char *user, const char *domain)
68 #endif /* HAVE_INNETGR */
70 #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
71 int seteuid(uid_t euid)
73 return(setreuid(-1,euid));
75 #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
77 #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
78 int setegid(uid_t egid)
80 return(setresgid(-1,egid,-1));
82 #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
84 #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR)
85 const char *strerror(int e)
88 extern char *sys_errlist[];
90 if ((e >= 0) && (e < sys_nerr))
91 return(sys_errlist[e]);
93 return("unlisted error");
98 int utimes(char *filename, struct timeval *tvp)
102 ub.actime = tvp[0].tv_sec;
103 ub.modtime = tvp[1].tv_sec;
105 return(utime(filename, &ub));
109 #ifndef HAVE_TRUNCATE
110 int truncate (const char *path, off_t length)
112 int fd, ret, saverrno;
114 fd = open(path, O_WRONLY);
118 ret = ftruncate(fd, length);
125 #endif /* HAVE_TRUNCATE */
127 #if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
129 * Cygwin setgroups should be a noop.
132 setgroups(size_t size, const gid_t *list)
138 #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
139 int nanosleep(const struct timespec *req, struct timespec *rem)
143 struct timeval tstart, tstop, tremain, time2wait;
145 TIMESPEC_TO_TIMEVAL(&time2wait, req)
146 (void) gettimeofday(&tstart, NULL);
147 rc = select(0, NULL, NULL, NULL, &time2wait);
150 (void) gettimeofday (&tstop, NULL);
152 tremain.tv_sec = time2wait.tv_sec -
153 (tstop.tv_sec - tstart.tv_sec);
154 tremain.tv_usec = time2wait.tv_usec -
155 (tstop.tv_usec - tstart.tv_usec);
156 tremain.tv_sec += tremain.tv_usec / 1000000L;
157 tremain.tv_usec %= 1000000L;
162 TIMEVAL_TO_TIMESPEC(&tremain, rem)