Initial commit of src/ptmx.c
This commit is contained in:
parent
5754c383a6
commit
241f647b03
2 changed files with 54 additions and 1 deletions
|
@ -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
|
||||
|
|
53
src/ptmx.c
Normal file
53
src/ptmx.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
#define _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Add table
Reference in a new issue