Deleted Added
full compact
trimdomain.c (84225) trimdomain.c (121193)
1/*-
2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
3 * Based on original work by Atsushi Murai <amurai@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
3 * Based on original work by Atsushi Murai <amurai@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/lib/libutil/trimdomain.c 84225 2001-09-30 22:35:07Z dillon $");
30__FBSDID("$FreeBSD: head/lib/libutil/trimdomain.c 121193 2003-10-18 10:04:16Z markm $");
31
32#include <sys/param.h>
33
34#include <libutil.h>
35#include <string.h>
36#include <unistd.h>
37
38static int isDISP(const char *);

--- 31 unchanged lines hidden (view full) ---

70 dlen = strlen(domain);
71 }
72
73 if (domain[0] == '\0')
74 return;
75
76 s = fullhost;
77 end = s + hostsize + 1;
31
32#include <sys/param.h>
33
34#include <libutil.h>
35#include <string.h>
36#include <unistd.h>
37
38static int isDISP(const char *);

--- 31 unchanged lines hidden (view full) ---

70 dlen = strlen(domain);
71 }
72
73 if (domain[0] == '\0')
74 return;
75
76 s = fullhost;
77 end = s + hostsize + 1;
78 for (; (s = memchr(s, '.', end - s)) != NULL; s++) {
78 for (; (s = memchr(s, '.', (size_t)(end - s))) != NULL; s++) {
79 if (strncasecmp(s + 1, domain, dlen) == 0) {
80 if (s[dlen + 1] == '\0') {
81 /* Found -- lose the domain. */
82 *s = '\0';
83 break;
84 } else if (s[dlen + 1] == ':' &&
85 isDISP(s + dlen + 2) &&
79 if (strncasecmp(s + 1, domain, dlen) == 0) {
80 if (s[dlen + 1] == '\0') {
81 /* Found -- lose the domain. */
82 *s = '\0';
83 break;
84 } else if (s[dlen + 1] == ':' &&
85 isDISP(s + dlen + 2) &&
86 (len = strlen(s + dlen + 1)) < end - s) {
86 (len = strlen(s + dlen + 1)) < (size_t)(end - s)) {
87 /* Found -- shuffle the DISPLAY back. */
88 memmove(s, s + dlen + 1, len + 1);
89 break;
90 }
91 }
92 }
93}
94
95/*
96 * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ?
97 */
98static int
99isDISP(const char *disp)
100{
87 /* Found -- shuffle the DISPLAY back. */
88 memmove(s, s + dlen + 1, len + 1);
89 break;
90 }
91 }
92 }
93}
94
95/*
96 * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ?
97 */
98static int
99isDISP(const char *disp)
100{
101 int res, w;
101 size_t w;
102 int res;
102
103 w = strspn(disp, "0123456789");
104 res = 0;
105 if (w > 0) {
106 if (disp[w] == '\0')
107 res = 1; /* NN */
108 else if (disp[w] == '.') {
109 disp += w + 1;
110 w = strspn(disp, "0123456789");
111 if (w > 0 && disp[w] == '\0')
112 res = 1; /* NN.NN */
113 }
114 }
115 return (res);
116}
103
104 w = strspn(disp, "0123456789");
105 res = 0;
106 if (w > 0) {
107 if (disp[w] == '\0')
108 res = 1; /* NN */
109 else if (disp[w] == '.') {
110 disp += w + 1;
111 w = strspn(disp, "0123456789");
112 if (w > 0 && disp[w] == '\0')
113 res = 1; /* NN.NN */
114 }
115 }
116 return (res);
117}