Fortran: Suppress wrong End Of File error with user defined IO.
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / fd-glibc-byte-stream-socket.c
blobfd57d3b0894a023ba93194c1c6e5d1e6e30778d4
1 /* Example from glibc manual (16.9.6). */
2 /* { dg-require-effective-target sockets } */
4 /* Needed on some targets until we have exception-handling working (PR 111475). */
5 /* { dg-additional-options "-fno-exceptions" } */
7 /* { dg-skip-if "" { hppa*-*-hpux* powerpc*-*-aix* } } */
9 #include <stdio.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <netinet/in.h>
17 #include <netdb.h>
19 #define PORT 5555
20 #define MESSAGE "Yow!!! Are we having fun yet?!?"
21 #define SERVERHOST "www.gnu.org"
23 void
24 write_to_server (int filedes)
26 int nbytes;
28 nbytes = write (filedes, MESSAGE, strlen (MESSAGE) + 1);
29 if (nbytes < 0)
31 perror ("write");
32 exit (EXIT_FAILURE);
37 int
38 main (void)
40 extern void init_sockaddr (struct sockaddr_in *name,
41 const char *hostname,
42 uint16_t port);
43 int sock;
44 struct sockaddr_in servername;
46 /* Create the socket. */
47 sock = socket (PF_INET, SOCK_STREAM, 0);
48 if (sock < 0)
50 perror ("socket (client)");
51 exit (EXIT_FAILURE);
54 /* Connect to the server. */
55 init_sockaddr (&servername, SERVERHOST, PORT);
56 if (0 > connect (sock,
57 (struct sockaddr *) &servername,
58 sizeof (servername)))
60 perror ("connect (client)");
61 exit (EXIT_FAILURE);
64 /* Send data to the server. */
65 write_to_server (sock);
66 close (sock);
67 exit (EXIT_SUCCESS);