diff --git a/src/Makefile b/src/Makefile index d06d56b..a68caeb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ HEADERS = buffer.h kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \ OBJS = buffer.o kiss.o ax25.o if.o address.o frame.o \ list.o hash.o dict.o -EXAMPLES = iflist decode +EXAMPLES = iflist decode ptmx AR = $(CROSS)ar RANLIB = $(CROSS)ranlib diff --git a/src/ptmx.c b/src/ptmx.c new file mode 100644 index 0000000..8f8c654 --- /dev/null +++ b/src/ptmx.c @@ -0,0 +1,53 @@ +#define _XOPEN_SOURCE +#define _XOPEN_SOURCE_EXTENDED +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + int ptm; + char ptsname[64]; + + if ((ptm = open("/dev/ptmx", O_RDWR)) < 0) { + fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "open()", "/dev/ptmx", strerror(errno)); + + goto error_open_ptmx; + } + + if (grantpt(ptm) < 0) { + fprintf(stderr, "%s: %s: %s\n", argv[0], "grantpt()", strerror(errno)); + + goto error_grantpt_ptm; + } + + if (unlockpt(ptm) < 0) { + fprintf(stderr, "%s: %s: %s\n", argv[0], "unlockpt()", strerror(errno)); + + goto error_unlockpt_ptm; + } + + if (ptsname_r(ptm, ptsname, sizeof(ptsname)) < 0) { + fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "ptsname_r()", "/dev/ptmx", strerror(errno)); + + goto error_ptsname_r_ptm; + } + + printf("pts %s\n", ptsname); + + close(ptm); + + return 0; + +error_unlockpt_ptm: +error_grantpt_ptm: +error_ptsname_r_ptm: + close(ptm); + +error_open_ptmx: + return 127; +}