blob: 91e495c3fc8bd742f9f867c66a734757fa75a565 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001#include <stdio.h>
Doug Kwane49f9c92009-03-26 14:14:15 -07002#include <stdlib.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08003#include <string.h>
4#include <fcntl.h>
5#include <errno.h>
6
7int 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}