commit e6580c38bf2a87b47e3c41dcbd9e150e53a85629
parent a40d29ba9f5673523dfdf28e17d448a3cb8da1f8
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Sun, 14 Jan 2018 03:27:24 +0530
Replace snprintf() with xstrlcpy()
Diffstat:
| M | nnn.c | | | 14 | ++++++++------ |
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/nnn.c b/nnn.c
@@ -342,8 +342,7 @@ crc8fast(uchar const message[], size_t n)
}
/* The final remainder is the CRC */
- return (remainder);
-
+ return remainder;
}
/* Messages show up at the bottom */
@@ -1230,23 +1229,26 @@ readinput(void)
/*
* Updates out with "dir/name or "/name"
- * Returns the number of bytes in out including the terminating NULL byte
+ * Returns the number of bytes copied including the terminating NULL byte
*/
size_t
mkpath(char *dir, char *name, char *out, size_t n)
{
+ static size_t len;
+
/* Handle absolute path */
if (name[0] == '/')
return xstrlcpy(out, name, n);
else {
/* Handle root case */
if (istopdir(dir))
- return (snprintf(out, n, "/%s", name) + 1);
+ len = 1;
else
- return (snprintf(out, n, "%s/%s", dir, name) + 1);
+ len = xstrlcpy(out, dir, n);
}
- return 0;
+ out[len - 1] = '/';
+ return (xstrlcpy(out + len, name, n - len) + len);
}
static void