The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
Doug Kwan | e49f9c9 | 2009-03-26 14:14:15 -0700 | [diff] [blame] | 2 | #include <stdlib.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 3 | #include <string.h> |
| 4 | #include <fcntl.h> |
| 5 | #include <errno.h> |
| 6 | |
| 7 | int smd_main(int argc, char **argv) |
| 8 | { |
| 9 | int fd, len, r, port = 0; |
| 10 | char devname[32]; |
| 11 | argc--; |
| 12 | argv++; |
| 13 | |
| 14 | if((argc > 0) && (argv[0][0] == '-')) { |
| 15 | port = atoi(argv[0] + 1); |
| 16 | argc--; |
| 17 | argv++; |
| 18 | } |
| 19 | |
| 20 | sprintf(devname,"/dev/smd%d",port); |
| 21 | fd = open(devname, O_WRONLY); |
| 22 | if(fd < 0) { |
| 23 | fprintf(stderr,"failed to open smd0 - %s\n", |
| 24 | strerror(errno)); |
| 25 | return -1; |
| 26 | } |
| 27 | while(argc > 0) { |
| 28 | len = strlen(argv[0]); |
| 29 | r = write(fd, argv[0], len); |
| 30 | if(r != len) { |
| 31 | fprintf(stderr,"failed to write smd0 (%d) %s\n", |
| 32 | r, strerror(errno)); |
| 33 | return -1; |
| 34 | } |
| 35 | argc--; |
| 36 | argv++; |
| 37 | write(fd, argc ? " " : "\r", 1); |
| 38 | } |
| 39 | close(fd); |
| 40 | return 0; |
| 41 | } |