blob: 9c9f564af7157c62fe6177654a4617c4af9acf98 [file] [log] [blame]
Pengfei Liub4734232020-01-17 18:25:10 +08001#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
11int 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}