diff options
author | Damien Miller <djm@mindrot.org> | 2000-08-18 14:01:04 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-08-18 14:01:04 +1000 |
commit | 61c51508615381765249e6ef1f9f843de2f3d5b6 (patch) | |
tree | f6a676a945fc42fb5cf49dd2aa80e035d9cf306a /util.c | |
parent | 942da039d2a05e6f491883f50b516175a6dbb20f (diff) | |
download | openssh-git-61c51508615381765249e6ef1f9f843de2f3d5b6.tar.gz |
Forgot to add
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -0,0 +1,71 @@ +#include "includes.h" +RCSID("$OpenBSD: util.c,v 1.1 2000/08/01 19:01:42 provos Exp $"); + +#include "ssh.h" + +char * +chop(char *s) +{ + char *t = s; + while (*t) { + if(*t == '\n' || *t == '\r') { + *t = '\0'; + return s; + } + t++; + } + return s; + +} + +void +set_nonblock(int fd) +{ + int val; + if (isatty(fd)) { + /* do not mess with tty's */ + debug("no set_nonblock for tty fd %d", fd); + return; + } + val = fcntl(fd, F_GETFL, 0); + if (val < 0) { + error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno)); + return; + } + if (val & O_NONBLOCK) + return; + debug("fd %d setting O_NONBLOCK", fd); + val |= O_NONBLOCK; + if (fcntl(fd, F_SETFL, val) == -1) + error("fcntl(%d, F_SETFL, O_NONBLOCK): %s", fd, strerror(errno)); +} + +/* Characters considered whitespace in strsep calls. */ +#define WHITESPACE " \t\r\n" + +char * +strdelim(char **s) +{ + char *old; + int wspace = 0; + + if (*s == NULL) + return NULL; + + old = *s; + + *s = strpbrk(*s, WHITESPACE "="); + if (*s == NULL) + return (old); + + /* Allow only one '=' to be skipped */ + if (*s[0] == '=') + wspace = 1; + *s[0] = '\0'; + + *s += strspn(*s + 1, WHITESPACE) + 1; + if (*s[0] == '=' && !wspace) + *s += strspn(*s + 1, WHITESPACE) + 1; + + return (old); +} |