--- drivers/char/console.c.ori Tue Jun 12 15:17:17 2001 +++ drivers/char/console.c Thu Jul 26 17:33:46 2001 @@ -14,6 +14,8 @@ * * Copy and paste function by Andrew Haylett, * some enhancements by Alessandro Rubini. + * get selection into a buffer and length by + * Salvador E. Tropea * * Code to check for different video-cards mostly by Galen Hunt, * @@ -2204,6 +2206,10 @@ return 0; case 12: /* get fg_console */ return fg_console; + case 13: /* get selection into a buffer */ + return get_selection_buffer(arg); + case 14: /* get selection length */ + return put_user(get_selection_length(), (unsigned int *)((char *)arg + 1)); } return -EINVAL; } --- drivers/char/selection.c.ori Fri Feb 9 16:30:22 2001 +++ drivers/char/selection.c Thu Jul 26 17:53:46 2001 @@ -288,6 +288,41 @@ return 0; } +/* Copy the contents of the selection buffer into a + * user space buffer. + * Invoked by ioctl(). + */ +int get_selection_buffer(const unsigned long arg) +{ + char *dest; + unsigned int length; + + if (get_user(length, (unsigned int *)(arg + sizeof(char)))) + return -EFAULT; + + dest = (char *)(arg + sizeof(char) + sizeof(unsigned int)); + + if (length > sel_buffer_lth) + length = sel_buffer_lth; + + if (sel_buffer) { + if (copy_to_user(dest, sel_buffer, length)) + return -EFAULT; + } else { + length = 0; + } + __put_user(length, (unsigned long *)(arg + sizeof(char))); + return 0; +} + +/* Get the selection buffer length. + * Invoked by ioctl(). + */ +unsigned int get_selection_length(void) +{ + return sel_buffer ? sel_buffer_lth : 0; +} + /* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl(). --- include/linux/selection.h.ori Fri Jul 20 16:53:56 2001 +++ include/linux/selection.h Thu Jul 26 17:40:07 2001 @@ -17,6 +17,8 @@ extern int sel_loadlut(const unsigned long arg); extern int mouse_reporting(void); extern void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry); +extern int get_selection_buffer(const unsigned long arg); +extern unsigned int get_selection_length(void); #define video_num_columns (vc_cons[currcons].d->vc_cols) #define video_num_lines (vc_cons[currcons].d->vc_rows)