Annotation of src/usr.bin/ssh/util.c, Revision 1.4
1.1 provos 1: #include "includes.h"
1.4 ! markus 2: RCSID("$OpenBSD: util.c,v 1.3 2000/08/28 20:22:02 markus Exp $");
1.1 provos 3:
4: #include "ssh.h"
5:
6: char *
7: chop(char *s)
8: {
9: char *t = s;
10: while (*t) {
11: if(*t == '\n' || *t == '\r') {
12: *t = '\0';
13: return s;
14: }
15: t++;
16: }
17: return s;
18:
19: }
20:
21: void
22: set_nonblock(int fd)
23: {
24: int val;
25: if (isatty(fd)) {
26: /* do not mess with tty's */
27: debug("no set_nonblock for tty fd %d", fd);
28: return;
29: }
30: val = fcntl(fd, F_GETFL, 0);
31: if (val < 0) {
32: error("fcntl(%d, F_GETFL, 0): %s", fd, strerror(errno));
33: return;
34: }
35: if (val & O_NONBLOCK)
36: return;
37: debug("fd %d setting O_NONBLOCK", fd);
38: val |= O_NONBLOCK;
39: if (fcntl(fd, F_SETFL, val) == -1)
1.4 ! markus 40: if (errno != ENODEV)
! 41: error("fcntl(%d, F_SETFL, O_NONBLOCK): %s",
! 42: fd, strerror(errno));
1.1 provos 43: }
44:
45: /* Characters considered whitespace in strsep calls. */
46: #define WHITESPACE " \t\r\n"
47:
48: char *
49: strdelim(char **s)
50: {
51: char *old;
52: int wspace = 0;
53:
54: if (*s == NULL)
55: return NULL;
56:
57: old = *s;
58:
59: *s = strpbrk(*s, WHITESPACE "=");
60: if (*s == NULL)
61: return (old);
62:
63: /* Allow only one '=' to be skipped */
64: if (*s[0] == '=')
65: wspace = 1;
66: *s[0] = '\0';
67:
68: *s += strspn(*s + 1, WHITESPACE) + 1;
69: if (*s[0] == '=' && !wspace)
70: *s += strspn(*s + 1, WHITESPACE) + 1;
71:
72: return (old);
73: }