removed a bunch of unnecesary strncpy()'s and replaced with strcat()

This commit is contained in:
Todd C. Miller
1995-07-30 18:38:19 +00:00
parent 8e3717b14b
commit b42c06bb1f

View File

@@ -322,6 +322,7 @@ void log_error(code)
strcat(logline, cmnd); /* stuff the command into the logline */ strcat(logline, cmnd); /* stuff the command into the logline */
strcat(logline, " "); strcat(logline, " ");
/* XXX - clean up this abonimation and just set count sanely */
if (Argc > 1) { if (Argc > 1) {
argc = Argc - 2; argc = Argc - 2;
argv = Argv + 1; argv = Argv + 1;
@@ -330,22 +331,14 @@ void log_error(code)
argv = Argv; argv = Argv;
} }
p = logline + strlen(logline);
count = (int) (logline + MAXLOGLEN - p);
/* /*
* Now stuff as much of the rest of the line as will fit * We have defined MAXLOGLEN to be bigger than argv[] can be
* Do word wrap if logging to a file. * so do not need to do bounds checking.
*/ */
while (count > 0 && argc--) { for (count = 0; count < argc; count++) {
strncpy(p, *(++argv), count); strcat(logline, argv[count]);
strcat(p, " "); strcat(logline, " ");
p += 1 + (count < strlen(*argv) ? count : strlen(*argv));
count = (int) (logline + MAXLOGLEN - p);
} }
if (count <= 0) /* if the line is too long, */
strcat(p, " ... "); /* add an elipsis to the end */
} }
#if (LOGGING & SLOG_SYSLOG) #if (LOGGING & SLOG_SYSLOG)
@@ -359,11 +352,12 @@ void log_error(code)
* Log the full line, breaking into multiple syslog(3) calls if necesary * Log the full line, breaking into multiple syslog(3) calls if necesary
*/ */
p = &logline[33]; /* skip past the date and user */ p = &logline[33]; /* skip past the date and user */
for (count=0; count < (strlen(logline) / MAXSYSLOGLEN) + 1; count++) { for (count = 0; count < strlen(logline) / MAXSYSLOGLEN + 1; count++) {
if (strlen(p) > MAXSYSLOGLEN) { if (strlen(p) > MAXSYSLOGLEN) {
/* /*
* Break up the line into what will fit on one syslog(3) line * Break up the line into what will fit on one syslog(3) line
* Try to break on a word boundary if possible. * Try to break on a word boundary if possible.
* XXX - speed this up!
*/ */
for (tmp = p + MAXSYSLOGLEN; tmp > p && *tmp != ' '; tmp--) for (tmp = p + MAXSYSLOGLEN; tmp > p && *tmp != ' '; tmp--)
; ;