/* readmouse.c */ #include #include #include #include #include #include int main(void) { unsigned char buf[64]; int fd, nread; fd = open("/dev/psaux", O_RDONLY,0); if (fd < 0) { printf("can't open file /dev/psaux\n"); return 1; } nread=0; do { nread += read(fd, buf+nread, 1); printf("0x%x ",buf[nread-1]); fflush(stdout); } while (nread < 20); printf("\n"); close(fd); return 0; } ========================================================================================= /* copyfile.c */ #include #include #include #include #include #include int main(int argc, char **argv) { unsigned char buf[4096]; int fd1, fd2, nread; if (argc != 3) { printf("wrong number of parameters\n"); return -1; } else { fd1 = open(argv[1], O_RDONLY); if (fd1 < 0) { printf("can't find file: %s\n", argv[1]); return 1; } fd2 = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600); if (fd2 < 0) { printf("can't open file: %s\n", argv[2]); return 1; } do { nread = read(fd1, buf, 4096); write(fd2, buf, nread); } while (nread); close(fd1); close(fd2); return 0; } }