arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / ser-uds.c
blob8da4c7a22fa51a7f69a5bb87f67d99e0d42a649d
1 /* Serial interface for local domain connections on Un*x like systems.
3 Copyright (C) 1992-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "serial.h"
21 #include "ser-base.h"
23 #include <sys/socket.h>
24 #include <sys/un.h>
26 #ifndef UNIX_PATH_MAX
27 #define UNIX_PATH_MAX sizeof(((struct sockaddr_un *) NULL)->sun_path)
28 #endif
30 /* Open an AF_UNIX socket. */
32 static void
33 uds_open (struct serial *scb, const char *name)
35 struct sockaddr_un addr;
37 if (strlen (name) > UNIX_PATH_MAX - 1)
38 error (_("The socket name is too long. It may be no longer than %s bytes."),
39 pulongest (UNIX_PATH_MAX - 1L));
41 memset (&addr, 0, sizeof addr);
42 addr.sun_family = AF_UNIX;
43 strncpy (addr.sun_path, name, UNIX_PATH_MAX - 1);
45 scb->fd = socket (AF_UNIX, SOCK_STREAM, 0);
46 if (scb->fd < 0)
47 perror_with_name (_("could not open socket"));
49 if (connect (scb->fd, (struct sockaddr *) &addr,
50 sizeof (struct sockaddr_un)) < 0)
52 int saved = errno;
53 close (scb->fd);
54 perror_with_name (_("could not connect to remote"), saved);
58 static void
59 uds_close (struct serial *scb)
61 if (scb->fd == -1)
62 return;
64 close (scb->fd);
65 scb->fd = -1;
68 static int
69 uds_read_prim (struct serial *scb, size_t count)
71 int result = recv (scb->fd, scb->buf, count, 0);
72 if (result == -1 && errno != EINTR)
73 perror_with_name ("error while reading");
74 return result;
77 static int
78 uds_write_prim (struct serial *scb, const void *buf, size_t count)
80 int result = send (scb->fd, buf, count, 0);
81 if (result == -1 && errno != EINTR)
82 perror_with_name ("error while writing");
83 return result;
86 /* The local socket ops. */
88 static const struct serial_ops uds_ops =
90 "local",
91 uds_open,
92 uds_close,
93 NULL,
94 ser_base_readchar,
95 ser_base_write,
96 ser_base_flush_output,
97 ser_base_flush_input,
98 ser_base_send_break,
99 ser_base_raw,
100 ser_base_get_tty_state,
101 ser_base_copy_tty_state,
102 ser_base_set_tty_state,
103 ser_base_print_tty_state,
104 ser_base_setbaudrate,
105 ser_base_setstopbits,
106 ser_base_setparity,
107 ser_base_drain_output,
108 ser_base_async,
109 uds_read_prim,
110 uds_write_prim
113 void _initialize_ser_socket ();
114 void
115 _initialize_ser_socket ()
117 serial_add_interface (&uds_ops);