file: create a file on write if it does not exist
Signed-off-by: Luka Perkov <luka@openwrt.org>
This commit is contained in:
parent
ec21f653b9
commit
11f5072bb1
1 changed files with 5 additions and 7 deletions
12
file.c
12
file.c
|
@ -203,17 +203,15 @@ rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct blob_attr *msg)
|
struct blob_attr *msg)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char *path;
|
struct blob_attr *tb[__RPC_F_MAX];
|
||||||
struct stat s;
|
|
||||||
struct blob_attr **tb;
|
|
||||||
|
|
||||||
if (!(tb = rpc_check_path(msg, &path, &s)))
|
blobmsg_parse(rpc_file_policy, __RPC_F_MAX, tb,
|
||||||
return rpc_errno_status();
|
blob_data(msg), blob_len(msg));
|
||||||
|
|
||||||
if (!tb[RPC_F_DATA])
|
if (!tb[RPC_F_PATH] || !tb[RPC_F_DATA])
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
|
|
||||||
if ((fd = open(path, O_WRONLY)) < 0)
|
if ((fd = open(blobmsg_data(tb[RPC_F_PATH]), O_CREAT | O_TRUNC | O_WRONLY)) < 0)
|
||||||
return rpc_errno_status();
|
return rpc_errno_status();
|
||||||
|
|
||||||
write(fd, blobmsg_data(tb[RPC_F_DATA]), blobmsg_data_len(tb[RPC_F_DATA]));
|
write(fd, blobmsg_data(tb[RPC_F_DATA]), blobmsg_data_len(tb[RPC_F_DATA]));
|
||||||
|
|
Loading…
Reference in a new issue