~ubuntu-branches/ubuntu/trusty/dante/trusty-proposed

« back to all changes in this revision

Viewing changes to acinclude.m4

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bridgett
  • Date: 2002-04-07 12:45:55 UTC
  • Revision ID: james.westby@ubuntu.com-20020407124555-qke8rt2tdor0naz2
Tags: upstream-1.1.11.12p1
ImportĀ upstreamĀ versionĀ 1.1.11.12p1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -- acinclude start --
 
2
 
 
3
AC_DEFUN(L_UNCON_SELECT,
 
4
[AC_MSG_CHECKING(for correct select behaviour on unconnected sockets)
 
5
AC_TRY_RUN([
 
6
/*
 
7
 * ftp.inet.no:/pub/home/michaels/stuff/unconnectedsocket-select.c
 
8
 * $ cc unconnectedsocket-select.c && uname -a && ./a.out
 
9
 * Modified by Eric Anderson <anderse@hpl.hp.com>
 
10
 */
 
11
 
 
12
#include <sys/types.h>
 
13
#include <sys/time.h>
 
14
#include <sys/socket.h>
 
15
#include <netinet/in.h>
 
16
#include <arpa/inet.h>
 
17
 
 
18
#include <signal.h>
 
19
#include <stdio.h>
 
20
#include <string.h>
 
21
#include <errno.h>
 
22
#include <unistd.h>
 
23
#include <fcntl.h>
 
24
 
 
25
static int
 
26
selectcheck(int s);
 
27
 
 
28
int
 
29
main(void)
 
30
{
 
31
        char foo[5];
 
32
        int s, p;
 
33
        struct sigaction act;
 
34
        int res;
 
35
        
 
36
        act.sa_handler = SIG_IGN;
 
37
        sigaction(SIGPIPE,&act,NULL);
 
38
        fprintf(stderr, "testing with a normal, unconnected socket:\n");
 
39
        if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
 
40
                perror("socket()");
 
41
                exit(1);
 
42
        }
 
43
        fprintf(stderr, "  created socket, select() returned %d\n",
 
44
               selectcheck(s));
 
45
        p = read(s, NULL, 0);
 
46
        fprintf(stderr, "  read() returned %d, errno = %d (%s)\n", p, errno, (strerror(errno)));
 
47
        p = write(s, foo, 5);
 
48
        fprintf(stderr, "  write() returned %d, errno = %d (%s)\n", p, errno, (strerror(errno)));
 
49
 
 
50
        fprintf(stderr, "testing with a non-blocking, unconnected socket:\n");
 
51
        if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
 
52
                perror("socket()");
 
53
                exit(1);
 
54
        }
 
55
        if ((p = fcntl(s, F_GETFL, 0)) == -1
 
56
            || fcntl(s, F_SETFL, p | O_NONBLOCK) == -1) {
 
57
                perror("fcntl()");
 
58
                exit(1);
 
59
        }
 
60
        res = selectcheck(s);
 
61
        fprintf(stderr, "  socket nonblocking, select() returned %d\n", res);
 
62
 
 
63
        p = read(s, NULL, 0);
 
64
        fprintf(stderr, "  read() returned %d, errno = %d (%s)\n", p, errno, (strerror(errno)));
 
65
        p = write(s, &foo, 5);
 
66
        fprintf(stderr, "  write() returned %d, errno = %d (%s)\n", p, errno, (strerror(errno)));
 
67
 
 
68
        if (res == 0)
 
69
                return 0; /* correct behaviour */
 
70
        else
 
71
                return 1; /* incorrect behaviour */
 
72
}
 
73
 
 
74
static int 
 
75
selectcheck(s)
 
76
        int s;
 
77
{
 
78
        fd_set rset, wset, xset;
 
79
        struct timeval timeout;
 
80
        int ret,i;
 
81
 
 
82
        FD_ZERO(&rset);
 
83
        FD_SET(s, &rset);
 
84
        wset = xset = rset;
 
85
 
 
86
        timeout.tv_sec  = 0;
 
87
        timeout.tv_usec         = 0;
 
88
 
 
89
        errno = 0;
 
90
        ret = select(s + 1, &rset, &wset, &xset, &timeout);
 
91
        if (FD_ISSET(s,&rset)) {
 
92
            fprintf(stderr, "  socket is readable\n");
 
93
        }
 
94
        if (FD_ISSET(s,&wset)) {
 
95
            fprintf(stderr, "  socket is writeable\n");
 
96
        }
 
97
        if (FD_ISSET(s,&xset)) {
 
98
            fprintf(stderr, "  socket has an exception\n");
 
99
        }
 
100
        return ret;
 
101
}], [AC_MSG_RESULT(yes)
 
102
     [$1]],
 
103
    [AC_MSG_RESULT(no)
 
104
     [$2]])])
 
105
 
 
106
#can it really be this simple?
 
107
#nope, doesn't handle coff files which also have no underscore
 
