summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr/common_source/common.c
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2001-07-15 00:57:18 +0000
committergad <gad@FreeBSD.org>2001-07-15 00:57:18 +0000
commita76650f907e7aac1ed9e37f599a75de0160b55e3 (patch)
tree11cdd2e087078213c8cf31addfce31b3ffbb5026 /usr.sbin/lpr/common_source/common.c
parent75f5203b04d78ac555161bc219da58cbfeffefbd (diff)
downloadFreeBSD-src-a76650f907e7aac1ed9e37f599a75de0160b55e3.zip
FreeBSD-src-a76650f907e7aac1ed9e37f599a75de0160b55e3.tar.gz
Replace three subtly-wrong calls to strncpy with calls to strlcpy, and
use (size_t) in a few places to avoid compile-time warnings on alpha. MFC after: 1 week
Diffstat (limited to 'usr.sbin/lpr/common_source/common.c')
-rw-r--r--usr.sbin/lpr/common_source/common.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c
index 8c434b0..81b35ca 100644
--- a/usr.sbin/lpr/common_source/common.c
+++ b/usr.sbin/lpr/common_source/common.c
@@ -225,12 +225,11 @@ lock_file_name(const struct printer *pp, char *buf, size_t len)
if (len == 0)
len = MAXPATHLEN;
- if (pp->lock_file[0] == '/') {
- buf[0] = '\0';
- strncpy(buf, pp->lock_file, len);
- } else {
+ if (pp->lock_file[0] == '/')
+ strlcpy(buf, pp->lock_file, len);
+ else
snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file);
- }
+
return buf;
}
@@ -244,18 +243,17 @@ status_file_name(const struct printer *pp, char *buf, size_t len)
if (len == 0)
len = MAXPATHLEN;
- if (pp->status_file[0] == '/') {
- buf[0] = '\0';
- strncpy(buf, pp->status_file, len);
- } else {
+ if (pp->status_file[0] == '/')
+ strlcpy(buf, pp->status_file, len);
+ else
snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file);
- }
+
return buf;
}
/* routine to get a current timestamp, optionally in a standard-fmt string */
void
-lpd_gettime(struct timespec *tsp, char *strp, int strsize)
+lpd_gettime(struct timespec *tsp, char *strp, size_t strsize)
{
struct timespec local_ts;
struct timeval btime;
@@ -312,7 +310,7 @@ lpd_gettime(struct timespec *tsp, char *strp, int strsize)
strsize = TIMESTR_SIZE;
strp[TIMESTR_SIZE+1] = '\0';
}
- strncpy(strp, tempstr, strsize);
+ strlcpy(strp, tempstr, strsize);
}
/* routines for writing transfer-statistic records */
@@ -346,7 +344,7 @@ trstat_init(struct printer *pp, const char *fname, int filenum)
/* get the starting time in both numeric and string formats, and
* save those away along with the file-number */
pp->jobdfnum = filenum;
- lpd_gettime(&pp->tr_start, pp->tr_timestr, TIMESTR_SIZE);
+ lpd_gettime(&pp->tr_start, pp->tr_timestr, (size_t)TIMESTR_SIZE);
return;
}
@@ -367,7 +365,7 @@ trstat_write(struct printer *pp, tr_sendrecv sendrecv, size_t bytecnt,
remspace = eostat - xStr; \
} while(0)
- lpd_gettime(&pp->tr_done, NULL, 0);
+ lpd_gettime(&pp->tr_done, NULL, (size_t)0);
trtime = DIFFTIME_TS(pp->tr_done, pp->tr_start);
gethostname(thishost, sizeof(thishost));
OpenPOWER on IntegriCloud