#include <sys/ioctl.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
ps_root_dowritepathuint(const void *data, size_t len)
{
const char *path = data;
- FILE *fp;
- ssize_t r;
size_t plen;
unsigned int val;
+ int fd;
+ ssize_t r;
if (len < sizeof(plen)) {
errno = EINVAL;
memcpy(&val, path + plen, sizeof(val));
- fp = fopen(path, "w");
- if (fp == NULL)
+ fd = open(path, O_WRONLY);
+ if (fd == -1)
return -1;
- r = fprintf(fp, "%u\n", val);
- fclose(fp);
+ r = dprintf(fd, "%u", val);
+ close(fd);
+
return r;
}
ps_root_writepathuint(struct dhcpcd_ctx *ctx, const char *path,
unsigned int val)
{
- char buf[PS_BUFLEN];
+ char buf[PS_BUFLEN], *p = buf;
size_t plen = strlen(path) + 1;
size_t len = sizeof(plen) + plen + sizeof(val);
return -1;
}
- memcpy(buf, &plen, sizeof(plen));
- memcpy(buf + sizeof(plen), path, plen);
- memcpy(buf + sizeof(plen) + plen, &val, sizeof(val));
+ memcpy(p, &plen, sizeof(plen));
+ p += sizeof(plen);
+ memcpy(p, path, plen);
+ p += plen;
+ memcpy(p, &val, sizeof(val));
return ps_sendcmd(ctx, ctx->ps_root_fd, PS_WRITEPATHUINT, 0, buf, len);
}