Use ptsname(), not ptsname_r(), for portability

This commit is contained in:
XANTRONIX Development 2020-07-26 18:42:49 -04:00 committed by XANTRONIX Industrial
parent 10745bbabf
commit 9463e22481
4 changed files with 14 additions and 11 deletions

View file

@ -54,16 +54,16 @@ int main(int argc, char **argv) {
} }
if (isatty(info.fd) && grantpt(info.fd) == 0 && unlockpt(info.fd) == 0) { if (isatty(info.fd) && grantpt(info.fd) == 0 && unlockpt(info.fd) == 0) {
char name[256]; char *pts;
if (ptsname_r(info.fd, name, sizeof(name)) < 0) { if ((pts = ptsname(info.fd)) == NULL) {
fprintf(stderr, "%s: %s: %s: %s\n", fprintf(stderr, "%s: %s: %s: %s\n",
argv[0], argv[1], "ptsname_r()", strerror(errno)); argv[0], argv[1], "ptsname()", strerror(errno));
goto error_open; goto error_open;
} }
fprintf(stderr, "pts %s\n", name); fprintf(stderr, "pts %s\n", pts);
} }
errno = 0; errno = 0;

View file

@ -73,7 +73,7 @@ typedef struct _patty_ax25_sock {
flags_hdlc; flags_hdlc;
int fd; int fd;
char path[PATTY_AX25_SOCK_PATH_SIZE]; char pty[PATTY_AX25_SOCK_PATH_SIZE];
void *tx_buf, void *tx_buf,
*rx_buf; *rx_buf;

View file

@ -555,7 +555,7 @@ static int server_socket(patty_ax25_server *server, int client) {
response.ret = sock->fd; response.ret = sock->fd;
response.eno = 0; response.eno = 0;
memcpy(response.path, sock->path, sizeof(response.path)); memcpy(response.path, patty_ax25_sock_pty(sock), sizeof(response.path));
return write(client, &response, sizeof(response)); return write(client, &response, sizeof(response));
@ -1201,7 +1201,7 @@ static int handle_sabm(patty_ax25_server *server,
fd_watch(server, remote->fd); fd_watch(server, remote->fd);
if (respond_accept(client, 0, 0, &frame->src, remote->path) < 0) { if (respond_accept(client, 0, 0, &frame->src, remote->pty) < 0) {
goto error_respond_accept; goto error_respond_accept;
} }

View file

@ -14,6 +14,7 @@
static int bind_pty(patty_ax25_sock *sock) { static int bind_pty(patty_ax25_sock *sock) {
struct termios t; struct termios t;
char *pty;
if ((sock->fd = open("/dev/ptmx", O_RDWR)) < 0) { if ((sock->fd = open("/dev/ptmx", O_RDWR)) < 0) {
goto error_open; goto error_open;
@ -27,10 +28,12 @@ static int bind_pty(patty_ax25_sock *sock) {
goto error_unlockpt; goto error_unlockpt;
} }
if (ptsname_r(sock->fd, sock->path, sizeof(sock->path)) < 0) { if ((pty = ptsname(sock->fd)) == NULL) {
goto error_ptsname_r; goto error_ptsname;
} }
(void)strncpy(sock->pty, pty, sizeof(sock->pty));
if (tcgetattr(sock->fd, &t) < 0) { if (tcgetattr(sock->fd, &t) < 0) {
goto error_tcgetattr; goto error_tcgetattr;
} }
@ -45,7 +48,7 @@ static int bind_pty(patty_ax25_sock *sock) {
error_tcsetattr: error_tcsetattr:
error_tcgetattr: error_tcgetattr:
error_ptsname_r: error_ptsname:
error_unlockpt: error_unlockpt:
error_grantpt: error_grantpt:
close(sock->fd); close(sock->fd);
@ -299,7 +302,7 @@ error_invalid:
} }
char *patty_ax25_sock_pty(patty_ax25_sock *sock) { char *patty_ax25_sock_pty(patty_ax25_sock *sock) {
return sock->path; return sock->pty;
} }
int patty_ax25_sock_bind_if(patty_ax25_sock *sock, int patty_ax25_sock_bind_if(patty_ax25_sock *sock,