lnstat_util: Simplify alloc_and_open() a bit

Relying upon callers and using unsafe strcpy() is probably not the best
idea. Aside from that, using snprintf() allows to format the string for
lf->path in one go.

Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
Phil Sutter 2017-08-24 11:51:48 +02:00 committed by Stephen Hemminger
parent cfda500a7d
commit bc27878d21
1 changed files with 2 additions and 5 deletions

View File

@ -180,11 +180,8 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file)
}
/* initialize */
/* de->d_name is guaranteed to be <= NAME_MAX */
strcpy(lf->basename, file);
strcpy(lf->path, path);
strcat(lf->path, "/");
strcat(lf->path, lf->basename);
snprintf(lf->basename, sizeof(lf->basename), "%s", file);
snprintf(lf->path, sizeof(lf->path), "%s/%s", path, file);
/* initialize to default */
lf->interval.tv_sec = 1;