aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/config.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-01-24 04:20:05 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-02-07 12:21:22 +0100
commit7df25293c436beef0b86dd7954ce0ee495c4936b (patch)
tree81cedd892b3b47f95c3cae8c292a2f4009b73daf /src/tools/config.c
parenttools: setconf should remove existing psk (diff)
downloadwireguard-monolithic-historical-7df25293c436beef0b86dd7954ce0ee495c4936b.tar.xz
wireguard-monolithic-historical-7df25293c436beef0b86dd7954ce0ee495c4936b.zip
tools: remove key for any empty file
Rather than just using /dev/null to mean key removal, match on any empty file, so that this interface is cross platform.
Diffstat (limited to 'src/tools/config.c')
-rw-r--r--src/tools/config.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/tools/config.c b/src/tools/config.c
index e6db6ad..da19cc3 100644
--- a/src/tools/config.c
+++ b/src/tools/config.c
@@ -390,7 +390,6 @@ static int read_line(char **dst, const char *path)
{
FILE *f;
size_t n = 0;
- struct stat stat;
*dst = NULL;
@@ -399,22 +398,15 @@ static int read_line(char **dst, const char *path)
perror("fopen");
return -1;
}
- if (fstat(fileno(f), &stat) < 0) {
- perror("fstat");
- fclose(f);
- return -1;
- }
- if (S_ISCHR(stat.st_mode) && stat.st_rdev == makedev(1, 3)) {
- fclose(f);
- return 1;
- }
- if (getline(dst, &n, f) < 0) {
+ if (getline(dst, &n, f) < 0 && errno) {
perror("getline");
fclose(f);
return -1;
}
fclose(f);
n = strlen(*dst);
+ if (!n)
+ return 1;
while (--n) {
if (isspace((*dst)[n]))
(*dst)[n] = '\0';