mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Replace snprintf() with xstrlcpy()
This commit is contained in:
parent
a40d29ba9f
commit
e6580c38bf
14
nnn.c
14
nnn.c
|
@ -342,8 +342,7 @@ crc8fast(uchar const message[], size_t n)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The final remainder is the CRC */
|
/* The final remainder is the CRC */
|
||||||
return (remainder);
|
return remainder;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Messages show up at the bottom */
|
/* Messages show up at the bottom */
|
||||||
|
@ -1230,23 +1229,26 @@ readinput(void)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Updates out with "dir/name or "/name"
|
* 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
|
size_t
|
||||||
mkpath(char *dir, char *name, char *out, size_t n)
|
mkpath(char *dir, char *name, char *out, size_t n)
|
||||||
{
|
{
|
||||||
|
static size_t len;
|
||||||
|
|
||||||
/* Handle absolute path */
|
/* Handle absolute path */
|
||||||
if (name[0] == '/')
|
if (name[0] == '/')
|
||||||
return xstrlcpy(out, name, n);
|
return xstrlcpy(out, name, n);
|
||||||
else {
|
else {
|
||||||
/* Handle root case */
|
/* Handle root case */
|
||||||
if (istopdir(dir))
|
if (istopdir(dir))
|
||||||
return (snprintf(out, n, "/%s", name) + 1);
|
len = 1;
|
||||||
else
|
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
|
static void
|
||||||
|
|
Loading…
Reference in a new issue