misc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * Copyright (c) 2000 Markus Friedl. All rights reserved.
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * Redistribution and use in source and binary forms, with or without
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * modification, are permitted provided that the following conditions
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * 1. Redistributions of source code must retain the above copyright
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * notice, this list of conditions and the following disclaimer.
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * 2. Redistributions in binary form must reproduce the above copyright
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * notice, this list of conditions and the following disclaimer in the
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * documentation and/or other materials provided with the distribution.
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30ad4487f491cce61c10639362ccf67a3e4bf0a0Joe Bandenburg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40bb86b15037ea7692f11b39c298658a068d948asean oneill * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
40bb86b15037ea7692f11b39c298658a068d948asean oneill * Use is subject to license terms.
40bb86b15037ea7692f11b39c298658a068d948asean oneillRCSID("$OpenBSD: misc.c,v 1.19 2002/03/04 17:27:39 stevesk Exp $");
40bb86b15037ea7692f11b39c298658a068d948asean oneill#pragma ident "%Z%%M% %I% %E% SMI"
40bb86b15037ea7692f11b39c298658a068d948asean oneill/* remove newline at end of string */
40bb86b15037ea7692f11b39c298658a068d948asean oneill char *t = s;
40bb86b15037ea7692f11b39c298658a068d948asean oneill while (*t) {
40bb86b15037ea7692f11b39c298658a068d948asean oneill/* set/unset filedescriptor to non-blocking */
40bb86b15037ea7692f11b39c298658a068d948asean oneill error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
567df49a25d2745e1fc9fcfd39506078b62698d4Eugenia Sergueeva debug("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
40bb86b15037ea7692f11b39c298658a068d948asean oneill error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
40bb86b15037ea7692f11b39c298658a068d948asean oneill/* disable nagle on socket */
99973e2356cf31656e2d239d89559ca67e62e82dEugenia Sergueeva if (getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen) == -1) {
40bb86b15037ea7692f11b39c298658a068d948asean oneill error("getsockopt TCP_NODELAY: %.100s", strerror(errno));
40bb86b15037ea7692f11b39c298658a068d948asean oneill if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof opt) == -1)
40bb86b15037ea7692f11b39c298658a068d948asean oneill error("setsockopt TCP_NODELAY: %.100s", strerror(errno));
40bb86b15037ea7692f11b39c298658a068d948asean oneill/* Characters considered whitespace in strsep calls. */
40bb86b15037ea7692f11b39c298658a068d948asean oneill/* return next token in configuration line */
40bb86b15037ea7692f11b39c298658a068d948asean oneill /* Allow only one '=' to be skipped */
40bb86b15037ea7692f11b39c298658a068d948asean oneill if (*s[0] == '=')
40bb86b15037ea7692f11b39c298658a068d948asean oneill *s[0] = '\0';
return (old);
struct passwd *
#ifdef HAVE_PW_EXPIRE_IN_PASSWD
#ifdef HAVE_PW_CHANGE_IN_PASSWD
#ifdef HAVE_PW_CLASS_IN_PASSWD
return copy;
struct passwd *p;
p = *pw;
#ifdef HAVE_PW_CLASS_IN_PASSWD
xfree(p);
a2port(const char *s)
long port;
char *endp;
errno = 0;
return port;
convtime(const char *s)
char *endp;
errno = 0;
total = 0;
if (p == endp ||
secs < 0)
switch (*endp++) {
endp--;
if (total < 0)
p = endp;
return total;
return host;
int flag = 0;
return (cp);
#ifdef HAVE_SIGACTION
#if defined(SA_INTERRUPT)