commit 2e6ecfd77a20af7528d0bdb03a20697778577a7b
parent 93e2996fffbeaa4fc51e1a61e15309561cd257cb
Author: Kyle Milz <krwmilz@gmail.com>
Date: Sat, 11 Mar 2023 20:07:40 +0000
simplify and inline prep_fd()
Diffstat:
3 files changed, 11 insertions(+), 37 deletions(-)
diff --git a/popups.c b/popups.c
@@ -34,9 +34,11 @@ IN THE SOFTWARE.
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h> /* fcntl() */
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h> /* free(), atoi(), getenv() */
+#include <unistd.h> /* getpid() */
#include <X11/Xatom.h>
#include <X11/Xos.h>
@@ -52,7 +54,7 @@ IN THE SOFTWARE.
#include "events.h" /* handle_messages(), mane, struct xio */
#include "popups.h"
#include "xdvi.h"
-#include "util.h" /* prep_fd(), xfopen() */
+#include "util.h" /* xfopen() */
#ifdef EWOULDBLOCK
@@ -1402,7 +1404,12 @@ print_do_it()
(void) close(print_io[1]);
/* Set up file descriptor for non-blocking I/O */
- prep_fd(print_io[0], True);
+ fcntl(print_io[0], F_SETFL, fcntl(print_io[0], F_GETFL, 0) | O_NONBLOCK);
+ if (fcntl(print_io[0], F_SETOWN, getpid()) == -1)
+ warnx("fcntl F_SETOWN");
+ if (fcntl(print_io[0], F_SETFL, fcntl(print_io[0], F_GETFL, 0) | FASYNC) == -1)
+ warnx("fcntl F_SETFL");
+
print_xio.fd = print_io[0];
set_io(&print_xio);
diff --git a/util.c b/util.c
@@ -25,15 +25,13 @@ NOTE:
\*========================================================================*/
-#include <sys/file.h> /* this defines FASYNC */
-#include <sys/ioctl.h> /* this defines SIOCSPGRP and FIOASYNC */
-
#include <err.h>
+#include <fcntl.h> /* fcntl() */
#include <stdlib.h> /* malloc(), realloc() */
#include <string.h> /* strdup(), memcpy() */
#include <strings.h> /* bcopy() */
#include <pwd.h> /* getpwuid(), getpwnam() */
-#include <unistd.h> /* getuid(), getpid() */
+#include <unistd.h> /* getuid() */
#include "util.h"
#include "xdvi.h"
@@ -337,36 +335,6 @@ avladd(const char *key, size_t key_len, struct avl **headp, size_t size)
}
/*
- * Prepare the file descriptor to generate SIGPOLL/SIGIO events.
- * If called with a True argument, set it up for non-blocking I/O.
- */
-void
-prep_fd(int fd, Boolean noblock)
-{
- /* Set file descriptor for non-blocking I/O */
- if (noblock)
- (void) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
- {
-# ifdef FASYNC
- if (fcntl(fd, F_SETOWN, getpid()) == -1)
- perror("xdvi: fcntl F_SETOWN");
- if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FASYNC) == -1)
- perror("xdvi: fcntl F_SETFL");
-# elif defined SIOCSPGRP && defined FIOASYNC
- /* For HP-UX B.10.10 and maybe others. See "man 7 socket". */
- int arg;
-
- arg = getpid();
- if (ioctl(fd, SIOCSPGRP, &arg) == -1)
- perror("xdvi: ioctl SIOCSPGRP");
- arg = 1;
- if (ioctl(fd, FIOASYNC, &arg) == -1)
- perror("xdvi: ioctl FIOASYNC");
-# endif
- }
-}
-
-/*
* Try and parse dest_url[] as a url:
* - ignore protocol if found
* - hostname is either what's remaining or up to a colon or slash character
diff --git a/util.h b/util.h
@@ -18,7 +18,6 @@ struct avl *avladd(const char *, size_t, struct avl **, size_t);
void expandline(size_t);
const struct passwd *ff_getpw(const char **, const char *);
-void prep_fd(int, Boolean);
FILE *xfopen(const char *, const char *);
void *xmalloc(size_t);