1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include <errno.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <paths.h>
- #include <sys/statfs.h>
- #define DEVPTS_SUPER_MAGIC 0x1cd1
- #define DEVFS_SUPER_MAGIC 0x1373
- #define _PATH_DEVPTMX _PATH_DEV "ptmx"
- #define _PATH_DEVPTS _PATH_DEV "pts"
- int __bsd_getpt (void);
- int
- getpt (void)
- {
- static int have_no_dev_ptmx;
- int fd;
- if (!have_no_dev_ptmx)
- {
- fd = open (_PATH_DEVPTMX, O_RDWR);
- if (fd != -1)
- {
- struct statfs fsbuf;
- static int devpts_mounted;
-
- if (devpts_mounted
- || (statfs (_PATH_DEVPTS, &fsbuf) == 0
- && fsbuf.f_type == DEVPTS_SUPER_MAGIC)
- || (statfs (_PATH_DEV, &fsbuf) == 0
- && fsbuf.f_type == DEVFS_SUPER_MAGIC))
- {
-
- devpts_mounted = 1;
- return fd;
- }
-
- close (fd);
- have_no_dev_ptmx = 1;
- }
- else
- {
- if (errno == ENOENT || errno == ENODEV)
- have_no_dev_ptmx = 1;
- else
- return -1;
- }
- }
- return __bsd_getpt ();
- }
- #define PTYNAME1 "pqrstuvwxyzabcde";
- #define PTYNAME2 "0123456789abcdef";
- #define __getpt __bsd_getpt
- #include "bsd_getpt.c"
|