I am trying to work with the selection buffer of the terminal from my ncurses application. I want to be able to copy some text into the buffer. From what I've been able to find, it looks like I need to use 'ioctl'. So that's what I do (code to follow), and it looks like it does work in TTYs, at least to some extent. However, it does not work in any of the X terminals (mrxvt, urxvt, xterm etc.). Can anyone please tell me what I am missing?
int fd = 1; /* XXX: Perhaps I need to open(terminal, O_WRONLY)? * In which case, what's "terminal"? */
if (ioctl(fd, TIOCLINUX, buf+sizeof(short)-1) < 0) { printf("can't ioctl\n"); switch (errno) { case EBADF: printf("invalid file desc\n"); break;
case EFAULT: printf("argp\n"); break; case EINVAL: printf("invalid argp\n"); break; case ENOTTY: printf("invalid tty\n");
break; default: printf("unknown: %d\n", errno); break; } } close(fd);
return 0; }
/* END CODE */
The error I get from X terminals is "invalid argp".
I am using 1 as the file-descriptor argument to ioctl. Should I use something else? Is there any way I can find out the file descriptor for the current terminal from my application?
Or better yet, is there a better way of doing what I want to do?