summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAlex Richardson <arichardson@FreeBSD.org>2020-01-16 14:15:00 +0000
committerAlex Richardson <arichardson@FreeBSD.org>2020-01-16 14:15:00 +0000
commita33ee411d9878bc4553ee87a1ecc7fc6c55e6e14 (patch)
treee7533642c67ecd0a52c57285d5a83a5dd7d11e70 /bin
parenta9638453049babcd185f730126f50d4598dc7b16 (diff)
downloadsrc-test-a33ee411d9878bc4553ee87a1ecc7fc6c55e6e14.tar.gz
src-test-a33ee411d9878bc4553ee87a1ecc7fc6c55e6e14.zip
Allow building bin/cat on non-FreeBSD systems
`cat -l` is needed during the installworld phase and other system's cat don't support that flag. To avoid portability issues when compiling on Linux/macOS (such as the the direct access to &fp->_mbstate), we disable the entire multibyte support when building as a boostrap tool. Reviewed By: brooks, emaste Differential Revision: https://reviews.freebsd.org/D13939
Notes
Notes: svn path=/head/; revision=356791
Diffstat (limited to 'bin')
-rw-r--r--bin/cat/Makefile6
-rw-r--r--bin/cat/cat.c22
2 files changed, 26 insertions, 2 deletions
diff --git a/bin/cat/Makefile b/bin/cat/Makefile
index 8d0a6e20c3491..cba55d2870bba 100644
--- a/bin/cat/Makefile
+++ b/bin/cat/Makefile
@@ -6,6 +6,12 @@
PACKAGE=runtime
PROG= cat
+.ifdef BOOTSTRAPPING
+# For the bootstrap cat we disable all wide char support to allow building
+# on Linux/macOS
+CFLAGS+=-DBOOTSTRAP_CAT
+.endif
+
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
diff --git a/bin/cat/cat.c b/bin/cat/cat.c
index 817ab6df8707f..7668673f5e89c 100644
--- a/bin/cat/cat.c
+++ b/bin/cat/cat.c
@@ -96,6 +96,20 @@ static int udom_open(const char *path, int flags);
*/
#define BUFSIZE_SMALL (MAXPHYS)
+
+/*
+ * For the bootstrapped cat binary (needed for locked appending to METALOG), we
+ * disable all flags except -l and -u to avoid non-portable function calls.
+ * In the future we may instead want to write a small portable bootstrap tool
+ * that locks the output file before writing to it. However, for now
+ * bootstrapping cat without multibyte support is the simpler solution.
+ */
+#ifdef BOOTSTRAP_CAT
+#define SUPPORTED_FLAGS "lu"
+#else
+#define SUPPORTED_FLAGS "belnstuv"
+#endif
+
int
main(int argc, char *argv[])
{
@@ -104,7 +118,7 @@ main(int argc, char *argv[])
setlocale(LC_CTYPE, "");
- while ((ch = getopt(argc, argv, "belnstuv")) != -1)
+ while ((ch = getopt(argc, argv, SUPPORTED_FLAGS)) != -1)
switch (ch) {
case 'b':
bflag = nflag = 1; /* -b implies -n */
@@ -158,7 +172,7 @@ static void
usage(void)
{
- fprintf(stderr, "usage: cat [-belnstuv] [file ...]\n");
+ fprintf(stderr, "usage: cat [-" SUPPORTED_FLAGS "] [file ...]\n");
exit(1);
/* NOTREACHED */
}
@@ -187,6 +201,7 @@ scanfiles(char *argv[], int cooked)
if (fd < 0) {
warn("%s", path);
rval = 1;
+#ifndef BOOTSTRAP_CAT
} else if (cooked) {
if (fd == STDIN_FILENO)
cook_cat(stdin);
@@ -195,6 +210,7 @@ scanfiles(char *argv[], int cooked)
cook_cat(fp);
fclose(fp);
}
+#endif
} else {
raw_cat(fd);
if (fd != STDIN_FILENO)
@@ -206,6 +222,7 @@ scanfiles(char *argv[], int cooked)
}
}
+#ifndef BOOTSTRAP_CAT
static void
cook_cat(FILE *fp)
{
@@ -295,6 +312,7 @@ ilseq:
if (ferror(stdout))
err(1, "stdout");
}
+#endif /* BOOTSTRAP_CAT */
static void
raw_cat(int rfd)