bump for release
[uclibc-ng.git] / test / inet / tst-sock-nonblock.c
blob54a7ee28a8461d5775fffcce1b03f781399b0e20
1 /* vi: set sw=4 ts=4 sts=4: */
2 /*
3 * Nonblocking socket test for uClibc
4 * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <error.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <sys/un.h>
18 #include <sys/fcntl.h>
20 static int
21 do_test(void)
23 int fd, ret, result = 0;
24 struct sockaddr_un sa;
25 char buf;
27 fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
28 if (fd < 0) {
29 perror("socket()");
30 result = 1;
33 memset(&sa, 0, sizeof(sa));
34 sa.sun_family = AF_UNIX;
35 strcpy(sa.sun_path, "socktest");
36 unlink("socktest");
37 if (bind(fd, (const struct sockaddr *)&sa, sizeof(sa)) < 0) {
38 perror("bind()");
39 result = 1;
42 ret = read(fd, &buf, sizeof(buf));
43 if (ret != -1 || errno != EAGAIN) {
44 error(0, 0, "Nonblocking read returned %d", ret);
45 result = 1;
48 return result;
51 #define TIMEOUT 5
52 #define TEST_FUNCTION do_test ()
53 #include "../test-skeleton.c"