summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install
diff options
context:
space:
mode:
authorlioux <lioux@FreeBSD.org>2003-05-26 17:06:05 +0000
committerlioux <lioux@FreeBSD.org>2003-05-26 17:06:05 +0000
commit477bf2ab2318375737a5d705511ae342c3c54c18 (patch)
tree1438546aa4d23af89d8aceabb08d1cec7040f800 /usr.sbin/pkg_install
parent1042f1605f3a4670cb00adea0745ae4f7a0e2479 (diff)
downloadFreeBSD-src-477bf2ab2318375737a5d705511ae342c3c54c18.zip
FreeBSD-src-477bf2ab2318375737a5d705511ae342c3c54c18.tar.gz
Add a trailing '\n' character if none is found in the information
obtained from a package. Patch show_file() [1] and show_index() [2] functions. PR: 52097 Reviewed by: bento, kris, portmgr, re, Michael Nottebrock <michaelnottebrock@gmx.net>, Martin Horcicka <horcicka@FreeBSD.cz> Approved by: re (scottl) Obtained from: NetBSD [1], OpenBSD [2] MFC after: 1 week
Diffstat (limited to 'usr.sbin/pkg_install')
-rw-r--r--usr.sbin/pkg_install/info/show.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c
index 205f865..10f846a 100644
--- a/usr.sbin/pkg_install/info/show.c
+++ b/usr.sbin/pkg_install/info/show.c
@@ -39,12 +39,16 @@ show_file(const char *title, const char *fname)
if (!Quiet)
printf("%s%s", InfoPrefix, title);
fp = fopen(fname, "r");
- if (!fp)
+ if (fp == (FILE *) NULL)
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
else {
+ int append_nl = 0;
while ((n = fread(line, 1, 1024, fp)) != 0)
fwrite(line, 1, n, stdout);
fclose(fp);
+ append_nl = (line[n - 1] != '\n'); /* Do we have a trailing \n ? */
+ if (append_nl)
+ printf("\n");
}
printf("\n"); /* just in case */
}
@@ -55,20 +59,25 @@ show_index(const char *title, const char *fname)
FILE *fp;
char line[MAXINDEXSIZE+2];
+ strlcpy(line, "???\n", sizeof(line));
+
if (!Quiet)
printf("%s%s", InfoPrefix, title);
fp = fopen(fname, "r");
- if (!fp) {
+ if (fp == (FILE *) NULL) {
warnx("show_file: can't open '%s' for reading", fname);
- return;
- }
- if(fgets(line, MAXINDEXSIZE+1, fp)) {
- if(line[MAXINDEXSIZE-1] != '\n')
- line[MAXINDEXSIZE] = '\n';
- line[MAXINDEXSIZE+1] = 0;
- fputs(line, stdout);
+ } else {
+ if(fgets(line, MAXINDEXSIZE + 1, fp)) {
+ size_t line_length = strlen(line);
+
+ if (line[line_length - 1] != '\n') { /* Do we have a trailing \n ? */
+ line[line_length] = '\n'; /* Add a trailing \n */
+ line[line_length + 1] = '\0'; /* Terminate string */
+ }
+ }
+ fclose(fp);
}
- fclose(fp);
+ fputs(line, stdout);
}
/* Show a packing list item type. If showall is TRUE, show all */
OpenPOWER on IntegriCloud