pkg_create incorrectly does not add trailing '\n' when it receives

either COMMENT or DESCR from the command line. When a port is
installed, one gets both +COMMENT and +DESCR files with a trailing
'\n' character. However, +COMMENT does not contain a trailing '\n'
when it is installed from a package due to this behavior of pkg_create.

 Therefore, make sure it behaves exactly the same regardless of
where got its information; either command line or files. The modified
functions are used by pkg_create.

PR:		52097
Reviewed by:	bento, kris,
		portmgr, re,
		Michael Nottebrock <michaelnottebrock@gmx.net>,
		Martin Horcicka <horcicka@FreeBSD.cz>
Approved by:	re (scottl)
MFC after:	1 week
This commit is contained in:
Mario Sergio Fujikawa Ferreira 2003-05-26 17:12:22 +00:00
parent c32acd2e5c
commit fc12c41ca3
2 changed files with 23 additions and 1 deletions

View file

@ -147,6 +147,7 @@ off_t min_free(const char *);
/* String */
char *get_dash_string(char **);
char *copy_string(const char *);
char *copy_string_adds_newline(const char *);
Boolean suffix(const char *, const char *);
void nuke_suffix(char *);
void str_lowercase(char *);

View file

@ -42,7 +42,7 @@ get_dash_string(char **str)
char *s = *str;
if (*s == '-')
*str = copy_string(s + 1);
*str = copy_string_adds_newline(s + 1);
else
*str = fileGetContents(s);
return *str;
@ -55,6 +55,27 @@ copy_string(const char *str)
return (str ? strdup(str) : NULL);
}
/* Rather Obvious but adds a trailing \n newline */
char *
copy_string_adds_newline(const char *str)
{
if (str == NULL) {
return (NULL);
} else {
char *copy;
size_t line_length;
line_length = strlen(str) + 2;
if ((copy = malloc(line_length)) == NULL)
return (NULL);
memcpy(copy, str, line_length - 2);
copy[line_length - 2] = '\n'; /* Adds trailing \n */
copy[line_length - 1] = '\0';
return (copy);
}
}
/* Return TRUE if 'str' ends in suffix 'suff' */
Boolean
suffix(const char *str, const char *suff)