#include #include #include int main (int argc, char * * argv) { char * fn = "/dev/clipboard"; int fd = open (fn, O_RDONLY | O_BINARY, 0); if (fd < 0) { exit (fd); } int out_tty = isatty (1); int filebuflen = 100; argc --; if (argc > 0) { int ret = sscanf (argv [1], "%d", & filebuflen); } char * filebuf = malloc (filebuflen + 1); filebuf [filebuflen] = 77; fprintf (stderr, "filebuflen %d (overflow byte %d)\n", filebuflen, filebuf [filebuflen]); int n; do { n = read (fd, filebuf, filebuflen); if (out_tty) { filebuf [n] = 0; printf ("read %d bytes: <%s> (overflow byte %d)\n", n, filebuf, filebuf [filebuflen]); } else { fprintf (stderr, "read %d bytes\n", n); write (1, filebuf, n); } } while (n > 0); close (fd); }