108
AC_DEFUN(L_SYMBOL_UNDERSCORE,
 
109
[AC_MSG_CHECKING(for object file type)
 
110
AC_TRY_RUN([
 
111
/* look for ELF identification header at the start of argv[0] */
 
112
 
 
113
#include <stdio.h>
 
114
#include <fcntl.h>
 
115
#include <string.h>
 
116
 
 
117
/*
 
118
 * ELF header, from ELF standard (Portable Formats Specification,
 
119
 *  Version 1.1).
 
120
 */
 
121
char elfheader[] = { 0x7f, 'E', 'L', 'F' };
 
122
 
 
123
int
 
124
main (argc, argv)
 
125
        int argc;
 
126
        char *argv[];
 
127
{
 
128
        int fd;
 
129
        int len = sizeof(elfheader);
 
130
        char header[len];
 
131
 
 
132
        if ((fd = open(argv[0], O_RDONLY, 0)) == -1) {
 
133
                perror("open");
 
134
                exit(1);
 
135
        }
 
136
        if (read(fd, header, len) != len) {
 
137
                perror("read");
 
138
                exit(1);
 
139
        }
 
140
        if (memcmp(header, elfheader, len) == 0)
 
141
                exit(0); /* pointy ears */
 
142
        else
 
143
                exit(1);
 
144
}
 
145
], [AC_MSG_RESULT(elf)
 
146
    AC_DEFINE(HAVE_NO_SYMBOL_UNDERSCORE)],
 
147
   [
 
148
        #XXX exceptions for coff platforms, should be detected automatically
 
149
        case $host in
 
150
                alpha*-dec-osf*)
 
151
                        AC_DEFINE(HAVE_NO_SYMBOL_UNDERSCORE)
 
152
                        AC_MSG_RESULT(coff)
 
153
                        ;;
 
154
                *-*-hpux*) #XXX apparently does not use underscore
 
155
                        AC_DEFINE(HAVE_NO_SYMBOL_UNDERSCORE)
 
156
                        AC_MSG_RESULT(a.out?)
 
157
                        ;;
 
158
                *)
 
159
                        AC_MSG_RESULT(a.out)
 
160
                        ;;
 
161
        esac])])
 
162
 
 
163
 
 
164
define(testparam,[
 
165
_arg=[$2]
 
166
_param=[$3]
 
167
_func=[$4]
 
168
_ucfunc=[$5]
 
169
 
 
170
unset _nofunc
 
171
 
 
172
for val in [$1]
 
173
do
 
174
        cat ${_param} | egrep "^${val}" > /dev/null
 
175
        test $? -eq 0 && _nofunc="" && break
 
176
        _nofunc=t
 
177
done
 
178
if test "x${_nofunc}" = xt; then
 
179
        if test "x[$$6]" != x; then
 
180
                [$6]="$$6|"
 
181
        fi
 
182
        [$6]="[$$6] ${_func} (${_arg}): (`cat ${_param}`)"
 
183
else
 
184
        AC_DEFINE_UNQUOTED(HAVE_PROT_${_ucfunc}_${_arg}, ${val})
 
185
fi
 
186
])dnl
 
187
 
 
188
dnl #XXXugly
 
189
dnl #attempt to speed up runtime by avoiding subshells
 
