本文整理汇总了C++中posix_openpt函数的典型用法代码示例。如果您正苦于以下问题:C++ posix_openpt函数的具体用法?C++ posix_openpt怎么用?C++ posix_openpt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posix_openpt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: create_pts
int create_pts(void)
{
int pts = posix_openpt(O_RDWR | O_NONBLOCK);
struct termios termios;
if (pts < 0)
err(1, "failed to create pseudo terminal");
if (grantpt(pts))
err(1, "failed to grant psuedo terminal access");
if (unlockpt(pts))
err(1, "failed to unlock pseudo terminal");
if (tcgetattr(pts, &termios))
err(1, "failed to get termios");
cfmakeraw(&termios);
if (tcsetattr(pts, TCSANOW, &termios))
err(1, "failed to set termios");
if (sim_is_interactive())
printf("pts: %s\n", ptsname(pts));
return pts;
}
开发者ID:8l,项目名称:oldland-cpu,代码行数:25,代码来源:uart.c
示例2: GUCEF_pty_open
int
GUCEF_pty_open( int* fdm, int* fds )
{
int masterfd, slavefd;
char *slavedevice;
/*
* O_RDWR = Open the device for both reading and writing. It is usual to specify this flag.
* O_NOCTTY = Do not make this device the controlling terminal for the process.
*/
masterfd = posix_openpt( O_RDWR | O_NOCTTY );
if ( masterfd == -1 ||
grantpt (masterfd) == -1 ||
unlockpt (masterfd) == -1 ||
(slavedevice = ptsname (masterfd)) == NULL)
return 1;
slavefd = open(slavedevice, O_RDWR|O_NOCTTY);
if (slavefd < 0)
return 1;
/* success */
*fdm = masterfd;
*fds = slavefd;
return 0;
}
开发者ID:LiberatorUSA,项目名称:GUCEF,代码行数:27,代码来源:gucefCORE_pty.c
示例3: ptyFork
/* To open and start new
* python shell process
*/
gboolean
ptyFork (ChildProcessData *python_shell_data, GError **error)
{
int mfd, slaveFd, savedErrno;
mfd = posix_openpt (O_RDWR | O_NOCTTY | O_NONBLOCK);
grantpt (mfd);
unlockpt (mfd);
python_shell_data->master_fd = mfd;
python_shell_data->slave_name = g_strdup (ptsname (mfd));
python_shell_data->sh_argv = g_malloc0 (sizeof (gchar *));
python_shell_data->sh_argv[0] = g_strdup ("/bin/sh");
/*if (!g_spawn_async (python_shell_data->current_dir, python_shell_data->argv, NULL, 0,
child_func, (gpointer)python_shell_data,
&(python_shell_data->pid), error))
return FALSE;*/
pid_t childPid = fork ();
if (childPid == 0)
{
child_func ((gpointer)python_shell_data);
execv (python_shell_data->sh_argv [0], python_shell_data->sh_argv);
}
python_shell_data->pid = childPid;
return TRUE;
}
开发者ID:abhijangda,项目名称:gIDLE,代码行数:32,代码来源:pty_fork.c
示例4: ptym_open
int ptym_open(char *pts_name, int pts_namesz)
{
char *ptr;
int fdm;
/*
* Return the name of the master device so that on failure
* the caller can print an error message. Null terminate
* to handle case where string length > pts_namesz.
*/
strncpy(pts_name, "/dev/ptyXY", pts_namesz);
pts_name[pts_namesz - 1] = '\0';
if ((fdm = posix_openpt(O_RDWR)) < 0)
return(-1);
if (grantpt(fdm) < 0) { /* grant access to slave */
close(fdm);
return(-2);
}
if (unlockpt(fdm) < 0) { /* clear slave's lock flag */
close(fdm);
return(-3);
}
if ((ptr = ptsname(fdm)) == NULL) { /* get slave's name */
close(fdm);
return(-4);
}
/*
* Return name of slave. Null terminate to handle
* case where strlen(ptr) > pts_namesz.
*/
strncpy(pts_name, ptr, pts_namesz);
pts_name[pts_namesz - 1] = '\0';
return(fdm); /* return fd of master */
}
开发者ID:zhaochao,项目名称:programming-practice,代码行数:35,代码来源:ptyopen_bsd.c
示例5: get_pty
bool
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid)
{
char *line;
bool rval = false;
debug_decl(get_pty, SUDO_DEBUG_PTY)
*master = posix_openpt(O_RDWR|O_NOCTTY);
if (*master != -1) {
(void) grantpt(*master); /* may fork */
if (unlockpt(*master) != 0) {
close(*master);
goto done;
}
line = ptsname(*master);
if (line == NULL) {
close(*master);
goto done;
}
*slave = open(line, O_RDWR|O_NOCTTY, 0);
if (*slave == -1) {
close(*master);
goto done;
}
# if defined(I_PUSH) && !defined(_AIX)
ioctl(*slave, I_PUSH, "ptem"); /* pseudo tty emulation module */
ioctl(*slave, I_PUSH, "ldterm"); /* line discipline module */
# endif
(void) chown(line, ttyuid, -1);
strlcpy(name, line, namesz);
rval = true;
}
done:
debug_return_bool(rval);
}
开发者ID:aixoss,项目名称:sudo,代码行数:35,代码来源:get_pty.c
示例6: ptym_open
int
ptym_open(char *pts_name, int pts_namesz)
{
char *ptr;
int fdm, err;
if ((fdm = posix_openpt(O_RDWR)) < 0)
return(-1);
if (grantpt(fdm) < 0) /* grant access to slave */
goto errout;
if (unlockpt(fdm) < 0) /* clear slave's lock flag */
goto errout;
if ((ptr = ptsname(fdm)) == NULL) /* get slave's name */
goto errout;
/*
* Return name of slave. Null terminate to handle
* case where strlen(ptr) > pts_namesz.
*/
strncpy(pts_name, ptr, pts_namesz);
pts_name[pts_namesz - 1] = '\0';
return(fdm); /* return fd of master */
errout:
err = errno;
close(fdm);
errno = err;
return(-1);
}
开发者ID:daidaotian,项目名称:apue.3e-1,代码行数:28,代码来源:ptyopen.c
示例7: create_ps_term
int right_side::create_ps_term() {
int master;
if ((master = posix_openpt(O_RDWR)) == -1) { throw_error("posix_openpt()"); }
if (grantpt(master) == -1) { throw_error("grantpt()"); }
if (unlockpt(master) == -1) { throw_error("inlockpt()"); }
int slave = open(ptsname(master), O_RDWR);
if (slave == -1) { throw_error("open(ptsname(master)..."); }
child = fork();
if (child == -1) { throw_error("fork()"); }
if (!child) {
struct termios settings;
tcgetattr(slave, &settings);
cfmakeraw(&settings);
tcsetattr(slave, TCSANOW, &settings);
close(master);
if (dup2(slave, STDIN_FILENO) == -1) {throw_error("dup2(slave, STDIN_FILENO)");}
if (dup2(slave, STDOUT_FILENO) == -1) {throw_error("dup2(slave, STDOUT_FILENO)");}
if (dup2(slave, STDERR_FILENO) == -1) {throw_error("dup2(slave, STDERR_FILENO)");}
close(slave);
setsid();
ioctl(0, TIOCSCTTY, 1);
if (execlp("/bin/sh", "sh", NULL) == -1) {throw_error("execlp()");}
} else {
close(slave);
}
return master;
}
开发者ID:Voidmster,项目名称:OS_2015,代码行数:34,代码来源:rsh_daemon.cpp
示例8: test_ebadf
static int
test_ebadf (void)
{
int fd, ret, err;
fd = posix_openpt (O_RDWR);
if (fd == -1)
{
printf ("posix_openpt(O_RDWR) failed\nerrno %d (%s)\n",
errno, strerror (errno));
/* We don't fail because of this; maybe the system does not have
SUS pseudo terminals. */
return 0;
}
unlockpt (fd);
close (fd);
ret = grantpt (fd);
err = errno;
if (ret != -1 || err != EBADF)
{
printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EBADF);
printf (" got: return = %d, errno = %d\n", ret, err);
return 1;
}
return 0;
}
开发者ID:AdvancedC,项目名称:glibc,代码行数:27,代码来源:tst-grantpt.c
示例9: open
int open(const char *pathname, int flags, ...)
{
int fd = 99;
/* Ugly, but fine. */
if (!strncmp(pathname,LOG_PATH,strlen(LOG_PATH))) {
fd = alloc_fd(FTYPE_CONSOLE);
} else if (!strncmp(pathname, "/dev/mem", strlen("/dev/mem"))) {
fd = alloc_fd(FTYPE_MEM);
} else if (!strncmp(pathname, "/dev/ptmx", strlen("/dev/ptmx"))) {
fd = posix_openpt(flags);
} else if (!strncmp(pathname,SAVE_PATH,strlen(SAVE_PATH))) {
fd = open_savefile(pathname, flags & O_WRONLY);
} else if (!strcmp(pathname, "/etc/nsd/nsd.conf")) {
fd = open_compiled_file(CONFIGURATION, sizeof(CONFIGURATION) - 1, flags);
} else if (!strcmp(pathname, "/var/db/nsd/nsd.db")) {
fd = open_compiled_file(__nsd_database, sizeof(__nsd_database) - 1, flags);
} else if (!strcmp(pathname, "/var/run/nsd.pid")) {
errno = ENOENT;
fd = -1;
} else {
errno = EIO;
fd = -1;
}
printk("open(%s, %d) -> %d\n", pathname, flags, fd);
return fd;
}
开发者ID:carriercomm,项目名称:minios-hacks,代码行数:27,代码来源:sys.c
示例10: ATF_TC_BODY
ATF_TC_BODY(posix_openpt_failure, tc)
{
const char *regex = "posix_openpt.*return,failure : Invalid argument";
FILE *pipefd = setup(fds, auclass);
ATF_REQUIRE_EQ(-1, posix_openpt(-1));
check_audit(fds, regex, pipefd);
}
开发者ID:FreeBSDFoundation,项目名称:freebsd,代码行数:7,代码来源:inter-process.c
示例11: pty_open_master
static int
pty_open_master (char *pty_name)
{
char *slave_name;
int pty_master;
#ifdef HAVE_POSIX_OPENPT
pty_master = posix_openpt (O_RDWR);
#elif HAVE_GETPT
/* getpt () is a GNU extension (glibc 2.1.x) */
pty_master = getpt ();
#elif IS_AIX
strcpy (pty_name, "/dev/ptc");
pty_master = open (pty_name, O_RDWR);
#else
strcpy (pty_name, "/dev/ptmx");
pty_master = open (pty_name, O_RDWR);
#endif
if (pty_master == -1)
return -1;
if (grantpt (pty_master) == -1 /* Grant access to slave */
|| unlockpt (pty_master) == -1 /* Clear slave's lock flag */
|| !(slave_name = ptsname (pty_master))) /* Get slave's name */
{
close (pty_master);
return -1;
}
strcpy (pty_name, slave_name);
return pty_master;
}
开发者ID:GalaxyTab4,项目名称:workbench,代码行数:32,代码来源:subshell.c
示例12: test_overlap
/*
* Check that the given PTY index, which is in use for an old-style PTY, is not
* allocated through Unix98 PTY allocation. This test is not foolproof, but it
* does the job well enough.
*/
static void
test_overlap(int m)
{
char *tname;
size_t len;
int i, n, fd[MIN_PTYS];
for (i = 0; i < MIN_PTYS; i++) {
if ((fd[i] = posix_openpt(O_RDWR | O_NOCTTY)) < 0)
break; /* out of PTYs */
if (grantpt(fd[i]) < 0) e(0);
if (unlockpt(fd[i]) < 0) e(0);
if ((tname = ptsname(fd[i])) == NULL) e(0);
len = strlen(_PATH_DEV_PTS);
if (strncmp(tname, _PATH_DEV_PTS, strlen(_PATH_DEV_PTS))) e(0);
n = atoi(&tname[len]);
if (n < 0 || n > 9) e(0);
if (m == n) e(0);
}
for (i--; i >= 0; i--)
if (close(fd[i]) < 0) e(0);
}
开发者ID:newdispatcher,项目名称:minix,代码行数:30,代码来源:test77.c
示例13: get_pty
/* allocate one pty/tty pair (Unix 98 way) */
static int get_pty(char *tty_buf, int tty_buf_size)
{
#ifdef ZIPIT_Z2
return get_pty_old(tty_buf, tty_buf_size);
#else
int fd;
char *str;
fd = posix_openpt(O_RDWR | O_NOCTTY);
if (fd < 0) {
return get_pty_old(tty_buf, tty_buf_size);
}
if (grantpt(fd) < 0)
goto fail;
if (unlockpt(fd) < 0)
goto fail;
str = ptsname(fd);
if (!str)
goto fail;
pstrcpy(tty_buf, tty_buf_size, str);
return fd;
fail:
close(fd);
return -1;
#endif
}
开发者ID:deeice,项目名称:Qemacs,代码行数:27,代码来源:shell.c
示例14: main
int main(void) {
int fdm;
int rc;
// initial
system("ls -l /dev/pts");
fdm = posix_openpt(O_RDWR);
if (fdm < 0) {
perror("posix_openpt");
return 1;
}
rc = grantpt(fdm);
if (rc != 0) {
perror("grantpt");
return 1;
}
rc = unlockpt(fdm);
if (rc != 0) {
perror("unlockpt");
return 1;
}
// final
system("ls -l /dev/pts");
return 0;
}
开发者ID:Acidburn0zzz,项目名称:firejail,代码行数:30,代码来源:ttytest.c
示例15: ptym_open
int
ptym_open(char *pts_name, char *pts_name_s , int pts_namesz)
{
char *ptr;
int fdm;
strncpy(pts_name, "/dev/ptmx", pts_namesz);
pts_name[pts_namesz - 1] = '\0';
fdm = posix_openpt(O_RDWR | O_NONBLOCK);
if (fdm < 0)
return(-1);
if (grantpt(fdm) < 0)
{
close(fdm);
return(-2);
}
if (unlockpt(fdm) < 0)
{
close(fdm);
return(-3);
}
if ((ptr = ptsname(fdm)) == NULL)
{
close(fdm);
return(-4);
}
strncpy(pts_name_s, ptr, pts_namesz);
pts_name[pts_namesz - 1] = '\0';
return(fdm);
}
开发者ID:air-gh,项目名称:oRTP-SBus,代码行数:33,代码来源:ptssend.c
示例16: get_pty
int
get_pty(int *master, int *slave, char *name, size_t namesz, uid_t ttyuid)
{
char *line;
*master = posix_openpt(O_RDWR|O_NOCTTY);
if (*master == -1)
return 0;
(void) grantpt(*master); /* may fork */
if (unlockpt(*master) != 0) {
close(*master);
return 0;
}
line = ptsname(*master);
if (line == NULL) {
close(*master);
return 0;
}
*slave = open(line, O_RDWR|O_NOCTTY, 0);
if (*slave == -1) {
close(*master);
return 0;
}
# if defined(I_PUSH) && !defined(_AIX)
ioctl(*slave, I_PUSH, "ptem"); /* pseudo tty emulation module */
ioctl(*slave, I_PUSH, "ldterm"); /* line discipline module */
# endif
(void) chown(line, ttyuid, -1);
strlcpy(name, line, namesz);
return 1;
}
开发者ID:CVi,项目名称:sudo,代码行数:32,代码来源:get_pty.c
示例17: handle_signals_resets_terminal
void handle_signals_resets_terminal(void)
{
int status, masterfd;
char* slavedevice = NULL;
struct termios test_flags;
pid_t child_pid;
masterfd = posix_openpt(O_RDWR|O_NOCTTY);
if (masterfd == -1
|| grantpt (masterfd) == -1
|| unlockpt (masterfd) == -1
|| (slavedevice = ptsname (masterfd)) == NULL)
CU_FAIL_FATAL("Could not create pty");
terminal_fildes = open(slavedevice, O_RDWR|O_NOCTTY);
tcgetattr(terminal_fildes, &orig_flags);
new_flags = orig_flags;
new_flags.c_lflag &= ~ECHO;
tcsetattr(terminal_fildes, TCSANOW, &new_flags);
terminal_needs_reset = 1;
if((child_pid = fork()) == 0)
{
freerdp_handle_signals();
raise(SIGINT);
}
while(wait(&status) != -1);
tcgetattr(terminal_fildes, &test_flags);
CU_ASSERT_EQUAL(orig_flags.c_lflag, test_flags.c_lflag);
close(masterfd);
close(terminal_fildes);
}
开发者ID:Cyclic,项目名称:FreeRDP,代码行数:33,代码来源:test_utils.c
示例18: open_pty
int open_pty() {
int fd = check("posix_openpt", posix_openpt(O_RDWR | O_NOCTTY));
check("grantpt", grantpt(fd));
check("unlockpt", unlockpt(fd));
return fd;
}
开发者ID:Altonymous,项目名称:drip,代码行数:7,代码来源:drip_proxy.c
示例19: ptym_open
int
ptym_open(char * pts_name)
{
int fdm;
char *ptr;
strcpy(pts_name, "/dev/ptmx");
fdm = posix_openpt(O_RDWR);
if (fdm < 0)
return -1;
if (grantpt(fdm) < 0) { /* grant access to slave */
close(fdm);
return -2;
}
if (unlockpt(fdm) < 0) { /* clear slave's lock flag */
close(fdm);
return -3;
}
ptr = ptsname(fdm);
if (ptr == NULL) { /* get slave's name */
close (fdm);
return -4;
}
strcpy(pts_name, ptr); /* return name of slave */
return fdm; /* return fd of master */
}
开发者ID:BjornArnelid,项目名称:cdt,代码行数:26,代码来源:openpty.c
示例20: pseudoterminal
pseudoterminal(int options): master_fd(posix_openpt(options)) {
if (grantpt(master_fd.getfd()) == -1) {
throw errno_exception("pseudoterminal(), grantpt");
}
if (unlockpt(master_fd.getfd()) == -1) {
throw errno_exception("pseudoterminal(), unlockpt");
}
}
开发者ID:arthur-samarin,项目名称:os,代码行数:8,代码来源:rshd.cpp
注:本文中的posix_openpt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论