Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <string.h> |
| 7 | #include <errno.h> |
| 8 | #include <dvr_types.h> |
| 9 | #include <dvr_utils.h> |
| 10 | |
| 11 | int DVR_FileEcho(const char *name, const char *cmd) |
| 12 | { |
| 13 | int fd, len, ret; |
| 14 | |
| 15 | fd = open(name, O_WRONLY); |
| 16 | if (fd == -1) |
| 17 | { |
| 18 | DVR_DEBUG(1, "cannot open file \"%s\"", name); |
| 19 | return DVR_FAILURE; |
| 20 | } |
| 21 | |
| 22 | len = strlen(cmd); |
| 23 | ret = write(fd, cmd, len); |
| 24 | if (ret != len) |
| 25 | { |
| 26 | DVR_DEBUG(1, "write failed file:\"%s\" cmd:\"%s\" error:\"%s\"", name, cmd, strerror(errno)); |
| 27 | close(fd); |
| 28 | return DVR_FAILURE; |
| 29 | } |
| 30 | close(fd); |
| 31 | |
| 32 | return DVR_SUCCESS; |
| 33 | } |