summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2007-05-11 11:10:05 +0000
committerdes <des@FreeBSD.org>2007-05-11 11:10:05 +0000
commit719c87d1eefd84c258ae95fba843c7e46fe3ee9d (patch)
treec33f7f2829f8fb3b136afadaae5ac2a95f8707d9
parent185e8c88671208f81abcb7085173092a641a0175 (diff)
downloadFreeBSD-src-719c87d1eefd84c258ae95fba843c7e46fe3ee9d.zip
FreeBSD-src-719c87d1eefd84c258ae95fba843c7e46fe3ee9d.tar.gz
strlcpy() may be faster than snprintf(), but it is less portable, and this
is not performance critical code anyway. Also, avoid using strlen() to obtain information which we already have. MFC after: 3 weeks
-rw-r--r--lib/libutil/pidfile.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c
index e002d65..983d103 100644
--- a/lib/libutil/pidfile.c
+++ b/lib/libutil/pidfile.c
@@ -88,19 +88,19 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
{
struct pidfh *pfh;
struct stat sb;
- int error, fd;
+ int error, fd, len;
pfh = malloc(sizeof(*pfh));
if (pfh == NULL)
return (NULL);
- if (path == NULL) {
- snprintf(pfh->pf_path, sizeof(pfh->pf_path), "/var/run/%s.pid",
- getprogname());
- } else {
- strlcpy(pfh->pf_path, path, sizeof(pfh->pf_path));
- }
- if (strlen(pfh->pf_path) == sizeof(pfh->pf_path) - 1) {
+ if (path == NULL)
+ len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
+ "/var/run/%s.pid", getprogname());
+ else
+ len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
+ "%s", path);
+ if (len >= (int)sizeof(pfh->pf_path)) {
free(pfh);
errno = ENAMETOOLONG;
return (NULL);
OpenPOWER on IntegriCloud