Make sure socket file is created in socket_close testcase
[valgrind.git] / none / tests / socket_close.c
blob402c0a5d554b6d408d0252bab9f3e99dec950184
1 #define _GNU_SOURCE
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <sys/socket.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/un.h>
9 const char *SPATH = "/tmp/vgtest-foofrob";
10 int socket_fd;
12 void open_socket()
14 unlink (SPATH); /* Make sure socket path doesn't exist yet. */
16 socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
17 fprintf (stderr, "Open socket %d\n", socket_fd);
18 struct sockaddr_un my_addr;
20 memset(&my_addr, 0, sizeof(my_addr));
21 my_addr.sun_family = AF_UNIX;
22 strncpy(my_addr.sun_path, SPATH, sizeof(my_addr.sun_path) - 1);
23 bind(socket_fd, (struct sockaddr *) &my_addr, sizeof(my_addr));
26 int main ()
28 open_socket();
30 if (socket_fd != -1)
32 fprintf(stderr, "close socket_fd %d\n", socket_fd);
33 close (socket_fd);
36 fprintf (stderr, "and close the socket again %d\n", socket_fd);
37 close (socket_fd);
39 return 0;