commit 52872ba2cf357e4ee87723a63b0420aec4fd8754
parent aec88ab5ac2404fdd0f79988742cb2dd50ce0b60
Author: Jan Pobrislo <ccx@te2000.cz>
Date: Wed, 31 Jul 2024 11:22:33 +0000
ptsname program
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/src/ptsname.c b/src/ptsname.c
@@ -0,0 +1,30 @@
+#include <unistd.h> /* write() */
+#include <stdlib.h> /* ptsname() */
+#include <string.h>
+
+#include <skalibs/types.h>
+#include <skalibs/strerr.h>
+
+#define USAGE "ptsname ptmx_fd"
+#define PROG "ptsname"
+
+
+int main (int argc, char const *const *argv)
+{
+ unsigned int ptmx_fd;
+ const char *pts_name;
+ if ((argc != 2)) strerr_dieusage(100, USAGE) ;
+ if (!uint0_scan(argv[1], &ptmx_fd)) strerr_dieusage(100, USAGE) ;
+
+ pts_name = ptsname(ptmx_fd);
+ if (pts_name == NULL) {
+ strerr_dief1sys(111, "ptsname()");
+ }
+
+ if (write(1, pts_name, strlen(pts_name)) <= 0) {
+ strerr_dief1sys(111, "write()");
+ }
+ if (write(1, "\n", 1) <= 0) {
+ strerr_dief1sys(111, "write()");
+ }
+}