190
AC_DEFUN(L_SOCKPROTO,
 
191
[
 
192
dnl this function is not very generic, and only supports nine arguments
 
193
syscmd(if test $# -gt 9; then exit 1;fi) dnl
 
194
ifelse(sysval, 0, , [errprint(__file__:__line__: error in acinclude.m4: too many arguments to function [$0]
 
195
) m4exit(1)])dnl
 
196
 
 
197
nargs=[$#]
 
198
 
 
199
paramcnt=decr(decr([$#]))
 
200
 
 
201
dnl XXX
 
202
dnl func=translit([$1], ` ')
 
203
dnl ucfunc=translit(translit([$1], ` '), `a-z', `A-Z')
 
204
 
 
205
syscmd(echo '$1' | grep "\." > /dev/null)dnl
 
206
func=ifelse(sysval, 0, [esyscmd(echo '$1' | cut -d. -f1)dnl], translit([$1], ` '))
 
207
syscmd(echo '$1' | grep "\." > /dev/null)dnl
 
208
dnl ucfunc=ifelse(sysval, 0, esyscmd(echo '$1' | cut -d. -f2), translit(translit([$1], ` '), `a-z', `A-Z'))
 
209
ucfunc=translit(ifelse(sysval, 0, esyscmd(echo '$1' | cut -d. -f2), translit([$1], ` ')), `a-z', `A-Z')
 
210
 
 
211
dnl func=translit([$SYS_NAME], ` ')
 
212
dnl ucfunc=translit(translit([$REAL_NAME], ` '), `a-z', `A-Z')
 
213
 
 
214
AC_MSG_CHECKING([prototypes for $func])
 
215
 
 
216
unset failure
 
217
 
 
218
cat > conftest.$ac_ext <<EOF
 
219
#include "confdefs.h"
 
220
#include <sys/types.h>
 
221
#include <sys/socket.h>
 
222
#include <sys/uio.h>
 
223
#include <netdb.h>
 
224
#include <unistd.h>
 
225
EOF
 
226
 
 
227
changequote(<<, >>)dnl
 
228
${CPP} ${CPPFLAGS} ${CPPFLAG_STDC} conftest.$ac_ext | $AWK "{ if (/[^a-z0-9_]${func}[^a-z0-9_]/) { s=10 }; if ( s > 0 ) { s -= 1; print; } }" | egrep -v '^#' | tr '\n' ' ' | tr -s '/' |  tr ';' '\n'  | grep -v "__${func}" | egrep "[^a-z0-9_]${func}[^a-z0-9_]" | tr -s '[:blank:]' | sed -e 's/extern//' > conftest.out_proto
 
229
 
 
230
cnt=0
 
231
while test $cnt -lt $paramcnt; do
 
232
        if test $cnt -eq 0; then
 
233
                cat conftest.out_proto | sed -e "s/${func}.*//" | sed -e 's/^[  ]*//' | sed -e 's/[     ]*$//g' > conftest.out_param
 
234
        else
 
235
                cat conftest.out_proto | sed -e "s/.*${func}//" | sed -e "s/[\(\)]//g" | cut -d, -f $cnt | sed -e 's/^[         ]*//' | sed -e 's/[     ]*$//g' > conftest.out_param
 
236
        fi
 
237
dnl     XXXstrip whatever's behind any *?
 
238
 
 
239
        cat conftest.out_param | tr -s '[:blank:]' > conftest.out_nospace
 
240
        if test -s conftest.out_nospace; then
 
241
                cp -f conftest.out_param conftest.out_param_${cnt}
 
242
        else
 
243
dnl             #XXX
 
244
                echo "not found" > conftest.out_param_${cnt}
 
245
                echo "warning: found no argument"
 
246
        fi
 
247
 
 
248
        #XXX avoid subshell
 
249
        case $cnt in
 
250
                0) cnt=1;;
 
251
                1) cnt=2;;
 
252
                2) cnt=3;;
 
253
                3) cnt=4;;
 
254
                4) cnt=5;;
 
255
                5) cnt=6;;
 
256
                6) cnt=7;;
 
257
                7) cnt=8;;
 
258
                8) cnt=9;;
 
259
                9) cnt=10;;
 
260
                10) cnt=11;;
 
261
        esac
 
262
 
 
263
done
 
264
 
 
265
changequote([, ])dnl
 
266
 
 
267
ifelse([$3], , ,
 
268
[       #return value
 
269
        testparam([$3], 0, conftest.out_param_0, $func, $ucfunc, failure)dnl
 
270
])dnl
 
271
 
 
272
ifelse([$4], , ,
 
273
[       #first argument
 
274
        testparam([$4], 1, conftest.out_param_1, $func, $ucfunc, failure)dnl
 
275
])dnl
 
276
 
 
277
ifelse([$5], , ,
 
278
[       #second argument
 
279
        testparam([$5], 2, conftest.out_param_2, $func, $ucfunc, failure)dnl
 
280
])dnl
 
281
 
 
282
ifelse([$6], , ,
 
283
[       #third argument
 
284
        testparam([$6], 3, conftest.out_param_3, $func, $ucfunc, failure)dnl
 
285
])dnl
 
286
 
 
287
ifelse([$7], , ,
 
288
[       #fourth argument
 
289
        testparam([$7], 4, conftest.out_param_4, $func, $ucfunc, failure)dnl
 
290
])dnl
 
291
 
 
292
ifelse([$8], , ,
 
293
[       #fifth argument
 
294
        testparam([$8], 5, conftest.out_param_5, $func, $ucfunc, failure)dnl
 
295
])dnl
 
296
 
 
297
ifelse([$9], , ,
 
298
[       #sixth argument
 
299
        testparam([$9], 6, conftest.out_param_6, $func, $ucfunc, failure)dnl
 
300
])dnl
 
301
 
 
302
ifelse([$10], , ,
 
303
[       #seventh argument
 
304
        testparam([$10], 7, conftest.out_param_7, $func, $ucfunc, failure)dnl
 
305
])dnl
 
306
 
 
307
#failure
 
308
if test "x$failure" != x; then
 
309
AC_MSG_RESULT(failure)
 
310
 
 
311
echo "$failure" | tr '|' '\n'
 
312
 
 
313
ifelse([$2], , ,
 
314
[ $2
 
315
])dnl
 
316
else
 
317
        AC_MSG_RESULT(ok)
 
318
fi
 
319
 
 
320
rm -f conftest.*
 
321
])dnl
 
322
# -- acinclude end --
 
 
b'\\ No newline at end of file'