summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2022-12-28 16:41:09 +0100
committerAndrej Shadura <andrewsh@debian.org>2022-12-28 16:41:09 +0100
commit29e68bb395fd82746f8514a8e44eb9d31127e112 (patch)
treed9da7a5364259dccc652e98c83a264793abbb246
parent08e18503a1fc610c96f748e6616c51003cd047de (diff)
parent0804b2b54999273382b4d30c09128b97e675b215 (diff)
Update upstream source from tag 'upstream/0.37.0'
Update to upstream version '0.37.0' with Debian dir 1b6c755ce1774bd676efe37501c65d59c032e8e7
-rw-r--r--Makefile.inc2
-rw-r--r--doc/NEWS40
-rw-r--r--doc/TODO117
-rw-r--r--examples.mk3
-rw-r--r--examples/compatlib/test.mk8
-rw-r--r--examples/dictd/libmaa/export.sym5
-rw-r--r--examples/efun/expect.out3
-rw-r--r--examples/efun/prog.c16
-rw-r--r--examples/fgetln/test.mk4
-rw-r--r--examples/progs/test.mk2
-rw-r--r--examples/reallocarr/Makefile11
-rw-r--r--examples/reallocarr/expect.out2
-rw-r--r--examples/reallocarr/prog.c27
-rw-r--r--examples/reallocarr/test.mk6
-rw-r--r--examples/shquote/prog.c2
-rw-r--r--examples/strtoi/Makefile11
-rw-r--r--examples/strtoi/expect.out16
-rw-r--r--examples/strtoi/input.in8
-rw-r--r--examples/strtoi/prog.c71
-rw-r--r--examples/strtoi/test.mk6
-rw-r--r--features/Makefile27
-rw-r--r--features/efun/mkc_efun.c7
-rw-r--r--features/errc/mkc_errc.c4
-rw-r--r--features/errc/mkc_verrc.c3
-rw-r--r--features/macro/mkc_attribute_aligned.c1
-rw-r--r--features/macro/mkc_attribute_always_inline.c11
-rw-r--r--features/macro/mkc_attribute_const.c6
-rw-r--r--features/macro/mkc_attribute_noreturn.c8
-rw-r--r--features/macro/mkc_attribute_printflike.c5
-rw-r--r--features/macro/mkc_attribute_pure.c6
-rw-r--r--features/mkc_efun.h6
-rw-r--r--features/mkc_err.h10
-rw-r--r--features/mkc_errc.h6
-rw-r--r--features/mkc_imp.f_efun.mk5
-rw-r--r--features/mkc_imp.f_err.mk3
-rw-r--r--features/mkc_imp.f_errc.mk3
-rw-r--r--features/mkc_imp.f_humanize_number.mk1
-rw-r--r--features/mkc_imp.f_macro.mk18
-rw-r--r--features/mkc_imp.f_reallocarr.mk19
-rw-r--r--features/mkc_imp.f_shquote.mk2
-rw-r--r--features/mkc_imp.f_strtoi.mk19
-rw-r--r--features/mkc_imp.f_strtou.mk19
-rw-r--r--features/mkc_imp.f_warn.mk3
-rw-r--r--features/mkc_macro.h80
-rw-r--r--features/mkc_reallocarr.h46
-rw-r--r--features/mkc_shquote.h6
-rw-r--r--features/mkc_strtoi.h43
-rw-r--r--features/mkc_strtou.h43
-rw-r--r--features/mkc_warn.h10
-rw-r--r--features/reallocarr/mkc_reallocarr.c102
-rw-r--r--features/strto/mkc__strtoi.h146
-rw-r--r--features/strto/mkc_strtoi.c75
-rw-r--r--features/strto/mkc_strtou.c75
-rw-r--r--mk/mkc_imp.compiler_settings.mk2
-rw-r--r--mk/mkc_imp.compiler_type.mk1
-rw-r--r--mk/mkc_imp.final.mk14
-rw-r--r--mk/mkc_imp.foreign_autotools.mk2
-rw-r--r--mk/mkc_imp.mk1
-rw-r--r--mk/mkc_imp.pkg-config.mk5
-rw-r--r--mk/mkc_imp.platform.sys.mk30
-rw-r--r--scripts/mk-configure.7.in88
-rwxr-xr-xscripts/mkc_check_custom.in1
-rwxr-xr-xscripts/mkc_check_version.in1
-rw-r--r--scripts/mkc_compiler_settings.in1
-rwxr-xr-xscripts/mkc_get_deps.in1
-rwxr-xr-xscripts/mkc_install.in2
-rw-r--r--tests/mkc_features/features.mk3
-rw-r--r--tests/mkc_features/tool/test_features1.cxx25
68 files changed, 1220 insertions, 135 deletions
diff --git a/Makefile.inc b/Makefile.inc
index 7566b4a..eae6ea2 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -1,4 +1,4 @@
-VERSION = 0.36.0
+VERSION = 0.37.0
BIRTHDATE = 2009-02-21
diff --git a/doc/NEWS b/doc/NEWS
index 73dcb3a..29281cd 100644
--- a/doc/NEWS
+++ b/doc/NEWS
@@ -1,4 +1,44 @@
======================================================================
+Version 0.37.0, by Aleksey Cheusov, Thu, 8 Apr 2021 09:07:48 +0300
+
+ Features:
+ * new feature "strtoi" for NetBSD function with the same name
+ * new feature "strtou" for NetBSD function with the same name
+ * new feature "reallocarr" for NetBSD function with the same name
+ * new feature "macro". It provides NetBSD-style macro __dead, __pure,
+ __UNCONST, __printflike, __constfunc, __always_inline, __aligned,
+ __arraycount, MAX and MIN
+ * "efun": add support for ereallocarr(3), estrtoi(3) and estrtou(3)
+
+ Fixes:
+ * imp.foreign_autotools.mk: add MAKE=${AT_MAKE} to environment
+ This fixes ./configure when "make" executable is not available
+ * CXXSTD: appropriate option is passed to the linker. This fixes
+ failures with Sun C++ compiler.
+ * examples/shquote/prog.c: fix segfault seen on Solaris-10
+ (incorrect use of getline(3))
+
+ mk-configure.7:
+ * add missing documentation for features "reallocarray", "fparseln"
+ and "vis"
+ * minor fixes
+ * CXXSTD: fix incorrect description
+
+ Exit with error if generated config under ~/.mkcmake is older than
+ system mk files. This situation potentially means that generated
+ configs do not contain all required information about compiler.
+
+ System-wide mk file for compiler settings has higher priority
+ than files under ~/.mkcmake
+
+ EXPORT_SYMBOLS: empty lines and comments started with '#' are ignored
+
+ mkc_install: do not remove "$dst" before renaming "$dsttmp" to
+ "$dst", it is just useless.
+
+ Simplify the target "installdirs".
+
+======================================================================
Version 0.36.0, by Aleksey Cheusov, Tue, 5 Jan 2021 19:29:08 +0300
Introduce new variables:
diff --git a/doc/TODO b/doc/TODO
index 2fa8261..80b5b9a 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,33 +1,68 @@
+############################################################
+PLAN 0.38.0:
+
============================================================
-SRC_PATHADD, CC_PREFIX and CXX_PREFIX?
+Generate .d files at the same time as compilation and load
+in the very beginning by default if appropriate variable
+is set.
============================================================
-SHRTOUT -- set -x and redirect everything to temporary
-log file and print it only if the target fails?
+MKC_REQUIRE_PKGCONFIG - make sure _mkc_ files are deleted
+when this check fails.
============================================================
-Tests for MCOMPRESS?
+New rules for .by (bison without -y option)
============================================================
-MKC_PATH environment variable for mkcmake(1)
-and mkc_compiler_settings(1)
+Add new feature for glibc-style defines
+__wur and __deprecated
============================================================
-OBJDIR_* and SRCDIR_* variable should be available
-after mkc.init.mk and initialized again in mkc.mk
+MKC_CACHEDIR ?= ${OBJTOP:U${SRCTOP}}
============================================================
-Generate .d files at the same time as compilation and load
-in the very beginning by default if appropriate variable
-is set.
+Add new feature for define restrict (C99 etc.)
+
+
+
+
+
+############################################################
+PLAN 0.39.0:
+
+ - Implement mkc_imp.libtool.mk to build
+ the shared libraries using GNU libtool(1).
+
+ - add support for pkg-config aware projects, i.e., projects
+ that provide .pc files
+
+
+
+
+
+############################################################
+PLAN REST:
============================================================
More efun features: e{read,write,setenv} from FreeBSD
============================================================
-MKC_CACHEDIR ?= ${OBJTOP:U${SRCTOP}}
+Add recursive lint and ctags (by David Young) targets
-New rules for .by (bison without -y option)
+============================================================
+SHRTOUT -- set -x and redirect everything to temporary
+log file and print it only if the target fails?
+
+============================================================
+Tests for MCOMPRESS?
+
+============================================================
+MKC_PATH environment variable for mkcmake(1)
+and mkc_compiler_settings(1)
+
+============================================================
+OBJDIR_* and SRCDIR_* variable should be available
+after mkc.init.mk and initialized again in mkc.mk
============================================================
LDFLAGS.check
@@ -36,14 +71,11 @@ LDFLAGS.check
markdown to html rules
============================================================
-Add new feature for NetBSD-style defines like __dead,
-__pure, __printflike, __UNCONST, __constfunc, __noinline,
-__always_inline, __returns_twice, __noclone, __unused,
-__used, __packed, __aligned, __section, __restrict,
-__printflike, __sysloglike, __scanflike, __format_arg,
-__arraycount, __MIN, __MAX
+Add new feature for NetBSD-style defines
+__packed, __section, __restrict,
+__sysloglike, __scanflike, __format_arg
-and glibc-style defines like __wur, __deprecated, __nonnull
+and glibc-style define __nonnull
============================================================
Add feature "alloca"
@@ -57,15 +89,6 @@ New feature "path_max" for detecting PATH_MAX from getconf
or from define (if exists). This is issue #7
============================================================
-
-[06/27 15:13]<yauheni> MKDEP.c = ${MAKEDEPEND} -f- ${ddash} ${MKDEPFLAGS} \
-[06/27 15:13]<yauheni> ${CFLAGS:C/-([IDU])[ ]*/-\1/Wg:M-[IDU]*} ${_CPPFLAGS} >
-[06/27 15:13]<yauheni> ë¸øà, çà÷åì ýòà çàìåíà?
-[06/27 17:51]<yauheni> mkc_imp.dep.mk:
-[06/27 17:51]<yauheni> .if !defined(_MKC_IMP_DEP_MK) && !empty(_SRCS_ALL)
-[06/27 17:51]<yauheni> ...
-[06/27 17:51]<yauheni> .if defined(_SRCS_ALL)
-
INCS generated by INTEXTS
============================================================
@@ -75,21 +98,13 @@ Plan 0.28.0
- test for CCLD option
- bzero, bcopy
-- check awk capabilities at build time
- Hide regression tests details
- "bmake -k regrtest/check" (mkc.minitest.mk?)
-- PRId64
-- leveldb, strtoll, strtoull
-- wmemcpy, strnlen
-- wcsdup
-
- Special marker for checks that cannot be possible in cross-compiling
- regression tests without garbage, make it look like paexec
-- MKC_FEATURES: inttypes
-
Some thoughts inspired by talks with Michael Crogan
- MKASNEEDED=yes => ld --as-needed
@@ -112,28 +127,27 @@ Some thoughts inspired by talks with Michael Crogan
- Steal cool features from Simon Gerraty's mk files and analyse
"meta mode" he invented.
-Some "targets" from TARGETS should set MKCHECKS to "no"
+- Some "targets" from TARGETS should set MKCHECKS to "no"
-ronn(1) : markdown to man pages
+- ronn(1) : markdown to man pages
custom test failed -> exit status of mkcmake should not be zero
MKC_CUSTOM_ERR.qqqq -> error message before exiting just like
- mkcmake configure doesn't work
- New variable MKC_CUSTOM_ENV.xxx
+- New variable MKC_CUSTOM_ENV.xxx
+
+- BINSUBDIR, LIBSUBDIR, LIBEXECSUBDIR etc...
- - BINSUBDIR, LIBSUBDIR, LIBEXECSUBDIR etc...
- - USE_RPATH
- - Regression tests:
- * optional(!) glib2 tests
+- USE_RPATH
+
+- Regression tests:
+ * optional(!) glib2 tests
============================================================
Plan 1)
- Support for MKDEBUG like in NetBSD mk files
- .lua.luac:
- - Implement mkc_imp.libtool.mk to build
- the shared libraries using GNU libtool(1).
============================================================
Plan 2)
@@ -172,6 +186,7 @@ Plan 3)
= Online tutorial
= shared libraries support for AIX, UnixWare, Hurd, Haiku.
+
= shared libraries support for nwcc and other compilers.
= Comparison with quagmire, kBuild, CMake, scons, waf, framewerk, pmk,
@@ -196,6 +211,8 @@ Plan 4)
= Implement mkc.doxygen.mk?
+ = Implement mkc.cunit.mk?
+
============================================================
Plan 5)
@@ -234,8 +251,8 @@ Plan 6)
snprintf, sprintf, sscanf, strerror_r, strnlen,
sysconf, unlink, unsetenv, va_copy, va_list,
signed_shr, int_div, chown_minus_1,...
- (autoconf.info/Particular Function Checks)
AC_FUNC_ALLOCA
- = autoconf (Portability of headers)
- = autoconf (Particular Header Checks)
+ = autoconf info documentation: Particular Functions
+ = autoconf info documentation: Portability Of Headers
+ = autoconf info documentation: Particular Headers
diff --git a/examples.mk b/examples.mk
index 665a92e..1a521fc 100644
--- a/examples.mk
+++ b/examples.mk
@@ -9,4 +9,5 @@ examples = hello_world files files2 sizeof lexer \
require_tools check_compiler_opts help_target \
arc4random bswap dprintf efun strsep errc posix_getopt \
raise_default_signal reallocarray fparseln vis \
- fts humanize_number shquote tiny_id c99
+ fts humanize_number shquote tiny_id c99 reallocarr \
+ strtoi
diff --git a/examples/compatlib/test.mk b/examples/compatlib/test.mk
index 5bae6f1..9e9b12a 100644
--- a/examples/compatlib/test.mk
+++ b/examples/compatlib/test.mk
@@ -1,4 +1,4 @@
-FUNCS_RE=(fgetln|progname|strlcat|strlcpy|getline|err|getdelim|strndup|_mkcfake)[.][do]
+FUNCS_RE=(fgetln|progname|strlcat|strlcpy|getline|err|getdelim|strndup|_mkcfake)[.][do]|custom_attribute
.PHONY : test_output
test_output :
@@ -16,11 +16,11 @@ test_output :
echo =========== depend ============; \
${MAKE} ${MAKEFLAGS} depend > /dev/null; \
find ${.OBJDIR} -type f | LC_ALL=C sort | \
- grep '[.]d$$' | grep -Ev '${FUNCS_RE}' | \
+ grep '[.]d$$' | grep -Ev ${FUNCS_RE:Q} | \
env NOSORT=1 mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \
echo =========== clean ============; \
${MAKE} ${MAKEFLAGS} clean > /dev/null; \
- find ${.OBJDIR} -type f | grep -v _mkc | grep -Ev '${FUNCS_RE}' | \
+ find ${.OBJDIR} -type f | grep -v _mkc | grep -Ev ${FUNCS_RE:Q} | \
mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \
echo =========== cleandir ============; \
${MAKE} ${MAKEFLAGS} cleandir > /dev/null; \
@@ -29,7 +29,7 @@ test_output :
echo ======= depend to OBJDIR ==========; \
mkdir obj; MAKEOBJDIR=${.OBJDIR}/obj; export MAKEOBJDIR; \
${MAKE} ${MAKEFLAGS} depend > /dev/null; \
- find ${.OBJDIR}/obj -type f | grep -vE '${FUNCS_RE}' | \
+ find ${.OBJDIR}/obj -type f | grep -vE ${FUNCS_RE:Q} | \
grep -v _mkc | \
mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \
rm -rf obj; unset MAKEOBJDIR; \
diff --git a/examples/dictd/libmaa/export.sym b/examples/dictd/libmaa/export.sym
index ee9bd7c..4e65d4c 100644
--- a/examples/dictd/libmaa/export.sym
+++ b/examples/dictd/libmaa/export.sym
@@ -1,3 +1,6 @@
+# functions of category A
fake4
-fake5
+fake5 # one-line comment is allowed
+
+# functions of category B
fake6
diff --git a/examples/efun/expect.out b/examples/efun/expect.out
index 68ec8c9..28480e2 100644
--- a/examples/efun/expect.out
+++ b/examples/efun/expect.out
@@ -5,3 +5,6 @@ Hello World!
Hello World!
Hello
Hello World!
+Hello World!
+111
+-111
diff --git a/examples/efun/prog.c b/examples/efun/prog.c
index 79f2609..516d8e8 100644
--- a/examples/efun/prog.c
+++ b/examples/efun/prog.c
@@ -1,3 +1,4 @@
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <mkc_efun.h>
@@ -9,6 +10,8 @@ int main (int argc, char **argv)
char *buffer = ecalloc(BUF_SIZE, 1);
char *copy;
FILE *fd;
+ uintmax_t uval;
+ intmax_t sval;
estrlcpy(buffer, "Hello", BUF_SIZE);
estrlcat(buffer, " World!", BUF_SIZE);
@@ -32,9 +35,22 @@ int main (int argc, char **argv)
estrlcpy(copy, buffer, 200);
puts(copy);
free(copy);
+ copy = NULL;
+
+ ereallocarr(&copy, 200, 1);
+ estrlcpy(copy, buffer, 200);
+ puts(copy);
+ free(copy);
+ copy = NULL;
fd = efopen("/dev/null", "r");
fclose(fd);
+ uval = estrtou("111", 10, 0, 999);
+ printf("%" PRIuMAX "\n", uval);
+
+ sval = estrtoi("-111", 10, -999, 999);
+ printf("%" PRIdMAX "\n", sval);
+
return 0;
}
diff --git a/examples/fgetln/test.mk b/examples/fgetln/test.mk
index 4829960..c87cf5c 100644
--- a/examples/fgetln/test.mk
+++ b/examples/fgetln/test.mk
@@ -1,4 +1,4 @@
-FUNCS_RE=(fgetln|getline|err|progname|strndup)[.]o
+FUNCS_RE=(fgetln|getline|err|progname|strndup)[.]o|custom_attribute
.PHONY : test_output
test_output:
@@ -7,7 +7,7 @@ test_output:
rm -rf ${.OBJDIR}${PREFIX}; \
\
echo =========== all ============; \
- find ${.OBJDIR} -type f | grep -Ev '${FUNCS_RE}' | \
+ find ${.OBJDIR} -type f | grep -Ev ${FUNCS_RE:Q} | \
mkc_test_helper "${PREFIX}" "${.OBJDIR}"; \
\
echo ======= CLEANFILES ==========; \
diff --git a/examples/progs/test.mk b/examples/progs/test.mk
index b4ac7d9..3bc1a14 100644
--- a/examples/progs/test.mk
+++ b/examples/progs/test.mk
@@ -1,4 +1,4 @@
-FEATURES_RE=_mkc_|efun|progname|strlc|dprintf|strndup|err
+FEATURES_RE=_mkc_|efun|progname|strlc|dprintf|strndup|err|reallocarr|strto[iu]
.PHONY : test_output
test_output:
diff --git a/examples/reallocarr/Makefile b/examples/reallocarr/Makefile
new file mode 100644
index 0000000..5c5d72e
--- /dev/null
+++ b/examples/reallocarr/Makefile
@@ -0,0 +1,11 @@
+PROG = prog
+SRCS = prog.c
+
+WARNS = 4
+
+MKC_FEATURES += errc reallocarr
+
+MKC_REQD = 0.36.90
+
+.include "test.mk"
+.include <mkc.prog.mk>
diff --git a/examples/reallocarr/expect.out b/examples/reallocarr/expect.out
new file mode 100644
index 0000000..f470d50
--- /dev/null
+++ b/examples/reallocarr/expect.out
@@ -0,0 +1,2 @@
+Allocated pointer: NNNNNNNN
+Allocated pointer: NNNNNNNN
diff --git a/examples/reallocarr/prog.c b/examples/reallocarr/prog.c
new file mode 100644
index 0000000..7bddfa8
--- /dev/null
+++ b/examples/reallocarr/prog.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <mkc_reallocarr.h>
+#include <mkc_errc.h>
+
+int main(int argc, char *argv[])
+{
+ int *data = NULL;
+ int ret = 0;
+
+ ret = reallocarr(&data, 16, sizeof(*data));
+ if (ret)
+ errc(1, ret, "reallocarr failed");
+
+ printf("Allocated pointer: %p\n", data);
+
+ ret = reallocarr(&data, 256, sizeof(*data));
+ if (ret)
+ errc(1, ret, "reallocarr failed on resize");
+
+ printf("Allocated pointer: %p\n", data);
+
+ free(data);
+
+ return 0;
+}
diff --git a/examples/reallocarr/test.mk b/examples/reallocarr/test.mk
new file mode 100644
index 0000000..b997097
--- /dev/null
+++ b/examples/reallocarr/test.mk
@@ -0,0 +1,6 @@
+.PHONY : test_output
+test_output:
+ @${.OBJDIR}/prog | sed 's/: [^ ][^ ]*/: NNNNNNNN/'; \
+ ${MAKE} ${MAKEFLAGS} cleandir > /dev/null
+
+.include <mkc.minitest.mk>
diff --git a/examples/shquote/prog.c b/examples/shquote/prog.c
index 08742ba..c02598c 100644
--- a/examples/shquote/prog.c
+++ b/examples/shquote/prog.c
@@ -11,7 +11,7 @@ int main(int argc, char **argv)
{
char *buf = NULL;
char *old_buf = NULL;
- size_t size;
+ size_t size = 0;
size_t len;
char *shquoted_buf = NULL;
diff --git a/examples/strtoi/Makefile b/examples/strtoi/Makefile
new file mode 100644
index 0000000..872560c
--- /dev/null
+++ b/examples/strtoi/Makefile
@@ -0,0 +1,11 @@
+PROG = prog
+SRCS = prog.c
+
+WARNS = 4
+
+MKC_FEATURES = getline strtoi strtou
+
+MKC_REQD = 0.36.90
+
+.include "test.mk"
+.include <mkc.prog.mk>
diff --git a/examples/strtoi/expect.out b/examples/strtoi/expect.out
new file mode 100644
index 0000000..7c74096
--- /dev/null
+++ b/examples/strtoi/expect.out
@@ -0,0 +1,16 @@
+strtoi: ECANCELED
+strtou: ECANCELED
+strtoi: 12
+strtou: 12
+strtoi: 0
+strtou: 0
+strtoi: 99
+strtou: 99
+strtoi: ERANGE
+strtou: ERANGE
+strtoi: ECANCELED
+strtou: ECANCELED
+strtoi: ERANGE
+strtou: ERANGE
+strtoi: -17
+strtou: ERANGE
diff --git a/examples/strtoi/input.in b/examples/strtoi/input.in
new file mode 100644
index 0000000..98a1635
--- /dev/null
+++ b/examples/strtoi/input.in
@@ -0,0 +1,8 @@
+aaa
+12
+0
++99
+111
+
+-989
+-17
diff --git a/examples/strtoi/prog.c b/examples/strtoi/prog.c
new file mode 100644
index 0000000..0417577
--- /dev/null
+++ b/examples/strtoi/prog.c
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <errno.h>
+
+#include <mkc_getline.h>
+#include <mkc_strtoi.h>
+#include <mkc_strtou.h>
+
+int main (int argc, char ** argv)
+{
+ char *buf = NULL;
+ size_t size = 0;
+ ssize_t len = 0;
+ intmax_t sval;
+ uintmax_t uval;
+ int rstatus;
+
+ while (len = getline(&buf, &size, stdin), len != -1){
+ if (len > 0 && buf[len-1] == '\n')
+ buf[len - 1] = 0;
+
+ /* strtoi */
+ printf("strtoi: ");
+ sval = strtoi(buf, NULL, 10, -99, 99, &rstatus);
+ switch (rstatus){
+ case ECANCELED:
+ puts("ECANCELED");
+ break;
+ case EINVAL:
+ puts("EINVAL");
+ break;
+ case ENOTSUP:
+ puts("ENOTSUP");
+ break;
+ case ERANGE:
+ puts("ERANGE");
+ break;
+ case 0:
+ printf("%" PRIdMAX "\n", sval);
+ break;
+ default:
+ abort();
+ }
+
+ /* strtoi */
+ printf("strtou: ");
+ uval = strtou(buf, NULL, 10, 0, 99, &rstatus);
+ switch (rstatus){
+ case ECANCELED:
+ puts("ECANCELED");
+ break;
+ case EINVAL:
+ puts("EINVAL");
+ break;
+ case ENOTSUP:
+ puts("ENOTSUP");
+ break;
+ case ERANGE:
+ puts("ERANGE");
+ break;
+ case 0:
+ printf("%" PRIuMAX "\n", uval);
+ break;
+ default:
+ abort();
+ }
+ }
+
+ return 0;
+}
diff --git a/examples/strtoi/test.mk b/examples/strtoi/test.mk
new file mode 100644
index 0000000..d2af3ee
--- /dev/null
+++ b/examples/strtoi/test.mk
@@ -0,0 +1,6 @@
+.PHONY : test_output
+test_output:
+ @set -e; \
+ ${.OBJDIR}/prog < ${.CURDIR}/input.in
+
+.include <mkc.minitest.mk>
diff --git a/features/Makefile b/features/Makefile
index b9f6937..3077951 100644
--- a/features/Makefile
+++ b/features/Makefile
@@ -1,23 +1,32 @@
-FILES += mkc_imp.f_libl.mk
-FILESDIR_mkc_imp.f_libl.mk = ${MKFILESDIR}
+.for f in libl strtoi strtou macro
+FILES += mkc_imp.f_${f}.mk
+FILESDIR_mkc_imp.f_${f}.mk = ${MKFILESDIR}
+.endfor
-FILES += mkc_externc.h
-FILESDIR_mkc_externc.h = ${FEATURESDIR}
+.for f in mkc_externc.h mkc_macro.h mkc_strtoi.h mkc_strtou.h
+FILES += ${f}
+FILESDIR_${f} = ${FEATURESDIR}
+.endfor
.for f in dprintf efun err errc fgetln fparseln getdelim getline \
humanize_number posix_getopt progname pwdgrp raise_default_signal \
- reallocarray strlcat strlcpy strndup strsep vis warn shquote
+ reallocarr reallocarray strlcat strlcpy strndup strsep vis warn shquote
FILES += mkc_${f}.h mkc_imp.f_${f}.mk ${f}/mkc_${f}.c
FILESDIR_mkc_imp.f_${f}.mk = ${MKFILESDIR}
FILESDIR_mkc_${f}.h = ${FEATURESDIR}
FILESDIR_${f}/mkc_${f}.c = ${FEATURESDIR}/${f}
.endfor
-FILES += errc/mkc_verrc.c
-FILESDIR_errc/mkc_verrc.c = ${FEATURESDIR}/errc
+.for f in aligned always_inline const noreturn printflike pure
+FILES += macro/mkc_attribute_${f}.c
+FILESDIR_macro/mkc_attribute_${f}.c = ${FEATURESDIR}/macro
+.endfor
-FILES += vis/mkc_unvis.c
-FILESDIR_vis/mkc_unvis.c = ${FEATURESDIR}/vis
+.for f in strto/mkc_strtoi.c strto/mkc_strtou.c strto/mkc__strtoi.h vis/mkc_unvis.c \
+ errc/mkc_verrc.c
+FILES += ${f}
+FILESDIR_${f} = ${FEATURESDIR}/${f:H}
+.endfor
.for f in libm libdl SLIST RB bswap fts arc4random
FILES += mkc_${f}.h mkc_imp.f_${f}.mk
diff --git a/features/efun/mkc_efun.c b/features/efun/mkc_efun.c
index 00e89d9..158052e 100644
--- a/features/efun/mkc_efun.c
+++ b/features/efun/mkc_efun.c
@@ -33,6 +33,9 @@
#include "mkc_strlcat.h"
#include "mkc_strlcpy.h"
#include "mkc_strndup.h"
+#include "mkc_reallocarr.h"
+#include "mkc_strtoi.h"
+#include "mkc_strtou.h"
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
@@ -129,7 +132,6 @@ erealloc(void *p, size_t n)
return q;
}
-/*
void
ereallocarr(void *p, size_t n, size_t s)
{
@@ -139,7 +141,6 @@ ereallocarr(void *p, size_t n, size_t s)
(*efunc)(1, "Cannot re-allocate %zu * %zu bytes", n, s);
}
}
-*/
FILE *
efopen(const char *p, const char *m)
@@ -171,7 +172,6 @@ evasprintf(char ** /*__restrict*/ ret, const char * /*__restrict*/ format, va_li
return rv;
}
-/*
intmax_t
estrtoi(const char * nptr, int base, intmax_t lo, intmax_t hi)
{
@@ -199,4 +199,3 @@ estrtou(const char * nptr, int base, uintmax_t lo, uintmax_t hi)
}
return rv;
}
-*/
diff --git a/features/errc/mkc_errc.c b/features/errc/mkc_errc.c
index 7d16b6d..74ca6fb 100644
--- a/features/errc/mkc_errc.c
+++ b/features/errc/mkc_errc.c
@@ -39,12 +39,12 @@ __RCSID("$NetBSD: errc.c,v 1.3 2014/06/06 11:38:41 joerg Exp $");
#include "mkc_errc.h"
-/*__dead*/ void
+void
errc(int eval, int code, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
verrc(eval, code, fmt, ap);
- va_end(ap);
+ /* va_end(ap); NOT REACHED */
}
diff --git a/features/errc/mkc_verrc.c b/features/errc/mkc_verrc.c
index 06605cb..1b54ce6 100644
--- a/features/errc/mkc_verrc.c
+++ b/features/errc/mkc_verrc.c
@@ -43,11 +43,12 @@ __RCSID("$NetBSD: verrc.c,v 1.3 2014/06/06 11:38:41 joerg Exp $");
#include "mkc_errc.h"
#include "mkc_progname.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-/*__dead*/ void
+void
verrc(int eval, int code, const char *fmt, va_list ap)
{
(void)fprintf(stderr, "%s: ", getprogname());
diff --git a/features/macro/mkc_attribute_aligned.c b/features/macro/mkc_attribute_aligned.c
new file mode 100644
index 0000000..2c7d963
--- /dev/null
+++ b/features/macro/mkc_attribute_aligned.c
@@ -0,0 +1 @@
+char array[256] __attribute__((aligned(256)));
diff --git a/features/macro/mkc_attribute_always_inline.c b/features/macro/mkc_attribute_always_inline.c
new file mode 100644
index 0000000..0dfef5f
--- /dev/null
+++ b/features/macro/mkc_attribute_always_inline.c
@@ -0,0 +1,11 @@
+static int square(int v) __attribute__ ((always_inline));
+
+static int square(int v)
+{
+ return v * v;
+}
+
+int main(int argc, char **argv)
+{
+ return square(2);
+}
diff --git a/features/macro/mkc_attribute_const.c b/features/macro/mkc_attribute_const.c
new file mode 100644
index 0000000..1e4d8c3
--- /dev/null
+++ b/features/macro/mkc_attribute_const.c
@@ -0,0 +1,6 @@
+int square(int v) __attribute__ ((const));
+
+int square(int v)
+{
+ return v * v;
+}
diff --git a/features/macro/mkc_attribute_noreturn.c b/features/macro/mkc_attribute_noreturn.c
new file mode 100644
index 0000000..62aba1c
--- /dev/null
+++ b/features/macro/mkc_attribute_noreturn.c
@@ -0,0 +1,8 @@
+#include <stdlib.h>
+
+void err_exit() __attribute__ ((noreturn));
+
+void err_exit(int status)
+{
+ exit(status);
+}
diff --git a/features/macro/mkc_attribute_printflike.c b/features/macro/mkc_attribute_printflike.c
new file mode 100644
index 0000000..c2d2ed9
--- /dev/null
+++ b/features/macro/mkc_attribute_printflike.c
@@ -0,0 +1,5 @@
+extern int
+my_printf (void *my_object, const char *my_format, ...)
+ __attribute__ ((format (printf, 2, 3)));
+
+int zzz;
diff --git a/features/macro/mkc_attribute_pure.c b/features/macro/mkc_attribute_pure.c
new file mode 100644
index 0000000..eb67521
--- /dev/null
+++ b/features/macro/mkc_attribute_pure.c
@@ -0,0 +1,6 @@
+int square(int v) __attribute__ ((pure));
+
+int square(int v)
+{
+ return v * v;
+}
diff --git a/features/mkc_efun.h b/features/mkc_efun.h
index 8e8a217..0e604dd 100644
--- a/features/mkc_efun.h
+++ b/features/mkc_efun.h
@@ -63,7 +63,7 @@ void * emalloc(size_t n);
void * erealloc(void *p, size_t n);
-//void ereallocarr(void *, size_t, size_t);
+void ereallocarr(void *, size_t, size_t);
char * estrdup(const char *s);
@@ -75,6 +75,10 @@ size_t estrlcpy(char *dst, const char *src, size_t len);
int evasprintf(char ** /*__restrict*/ str, const char * /*__restrict*/ fmt, va_list ap);
+intmax_t estrtoi(const char * nptr, int base, intmax_t lo, intmax_t hi);
+
+uintmax_t estrtou(const char * nptr, int base, uintmax_t lo, uintmax_t hi);
+
__MKC_END_DECLS
# endif
diff --git a/features/mkc_err.h b/features/mkc_err.h
index e73d072..da5e281 100644
--- a/features/mkc_err.h
+++ b/features/mkc_err.h
@@ -27,17 +27,19 @@
__MKC_BEGIN_DECLS
+#include "mkc_macro.h"
+
#if !HAVE_FUNC3_ERR_ERR_H
-void err (int, const char *, ...);
+void err (int, const char *, ...) __printflike(2, 3) __dead;
#endif
#if !HAVE_FUNC3_ERRX_ERR_H
-void errx (int, const char *, ...);
+void errx (int, const char *, ...) __printflike(2, 3) __dead;
#endif
#if !HAVE_FUNC3_VERR_ERR_H
-void verr (int, const char *, va_list);
+void verr (int, const char *, va_list) __printflike(2, 0) __dead;
#endif
#if !HAVE_FUNC3_VERRX_ERR_H
-void verrx (int, const char *, va_list);
+void verrx (int, const char *, va_list) __printflike(2, 0) __dead;
#endif
__MKC_END_DECLS
diff --git a/features/mkc_errc.h b/features/mkc_errc.h
index a3c72b0..6f7d8f2 100644
--- a/features/mkc_errc.h
+++ b/features/mkc_errc.h
@@ -21,12 +21,14 @@
__MKC_BEGIN_DECLS
+#include "mkc_macro.h"
+
#if !HAVE_FUNC4_ERRC_ERR_H
-void errc(int status, int code, const char *fmt, ...);
+void errc(int status, int code, const char *fmt, ...) __printflike(3, 4) __dead;
#endif
#if !HAVE_PROTOTYPE_VERRC
-void verrc(int status, int code, const char *fmt, va_list args);
+void verrc(int status, int code, const char *fmt, va_list args) __printflike(3, 0) __dead;
#endif
__MKC_END_DECLS
diff --git a/features/mkc_imp.f_efun.mk b/features/mkc_imp.f_efun.mk
index 2426415..040c41b 100644
--- a/features/mkc_imp.f_efun.mk
+++ b/features/mkc_imp.f_efun.mk
@@ -9,8 +9,9 @@ _MKC_IMP_EFUN_MK := 1
.include "mkc_imp.f_strlcpy.mk"
.include "mkc_imp.f_strlcat.mk"
.include "mkc_imp.f_strndup.mk"
-
-MKC_FEATURES += strlcpy strlcat fgetln err
+.include "mkc_imp.f_reallocarr.mk"
+.include "mkc_imp.f_strtoi.mk"
+.include "mkc_imp.f_strtou.mk"
MKC_CHECK_FUNCS2 += ecalloc:util.h
MKC_CHECK_FUNCLIBS += ecalloc:util
diff --git a/features/mkc_imp.f_err.mk b/features/mkc_imp.f_err.mk
index 15f7b05..a931804 100644
--- a/features/mkc_imp.f_err.mk
+++ b/features/mkc_imp.f_err.mk
@@ -5,7 +5,8 @@
.ifndef _MKC_IMP_F_ERR_MK
_MKC_IMP_F_ERR_MK := 1
-.include <mkc_imp.f_progname.mk>
+.include "mkc_imp.f_progname.mk"
+.include "mkc_imp.f_macro.mk"
.include <mkc.conf.mk>
diff --git a/features/mkc_imp.f_errc.mk b/features/mkc_imp.f_errc.mk
index aea80ad..d45622a 100644
--- a/features/mkc_imp.f_errc.mk
+++ b/features/mkc_imp.f_errc.mk
@@ -5,7 +5,8 @@
.ifndef _MKC_IMP_F_ERRC_MK
_MKC_IMP_F_ERRC_MK := 1
-.include <mkc_imp.f_progname.mk>
+.include "mkc_imp.f_progname.mk"
+.include "mkc_imp.f_macro.mk"
.include <mkc.conf.mk>
diff --git a/features/mkc_imp.f_humanize_number.mk b/features/mkc_imp.f_humanize_number.mk
index 5d9552d..55d9661 100644
--- a/features/mkc_imp.f_humanize_number.mk
+++ b/features/mkc_imp.f_humanize_number.mk
@@ -12,6 +12,7 @@ MKC_CHECK_FUNCLIBS += humanize_number #dehumanize_number
.include <mkc.conf.mk>
. if ${HAVE_FUNCLIB.humanize_number:U} != 1 #|| ${HAVE_FUNCLIB.dehumanize_number:U} != 1
+. include "mkc_imp.f_macro.mk"
MKC_SRCS += ${FEATURESDIR}/humanize_number/mkc_humanize_number.c
. endif
diff --git a/features/mkc_imp.f_macro.mk b/features/mkc_imp.f_macro.mk
index 6f8e345..744099c 100644
--- a/features/mkc_imp.f_macro.mk
+++ b/features/mkc_imp.f_macro.mk
@@ -5,9 +5,19 @@
.ifndef _MKC_IMP_F_MACRO_MK
_MKC_IMP_F_MACRO_MK := 1
-#MKC_CHECK_TYPES += u_quad_t:sys/types.h
-#MKC_CHECK_HEADER_FILES += sys/sysmacros.h sys/cdefs.h paths.h
+.for f in noreturn pure printflike const always_inline aligned
+MKC_CHECK_CUSTOM += attribute_${f}
+MKC_CUSTOM_FN.attribute_${f} = ${FEATURESDIR}/macro/mkc_attribute_${f}.c
+.endfor
-#CPPFLAGS += -D_MKC_CHECK_MACRO
+.include <mkc.conf.mk>
-.endif #_MKC_IMP_F_MACRO_MK
+CPPFLAGS += -D_MKC_CHECK_MACRO
+
+.for f in noreturn pure printflike const always_inline aligned
+. if ${CUSTOM.attribute_${f}:U} != 1
+MKC_CPPFLAGS += -DHAVE_NO_ATTR_${f:tu}
+. endif
+.endfor
+
+.endif # _MKC_IMP_F_MACRO_MK
diff --git a/features/mkc_imp.f_reallocarr.mk b/features/mkc_imp.f_reallocarr.mk
new file mode 100644
index 0000000..e47ba4e
--- /dev/null
+++ b/features/mkc_imp.f_reallocarr.mk
@@ -0,0 +1,19 @@
+# Copyright (c) 2021 by Aleksey Cheusov
+#
+# See LICENSE file in the distribution.
+
+.ifndef _MKC_IMP_F_REALLOCARR_MK
+_MKC_IMP_F_REALLOCARR_MK := 1
+
+MKC_CHECK_FUNCS3 += reallocarr:stdlib.h
+MKC_CHECK_FUNCLIBS += reallocarr
+
+.include <mkc.conf.mk>
+
+.if ${HAVE_FUNCLIB.reallocarr:U} != 1
+MKC_SRCS += ${FEATURESDIR}/reallocarr/mkc_reallocarr.c
+.endif
+
+CPPFLAGS += -D_MKC_CHECK_REALLOCARR
+
+.endif #_MKC_IMP_F_REALLOCARR_MK
diff --git a/features/mkc_imp.f_shquote.mk b/features/mkc_imp.f_shquote.mk
index 905445b..01af20b 100644
--- a/features/mkc_imp.f_shquote.mk
+++ b/features/mkc_imp.f_shquote.mk
@@ -5,6 +5,8 @@
.ifndef _MKC_IMP_F_SHQUOTE_MK
_MKC_IMP_F_SHQUOTE_MK := 1
+.include "mkc_imp.f_macro.mk"
+
MKC_CHECK_FUNCLIBS += shquote
MKC_CHECK_FUNCS3 += shquote:stdlib.h
diff --git a/features/mkc_imp.f_strtoi.mk b/features/mkc_imp.f_strtoi.mk
new file mode 100644
index 0000000..e00aa74
--- /dev/null
+++ b/features/mkc_imp.f_strtoi.mk
@@ -0,0 +1,19 @@
+# Copyright (c) 2021 by Aleksey Cheusov
+#
+# See LICENSE file in the distribution.
+
+.ifndef _MKC_IMP_F_STRTOI_MK
+_MKC_IMP_F_STRTOI_MK := 1
+
+MKC_CHECK_FUNCS6 += strtoi:inttypes.h
+MKC_CHECK_FUNCLIBS += strtoi
+
+.include <mkc.conf.mk>
+
+.if ${HAVE_FUNCLIB.strtoi:U} != 1
+MKC_SRCS += ${FEATURESDIR}/strto/mkc_strtoi.c
+.endif
+
+CPPFLAGS += -D_MKC_CHECK_STRTOI
+
+.endif #_MKC_IMP_F_STRTOI_MK
diff --git a/features/mkc_imp.f_strtou.mk b/features/mkc_imp.f_strtou.mk
new file mode 100644
index 0000000..3443033
--- /dev/null
+++ b/features/mkc_imp.f_strtou.mk
@@ -0,0 +1,19 @@
+# Copyright (c) 2021 by Aleksey Cheusov
+#
+# See LICENSE file in the distribution.
+
+.ifndef _MKC_IMP_F_STRTOU_MK
+_MKC_IMP_F_STRTOU_MK := 1
+
+MKC_CHECK_FUNCS6 += strtou:inttypes.h
+MKC_CHECK_FUNCLIBS += strtou
+
+.include <mkc.conf.mk>
+
+.if ${HAVE_FUNCLIB.strtou:U} != 1
+MKC_SRCS += ${FEATURESDIR}/strto/mkc_strtou.c
+.endif
+
+CPPFLAGS += -D_MKC_CHECK_STRTOU
+
+.endif #_MKC_IMP_F_STRTOU_MK
diff --git a/features/mkc_imp.f_warn.mk b/features/mkc_imp.f_warn.mk
index af77be3..d243247 100644
--- a/features/mkc_imp.f_warn.mk
+++ b/features/mkc_imp.f_warn.mk
@@ -5,7 +5,8 @@
.ifndef _MKC_IMP_F_WARN_MK
_MKC_IMP_F_WARN_MK := 1
-.include <mkc_imp.f_progname.mk>
+.include "mkc_imp.f_progname.mk"
+.include "mkc_imp.f_macro.mk"
.include <mkc.conf.mk>
diff --git a/features/mkc_macro.h b/features/mkc_macro.h
index 0537fbb..e46c008 100644
--- a/features/mkc_macro.h
+++ b/features/mkc_macro.h
@@ -1,8 +1,86 @@
+/********************************************************************\
+ Copyright (c) 2021 by Aleksey Cheusov
+
+ See LICENSE file in the distribution.
+\********************************************************************/
+
#ifndef _MKC_MACRO_H_
#define _MKC_MACRO_H_
+#ifndef _MKC_CHECK_MACRO
+# error "Missing MKC_FEATURES += macro"
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+
+#ifndef __aligned
+# ifdef HAVE_NO_ATTR_ALIGNED
+# define __aligned(x)
+# else
+# define __aligned(x) __attribute__((aligned(x)))
+# endif
+#endif
+
+#ifndef __always_inline
+# ifdef HAVE_NO_ATTR_ALWAYS_INLINE
+# define __always_inline
+# else
+# define __always_inline __attribute__((always_inline))
+# endif
+#endif
+
+#ifndef __constfunc
+# ifdef HAVE_NO_ATTR_CONST
+# define __constfunc
+# else
+# define __constfunc __attribute__((const))
+# endif
+#endif
+
+#ifndef __dead
+# ifdef HAVE_NO_ATTR_NORETURN
+# define __dead
+# else
+# define __dead __attribute__((noreturn))
+# endif
+#endif
+
+#ifndef __pure
+# ifdef HAVE_NO_ATTR_PURE
+# define __pure
+# else
+# define __pure __attribute__((pure))
+# endif
+#endif
+
+#ifndef __printflike
+# ifdef HAVE_NO_ATTR_PRINTFLIKE
+# define __printflike(fmtarg, firstvararg)
+# else
+# define __printflike(fmtarg, firstvararg) \
+ __attribute__((format (printf, fmtarg, firstvararg)))
+# endif
+#endif
+
+#ifndef MIN
+# define MIN(a,b) (((a)<(b))?(a):(b))
+#endif
+
+#ifndef MAX
+# define MAX(b,a) (((a)<(b))?(a):(b))
+#endif
+
#ifndef _DIAGASSERT
-#define _DIAGASSERT(c) assert(c)
+# define _DIAGASSERT(c) assert(c)
#endif
+#ifndef __UNCONST
+# define __UNCONST(p) ((void *) ((char *)0 + ((const char *)(p) - (const char *)0)))
#endif
+
+#ifndef __arraycount
+# define __arraycount(__a) (sizeof(__a)/sizeof(__a[0]))
+#endif
+
+#endif /* _MKC_MACRO_H_ */
diff --git a/features/mkc_reallocarr.h b/features/mkc_reallocarr.h
new file mode 100644
index 0000000..51e2dd5
--- /dev/null
+++ b/features/mkc_reallocarr.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Aleksey Cheusov <vle@gmx.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MKC_REALLOCARR_H_
+#define _MKC_REALLOCARR_H_
+
+#ifndef _MKC_CHECK_REALLOCARR
+# error "Missing MKC_FEATURES += reallocarr"
+#endif
+
+#include <stdlib.h>
+
+#ifndef HAVE_FUNC3_REALLOCARR_STDLIB_H
+
+#include "mkc_externc.h"
+
+__MKC_BEGIN_DECLS
+
+int reallocarr(void *ptr, size_t number, size_t size);
+
+__MKC_END_DECLS
+
+#endif
+
+#endif // _MKC_REALLOCARR_H_
diff --git a/features/mkc_shquote.h b/features/mkc_shquote.h
index a587228..fe438e6 100644
--- a/features/mkc_shquote.h
+++ b/features/mkc_shquote.h
@@ -17,7 +17,11 @@
#ifndef HAVE_FUNC3_SHQUOTE_STDLIB_H
__MKC_BEGIN_DECLS
-size_t shquote (const char *arg, char *buf, size_t bufsize);
+
+#include "mkc_macro.h"
+
+size_t shquote (const char *arg, char *buf, size_t bufsize) __constfunc;
+
__MKC_END_DECLS
#endif
diff --git a/features/mkc_strtoi.h b/features/mkc_strtoi.h
new file mode 100644
index 0000000..f7fb767
--- /dev/null
+++ b/features/mkc_strtoi.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2021 Aleksey Cheusov <vle@gmx.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MKC_STRTOI_H_
+#define _MKC_STRTOI_H_ 1
+
+#ifndef _MKC_CHECK_STRTOI
+# error "Missing MKC_FEATURES += strtoi"
+#endif
+
+#include <inttypes.h>
+
+#ifndef HAVE_FUNC6_STRTOI_INTTYPES_H
+#include "mkc_externc.h"
+__MKC_BEGIN_DECLS
+intmax_t
+strtoi(const char * /*restrict*/ nptr, char ** /*restrict*/ endptr, int base,
+ intmax_t lo, intmax_t hi, int *rstatus);
+__MKC_END_DECLS
+#endif
+
+#endif
diff --git a/features/mkc_strtou.h b/features/mkc_strtou.h
new file mode 100644
index 0000000..0722e49
--- /dev/null
+++ b/features/mkc_strtou.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2021 Aleksey Cheusov <vle@gmx.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MKC_STRTOU_H_
+#define _MKC_STRTOU_H_ 1
+
+#ifndef _MKC_CHECK_STRTOU
+# error "Missing MKC_FEATURES += strtou"
+#endif
+
+#include <inttypes.h>
+
+#ifndef HAVE_FUNC6_STRTOU_INTTYPES_H
+#include "mkc_externc.h"
+__MKC_BEGIN_DECLS
+uintmax_t
+strtou(const char * /*restrict*/ nptr, char ** /*restrict*/ endptr, int base,
+ uintmax_t lo, uintmax_t hi, int *rstatus);
+__MKC_END_DECLS
+#endif
+
+#endif
diff --git a/features/mkc_warn.h b/features/mkc_warn.h
index 3d79bb0..aac7d50 100644
--- a/features/mkc_warn.h
+++ b/features/mkc_warn.h
@@ -27,17 +27,19 @@
__MKC_BEGIN_DECLS
+#include "mkc_macro.h"
+
#if !HAVE_FUNC2_WARN_ERR_H
-void warn (const char *, ...);
+void warn (const char *, ...) __printflike(1, 2);
#endif
#if !HAVE_FUNC2_WARNX_ERR_H
-void warnx (const char *, ...);
+void warnx (const char *, ...) __printflike(1, 2);
#endif
#if !HAVE_FUNC2_VWARN_ERR_H
-void vwarn (const char *, va_list);
+void vwarn (const char *, va_list) __printflike(1, 0);
#endif
#if !HAVE_FUNC2_VWARNX_ERR_H
-void vwarnx (const char *, va_list);
+void vwarnx (const char *, va_list) __printflike(1, 0);
#endif
__MKC_END_DECLS
diff --git a/features/reallocarr/mkc_reallocarr.c b/features/reallocarr/mkc_reallocarr.c
new file mode 100644
index 0000000..ae2da83
--- /dev/null
+++ b/features/reallocarr/mkc_reallocarr.c
@@ -0,0 +1,102 @@
+/* $NetBSD: reallocarr.c,v 1.5 2015/08/20 22:27:49 kamil Exp $ */
+
+/*-
+ * Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * Copyright (c) 2021 Aleksey Cheusov <vle@gmx.net>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+/* __RCSID("$NetBSD: reallocarr.c,v 1.5 2015/08/20 22:27:49 kamil Exp $"); */
+
+#include <errno.h>
+/* Old POSIX has SIZE_MAX in limits.h */
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "mkc_reallocarr.h"
+#include "mkc_macro.h"
+
+#ifdef _LIBC
+#ifdef __weak_alias
+__weak_alias(reallocarr, _reallocarr)
+#endif
+#endif
+
+#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2))
+
+#if !HAVE_REALLOCARR
+
+#ifndef __predict_false
+#define __predict_false(exp) (exp)
+#endif
+
+int
+reallocarr(void *ptr, size_t number, size_t size)
+{
+ int saved_errno, result;
+ void *optr;
+ void *nptr;
+
+ saved_errno = errno;
+ memcpy(&optr, ptr, sizeof(ptr));
+ if (number == 0 || size == 0) {
+ free(optr);
+ nptr = NULL;
+ memcpy(ptr, &nptr, sizeof(ptr));
+ errno = saved_errno;
+ return 0;
+ }
+
+ /*
+ * Try to avoid division here.
+ *
+ * It isn't possible to overflow during multiplication if neither
+ * operand uses any of the most significant half of the bits.
+ */
+ if (__predict_false((number|size) >= SQRT_SIZE_MAX &&
+ number > SIZE_MAX / size)) {
+ errno = saved_errno;
+ return EOVERFLOW;
+ }
+
+ nptr = realloc(optr, number * size);
+ if (__predict_false(nptr == NULL)) {
+ result = errno;
+ } else {
+ result = 0;
+ memcpy(ptr, &nptr, sizeof(ptr));
+ }
+ errno = saved_errno;
+ return result;
+}
+#endif
diff --git a/features/strto/mkc__strtoi.h b/features/strto/mkc__strtoi.h
new file mode 100644
index 0000000..89d1351
--- /dev/null
+++ b/features/strto/mkc__strtoi.h
@@ -0,0 +1,146 @@
+/* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Original version ID:
+ * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
+ *
+ * Created by Kamil Rytarowski, based on ID:
+ * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp
+ */
+
+/*
+ * function template for strtoi and strtou
+ *
+ * parameters:
+ * _FUNCNAME : function name
+ * __TYPE : return and range limits type
+ * __WRAPPED : wrapped function, strtoimax or strtoumax
+ */
+
+#define __WRAPPED_L_(x) x ## _l
+#define __WRAPPED_L__(x) __WRAPPED_L_(x)
+#define __WRAPPED_L __WRAPPED_L__(__WRAPPED)
+
+#if defined(_KERNEL) || defined(_STANDALONE) || \
+ defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+__TYPE
+_FUNCNAME(const char * /*restrict*/ nptr, char ** /*restrict*/ endptr, int base,
+ __TYPE lo, __TYPE hi, int * rstatus)
+#else
+#include <locale.h>
+#include "setlocale_local.h"
+#define INT_FUNCNAME_(pre, name, post) pre ## name ## post
+#define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post)
+
+static __TYPE
+INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char * /*restrict*/ nptr,
+ char ** /*restrict*/ endptr, int base,
+ __TYPE lo, __TYPE hi, int * rstatus, locale_t loc)
+#endif
+{
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ int serrno;
+#endif
+ __TYPE im;
+ char *ep;
+ int rep;
+
+ assert(hi >= lo);
+
+ assert(nptr != NULL);
+ /* endptr may be NULL */
+
+ if (endptr == NULL)
+ endptr = &ep;
+
+ if (rstatus == NULL)
+ rstatus = &rep;
+
+ *rstatus = 0;
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ serrno = errno;
+ errno = 0;
+#endif
+
+#if defined(_KERNEL) || defined(_STANDALONE) || \
+ defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY)
+ im = __WRAPPED(nptr, endptr, base);
+#else
+ im = __WRAPPED_L(nptr, endptr, base, loc);
+#endif
+
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+ *rstatus = errno;
+ errno = serrno;
+#endif
+
+ if (*rstatus == 0) {
+ /* No digits were found */
+ if (nptr == *endptr)
+ *rstatus = ECANCELED;
+ /* There are further characters after number */
+ else if (**endptr != '\0')
+ *rstatus = ENOTSUP;
+ }
+
+ if (im < lo) {
+ if (*rstatus == 0)
+ *rstatus = ERANGE;
+ return lo;
+ }
+ if (im > hi) {
+ if (*rstatus == 0)
+ *rstatus = ERANGE;
+ return hi;
+ }
+
+ return im;
+}
+
+#if !defined(_KERNEL) && !defined(_STANDALONE) && \
+ !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY)
+__TYPE
+_FUNCNAME(const char * /*restrict*/ nptr, char ** /*restrict*/ endptr, int base,
+ __TYPE lo, __TYPE hi, int * rstatus)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi,
+ rstatus, _current_locale());
+}
+
+__TYPE
+INT_FUNCNAME(, _FUNCNAME, _l)(const char * /*restrict*/ nptr,
+ char ** /*restrict*/ endptr, int base,
+ __TYPE lo, __TYPE hi, int * rstatus, locale_t loc)
+{
+ return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi,
+ rstatus, loc);
+}
+#endif
diff --git a/features/strto/mkc_strtoi.c b/features/strto/mkc_strtoi.c
new file mode 100644
index 0000000..f798059
--- /dev/null
+++ b/features/strto/mkc_strtoi.c
@@ -0,0 +1,75 @@
+/* $NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2021 Aleksey Cheusov <vle@gmx.net>. All rights reserved.
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Created by Kamil Rytarowski, based on ID:
+ * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+/*
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: strtoi.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+*/
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+
+#if defined(_KERNEL)
+#include <sys/param.h>
+#include <sys/types.h>
+#include <lib/libkern/libkern.h>
+#elif defined(_STANDALONE)
+#include <sys/param.h>
+#include <sys/types.h>
+#include <lib/libkern/libkern.h>
+#include <lib/libsa/stand.h>
+#else
+#include <stddef.h>
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#endif
+
+#define _FUNCNAME strtoi
+#define __TYPE intmax_t
+#define __WRAPPED strtoimax
+
+//#include "mkc_macro.h"
+#define _STANDALONE
+#include "mkc_strtoi.h"
+#include "mkc__strtoi.h"
+
+#ifdef _LIBC
+__weak_alias(strtoi, _strtoi)
+__weak_alias(strtoi_l, _strtoi_l)
+#endif
diff --git a/features/strto/mkc_strtou.c b/features/strto/mkc_strtou.c
new file mode 100644
index 0000000..508f96a
--- /dev/null
+++ b/features/strto/mkc_strtou.c
@@ -0,0 +1,75 @@
+/* $NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $ */
+
+/*-
+ * Copyright (c) 2021 Aleksey Cheusov <vle@gmx.net>. All rights reserved.
+ * Copyright (c) 2005 The DragonFly Project. All rights reserved.
+ * Copyright (c) 2003 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Created by Kamil Rytarowski, based on ID:
+ * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+/*
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: strtou.c,v 1.2 2015/05/01 14:17:56 christos Exp $");
+*/
+
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+
+#if defined(_KERNEL)
+#include <sys/param.h>
+#include <sys/types.h>
+#include <lib/libkern/libkern.h>
+#elif defined(_STANDALONE)
+#include <sys/param.h>
+#include <sys/types.h>
+#include <lib/libkern/libkern.h>
+#include <lib/libsa/stand.h>
+#else
+#include <stddef.h>
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#endif
+
+#define _FUNCNAME strtou
+#define __TYPE uintmax_t
+#define __WRAPPED strtoumax
+
+//#include "mkc_macro.h"
+#define _STANDALONE
+#include "mkc_strtou.h"
+#include "mkc__strtoi.h"
+
+#ifdef _LIBC
+__weak_alias(strtou, _strtou)
+__weak_alias(strtou_l, _strtou_l)
+#endif
diff --git a/mk/mkc_imp.compiler_settings.mk b/mk/mkc_imp.compiler_settings.mk
index e6561f6..ce6a040 100644
--- a/mk/mkc_imp.compiler_settings.mk
+++ b/mk/mkc_imp.compiler_settings.mk
@@ -2,7 +2,7 @@
### C variables
CFLAGS.dflt.clang = -Qunused-arguments -Werror=implicit-function-declaration
CFLAGS.dflt.icc = -we147 -we10006 # 147 is required for MKC_CHECK_PROTOTYPES
-CFLAGS.dflt.sunpro = -errtags
+CFLAGS.dflt.sunpro = -errtags -errwarn=E_ATTRIBUTE_UNKNOWN
CFLAGS.warnerr.gcc = -Werror
CFLAGS.warnerr.clang = -Werror
diff --git a/mk/mkc_imp.compiler_type.mk b/mk/mkc_imp.compiler_type.mk
index eb53461..9f50d10 100644
--- a/mk/mkc_imp.compiler_type.mk
+++ b/mk/mkc_imp.compiler_type.mk
@@ -6,6 +6,7 @@
!empty(MKC_CHECK_CXX_OPTS:U) || !empty(MKC_CHECK_CXXLD_OPTS:U)
src_type += cxx
LDREAL ?= ${CXX}
+LDFLAGS += ${CXXFLAGS.std.${CXXSTD}.${CXX_TYPE}}
.endif
.endif
diff --git a/mk/mkc_imp.final.mk b/mk/mkc_imp.final.mk
index e63e596..36c9af7 100644
--- a/mk/mkc_imp.final.mk
+++ b/mk/mkc_imp.final.mk
@@ -34,10 +34,10 @@ export_cmd += MAKEOBJDIR=${.OBJDIR}/${.TARGET:C/^.*-//}; \
realdo_clean: mkc_clean
mkc_clean: .PHONY
-.if ${CLEANFILES:U} != ""
+.if !empty(CLEANFILES)
-${CLEANFILES_CMD} ${CLEANFILES}
.endif
-.if ${CLEANDIRS:U} != ""
+.if !empty(CLEANDIRS)
-${CLEANDIRS_CMD} ${CLEANDIRS}
.endif
@@ -49,13 +49,19 @@ errorcheck: configure
realdo_cleandir: mkc_cleandir
mkc_cleandir:
-.if ${CLEANFILES:U} != "" || ${CLEANDIRFILES:U} != ""
+.if !empty(CLEANFILES) || !empty(CLEANDIRFILES)
-${CLEANFILES_CMD} ${CLEANDIRFILES} ${CLEANFILES}
.endif
-.if ${CLEANDIRS:U} != "" || ${CLEANDIRDIRS:U} != ""
+.if !empty(CLEANDIRS) || !empty(CLEANDIRDIRS)
-${CLEANDIRS_CMD} ${CLEANDIRDIRS} ${CLEANDIRS}
.endif
+#####
+realdo_installdirs:
+.if !empty(INSTALLDIRS)
+ ${INSTALL} ${INSTALL_FLAGS} -d -m ${DIRMODE} ${INSTALLDIRS:O:u}
+.endif
+
##########
# pre_, do_, post_ targets
.for t in ${ALLTARGETS}
diff --git a/mk/mkc_imp.foreign_autotools.mk b/mk/mkc_imp.foreign_autotools.mk
index e01166f..a002277 100644
--- a/mk/mkc_imp.foreign_autotools.mk
+++ b/mk/mkc_imp.foreign_autotools.mk
@@ -40,7 +40,7 @@ _CONFIGURE_ARGS = --prefix ${PREFIX:Q} --bindir=${BINDIR:Q} \
_CONFIGURE_ENV = CC=${CC:Q} CFLAGS=${_CFLAGS:Q} \
CXX=${CXX:Q} CXXFLAGS=${_CXXFLAGS:Q} \
- CPPFLAGS=${_CPPFLAGS:Q} \
+ CPPFLAGS=${_CPPFLAGS:Q} MAKE=${AT_MAKE} \
LDFLAGS=${LDFLAGS:Q} LIBS=${LDADD:Q} CPP=${CPP:Q} ${AT_CONFIGURE_ENV}
_AT_MAKE_ENV = ${DESTDIR:DDESTDIR=${DESTDIR:Q}} ${AT_MAKE_ENV}
diff --git a/mk/mkc_imp.mk b/mk/mkc_imp.mk
index 133af66..3b92089 100644
--- a/mk/mkc_imp.mk
+++ b/mk/mkc_imp.mk
@@ -72,7 +72,6 @@ realdo_uninstall:
-${UNINSTALL} ${UNINSTALLFILES}
realdo_installdirs:
- if test -n "${INSTALLDIRS:O:u}"; then ${INSTALL} ${INSTALL_FLAGS} -d -m ${DIRMODE} ${INSTALLDIRS:O:u}; fi
filelist:
@for d in ${UNINSTALLFILES:O:u}; do \
diff --git a/mk/mkc_imp.pkg-config.mk b/mk/mkc_imp.pkg-config.mk
index 780d4d1..3de048c 100644
--- a/mk/mkc_imp.pkg-config.mk
+++ b/mk/mkc_imp.pkg-config.mk
@@ -3,13 +3,10 @@
# See LICENSE file in the distribution.
############################################################
-.if !empty(MKC_REQUIRE_PKGCONFIG)
-MKC_CHECK_PKGCONFIG += ${MKC_REQUIRE_PKGCONFIG}
-.endif
+MKC_CHECK_PKGCONFIG += ${MKC_REQUIRE_PKGCONFIG:U}
.if ${MKCHECKS} == "yes" && !empty(MKC_CHECK_PKGCONFIG)
-MKC_CHECK_PKGCONFIG += ${MKC_REQUIRE_PKGCONFIG:U}
MKC_REQUIRE_PROGS += pkg-config
.include "mkc.conf.mk"
diff --git a/mk/mkc_imp.platform.sys.mk b/mk/mkc_imp.platform.sys.mk
index 85bb7d9..d172af6 100644
--- a/mk/mkc_imp.platform.sys.mk
+++ b/mk/mkc_imp.platform.sys.mk
@@ -103,14 +103,24 @@ _full_type != env ${mkc.cc_type.environ} mkc_check_compiler ${"${c}" ==
${c:tu}_TYPE := ${_full_type:[1]}
${c:tu}_VERSION := ${_full_type:[2]}
. undef _full_type
-_mkfile=mkc_imp.${c}_${${c:tu}_TYPE}-${${c:tu}_VERSION}.mk
-. if exists(${HOME}/.mk-c/${_mkfile})
-.warning "Directory ~/.mk-c is deprecated since 2020-12-11, please rename it to ~/.mkcmake"
-. include "${HOME}/.mk-c/${_mkfile}"
+_mkfile:=mkc_imp.${c}_${${c:tu}_TYPE}-${${c:tu}_VERSION}.mk
+. if exists(${_MKFILESDIR}/${_mkfile})
+ _full_mkfile:=${_MKFILESDIR}/${_mkfile}
+. elif exists(${HOME}/.mk-c/${_mkfile})
+. warning "Directory ~/.mk-c is deprecated since 2020-12-11, please rename it to ~/.mkcmake"
+ _full_mkfile:=${HOME}/.mk-c/${_mkfile}
. elif exists(${HOME}/.mkcmake/${_mkfile})
-. include "${HOME}/.mkcmake/${_mkfile}"
-. elif exists(${_MKFILESDIR}/${_mkfile})
-. include "${_MKFILESDIR}/${_mkfile}"
+ _full_mkfile:=${HOME}/.mkcmake/${_mkfile}
+. endif
+. if defined(_full_mkfile)
+ _ != test ${_full_mkfile} -ot ${.PARSEDIR}/${.PARSEFILE}; echo $$?
+. if ${_} == 0 && !defined(MK_C_PROJECT) && !defined(compiler_settings)
+. error '${_full_mkfile} is older than ${.PARSEDIR}/${.PARSEFILE}, please update it using "mkc_compiler_settings" utility'
+. endif
+. undef _
+. if !defined(compiler_settings)
+. include "${_full_mkfile}"
+. endif
. elif !defined(MK_C_PROJECT) && empty(compiler_settings)
. if ${MKCOMPILERSETTINGS:Uno:tl} == "yes"
_ != env CC= CXX= ${c:tu}=${${c:tu}} mkc_compiler_settings
@@ -119,6 +129,8 @@ _ != env CC= CXX= ${c:tu}=${${c:tu}} mkc_compiler_settings
. error 'Settings for ${${c:tu}_TYPE}-${${c:tu}_VERSION} is not available, run "mkc_compiler_settings" utility'
. endif
. endif # exists(...)
+
+. undef _full_mkfile
. undef _mkfile
. endfor # .for c in ${src_type}
.endif # cleandir|distclean|...
@@ -311,13 +323,13 @@ CLEANFILES += ${EXPORT_SYMBOLS}.tmp
lib${LIB}${SHLIB_EXTFULL}: ${EXPORT_SYMBOLS}.tmp
${EXPORT_SYMBOLS}.tmp: ${EXPORT_SYMBOLS}
awk 'BEGIN {print "{ global:"} \
- {print $$0 ";"} \
+ {sub(/#.*/, ""); if (NF>0) { $$1=$$1; print $$0 ";"} } \
END {print "local: *; };"}' ${.ALLSRC} > ${.TARGET}
.elif ${LD_TYPE} == "darwinld"
CLEANFILES += ${EXPORT_SYMBOLS}.tmp
lib${LIB}${SHLIB_EXTFULL}: ${EXPORT_SYMBOLS}.tmp
${EXPORT_SYMBOLS}.tmp: ${EXPORT_SYMBOLS}
- awk '{print "_" $$0}' ${.ALLSRC} > ${.TARGET}
+ awk '{sub(/#.*/, ""); if (NF>0) { $$1=$$1; print "_" $$0}}' ${.ALLSRC} > ${.TARGET}
.endif # sunld or darwinld
LDFLAGS.expsym.gnuld = --version-script ${EXPORT_SYMBOLS}.tmp
diff --git a/scripts/mk-configure.7.in b/scripts/mk-configure.7.in
index afb42a2..8123ec6 100644
--- a/scripts/mk-configure.7.in
+++ b/scripts/mk-configure.7.in
@@ -18,7 +18,7 @@
.sp
..
.\" ------------------------------------------------------------------
-.TH MK-CONFIGURE 7 "Jan 05, 2021" "" ""
+.TH MK-CONFIGURE 7 "Jan 21, 2021" "" ""
.SH NAME
mk-configure \- lightweight replacement for GNU autotools
.SH DESCRIPTION
@@ -222,11 +222,12 @@ mipspro MIPSpro C compiler
C compiler version.
.RI < "I" >
.IP CCSTD
-C language standard required by program. Supported options:
+Add C language standard command line option to the compiler.
+Supported options:
.IR c89 ", " gnu89 " (C89 with GNU extensions), " c99 ", " gnu99 \
" (C99 with GNU extensions), " c11 ", " gnu11 " (C89 with GNU extensions), " \
c17 ", " gnu17 " (C17 with GNU extensions)."
-If compiler is not known for mk-configure developer or does not
+If compiler is not known for mk-configure or does not
support appropriate option, no additional options are applied.
.RI < M >
.RI [ "" ]
@@ -353,11 +354,13 @@ Additional flags to the compiler when creating C++ objects.
Similar to CXXOPTS but for project ${PROJECTNAME}.
.RI < "U" >
.IP CXXSTD
-C++ language standard required by program. Supported options:
-.IR c89 ", " gnu89 " (C89 with GNU extensions), " c99 ", " gnu99 \
-" (C99 with GNU extensions), " c11 ", " gnu11 " (C89 with GNU extensions), " \
-c17 ", " gnu17 " (C17 with GNU extensions)."
-If compiler is not known for mk-configure developer or does not
+Add C++ language standard command line option to the compiler and linker.
+Supported options:
+.IR c++98 ", " gnu++98 " (C++98 with GNU extensions), "
+.IR c++11 ", " gnu++11 " (C++11 with GNU extensions), "
+.IR c++14 ", " gnu++14 " (C++14 with GNU extensions), "
+.IR c++17 ", " gnu++17 " (C++17 with GNU extensions)"
+If compiler is not known for mk-configure or does not
support appropriate option, no additional options are applied.
.RI < M >
.RI [ "" ]
@@ -876,7 +879,8 @@ See LIBDEPS in section
.BR mk.subprj.mk .
.IP EXPORT_SYMBOLS
Only symbols listed in a specified file (one symbol per line) are
-exported. This variable has no effect on some platforms. By default
+exported. Empty lines and comments started with # symbol
+are ignored. This variable has no effect on some platforms. By default
all symbols are exported.
.RI < "M" >
[]
@@ -1388,7 +1392,7 @@ is "yes", equivalent define leads to the same results.
MKC_CHECK_FUNCS1 += htobe32:sys/endian.h
MKC_FUNC_OR_DEFINE.htobe32 += yes
Res: HAVE_FUNC2.fgetln.stdio_h = 1
- HAVE_FUNC6.pselect.sys.select_h = 1
+ HAVE_FUNC6.pselect.sys_select_h = 1
HAVE_FUNC1.htobe32.sys_endian_h=1
CFLAGS += -DHAVE_FUNC2_FGETLN_STDIO_H=1 \\
+= -DHAVE_FUNC6_PSELECT_SYS_SELECT_H=1 \\
@@ -1620,10 +1624,11 @@ functions available in *BSD.
.B dprintf
This feature provides dprintf(3).
.TP
-.B efunc
-This feature provides esetfunc(3), efopen(3), ecalloc(3),
-emalloc(3), erealloc(3), estrdup(3), estrndup(3), estrlcpy(3),
-estrlcat(3), easprintf(3), and evasprintf(3) functions from NetBSD.
+.B efun
+This feature provides esetfunc(3), efopen(3), ecalloc(3), emalloc(3),
+erealloc(3), ereallocarr(3), estrdup(3), estrndup(3), estrlcpy(3),
+estrlcat(3), easprintf(3), estrtoi(3), estrtou(3)
+and evasprintf(3) functions from NetBSD.
.TP
.B err
This feature provides err(3), errx(3), verr(3) and verrx(3) BSD-isms.
@@ -1634,6 +1639,9 @@ This feature provides errc(3) and verrc(3) BSD-isms.
.B fgetln
This feature provides fgetln(3) BSD-ism.
.TP
+.B fparseln
+This feature provides fparseln(3) BSD-ism.
+.TP
.B fts
This feature provides fts_open(3), fts_read(3) etc. functions
available on BSDs and Linux. If it is absent on your system,
@@ -1670,6 +1678,37 @@ LDADD. Most UNIX-like systems have libm but Haiku, for example, does
not. mkc_imp.f_libm.mk checks whether libm library is available and if yes,
-lm is added to LDADD.
.TP
+.B macro
+This feature provides the following macro stolen from NetBSD.
+.I __aligned(x)
+defined as
+.I "__attribute__((aligned(x)))"
+if supported by compiler,
+.I __always_inline
+defined as
+.I "__attribute__((always_inline))"
+if supported by compiler,
+.I __arraycount(a)
+defined as
+.I "(sizeof(__a)/sizeof(__a[0]))",
+.I __constfunc
+defined as
+.I "__attribute__((const))"
+if supported by compiler,
+.I __dead
+defined as
+.I "__attribute__((noreturn))"
+if supported by compiler,
+.IR "MIN(a,b)" " and " "MAX(a,b),"
+.I __pure
+defined as
+.I "__attribute__((pure))"
+if supported by compiler,
+.I "__printflike(n,m)"
+defined as
+.I "__attribute__((format (printf, n, m)))"
+if supported by compiler.
+.TP
.B posix_getopt
It is well-known that glibc getopt(3) does not conform to POSIX by default.
This feature provides POSIX-ly correct getopt.
@@ -1692,6 +1731,12 @@ sys/tree.h and appropriate macroses are available. If yes, mkc_RB.h
and mkc_SPLAY.h include system-wide sys/tree.h, otherwise NetBSD
version of sys/tree.h provided by mk-configure is included.
.TP
+.B reallocarr
+This feature provides reallocarr(3) function from NetBSD.
+.TP
+.B reallocarray
+This feature provides reallocarray(3) function from OpenBSD.
+.TP
.B shquote
This feature provides shquote(3) function from NetBSD.
.TP
@@ -1719,6 +1764,21 @@ This feature provides strndup(3) from POSIX.
.B strsep
This features provides strsep(3) and stresep(3) functions.
.TP
+.B strtoi
+This feature provides strtoi(3) function
+introduced in NetBSD.
+.TP
+.B strtou
+This feature provides strtoi(3) function
+introduced in NetBSD.
+.TP
+.B vis
+This feature provides vis(3), nvis(3), svis(3), snvis(3), strvis(3),
+strnvis(3), strsvis(3), strsnvis(3), strvisx(3), strnvisx(3),
+strenvisx(3), strsvisx(3), strsnvisx(3), strsenvisx(3),
+strunvis(3), strnunvis(3), strunvisx(3), strnunvisx(3) and
+unvis(3) from NetBSD.
+.TP
.B warn
This feature provides warn(3), warnx(3), vwarn(3) and vwarnx(3) BSD-isms.
.RE
diff --git a/scripts/mkc_check_custom.in b/scripts/mkc_check_custom.in
index 4b4055b..e4b7172 100755
--- a/scripts/mkc_check_custom.in
+++ b/scripts/mkc_check_custom.in
@@ -1,4 +1,5 @@
#!@SH@
+# -*- mode: sh; -*-
############################################################
# Copyright (c) 2009-2020 by Aleksey Cheusov
diff --git a/scripts/mkc_check_version.in b/scripts/mkc_check_version.in
index 79ca154..245f25d 100755
--- a/scripts/mkc_check_version.in
+++ b/scripts/mkc_check_version.in
@@ -1,4 +1,5 @@
#!@AWK@ -f
+# -*- mode: awk; -*-
############################################################
# Copyright (c) 2009-2010 by Aleksey Cheusov
diff --git a/scripts/mkc_compiler_settings.in b/scripts/mkc_compiler_settings.in
index d8630ae..24521e0 100644
--- a/scripts/mkc_compiler_settings.in
+++ b/scripts/mkc_compiler_settings.in
@@ -1,4 +1,5 @@
#!@SH@
+# -*- mode: sh; -*-
set -e
diff --git a/scripts/mkc_get_deps.in b/scripts/mkc_get_deps.in
index 74c8092..6b3b6e5 100755
--- a/scripts/mkc_get_deps.in
+++ b/scripts/mkc_get_deps.in
@@ -1,4 +1,5 @@
#!@AWK@ -f
+# -*- mode: awk; -*-
# Usage: mkc_get_deps
# $1 -- project name
diff --git a/scripts/mkc_install.in b/scripts/mkc_install.in
index 1d38b6e..769a157 100755
--- a/scripts/mkc_install.in
+++ b/scripts/mkc_install.in
@@ -1,4 +1,5 @@
#!@SH@
+# -*- mode: sh; -*-
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh)
@@ -119,7 +120,6 @@ copy_file () {
$doit $stripcmd "$dsttmp"
$doit $chmodcmd "$dsttmp"
- $doit $rmcmd -f "$dst"
$doit $mvcmd "$dsttmp" "$dst"
}
diff --git a/tests/mkc_features/features.mk b/tests/mkc_features/features.mk
index 2ccfd56..e266f1e 100644
--- a/tests/mkc_features/features.mk
+++ b/tests/mkc_features/features.mk
@@ -1,4 +1,5 @@
MKC_FEATURES += strlcat strlcpy getline progname fgetln err warn libm \
getdelim strndup libdl RB SLIST SIMPLEQ STAILQ LIST TAILQ CIRCLEQ SPLAY \
bswap dprintf efun strsep errc posix_getopt shquote pwdgrp \
- raise_default_signal reallocarray fparseln vis fts humanize_number
+ raise_default_signal reallocarr reallocarray fparseln vis fts \
+ humanize_number strtoi strtou
diff --git a/tests/mkc_features/tool/test_features1.cxx b/tests/mkc_features/tool/test_features1.cxx
index a41e7c5..715ae7b 100644
--- a/tests/mkc_features/tool/test_features1.cxx
+++ b/tests/mkc_features/tool/test_features1.cxx
@@ -24,6 +24,7 @@
#include "mkc_strsep.h"
#include "mkc_posix_getopt.h"
#include "mkc_raise_default_signal.h"
+#include "mkc_reallocarr.h"
#include "mkc_reallocarray.h"
#include "mkc_fparseln.h"
#include "mkc_vis.h"
@@ -31,6 +32,18 @@
#include "mkc_humanize_number.h"
#include "mkc_shquote.h"
#include "mkc_pwdgrp.h"
+#include "mkc_macro.h"
+#include "mkc_strtoi.h"
+#include "mkc_strtou.h"
+
+extern int myprintf(void *my_object, const char *my_format, ...) __printflike(2, 3);
+extern int square(int v) __constfunc;
+__always_inline static int cube(int v)
+{
+ return v * v * v;
+}
+
+int aligned_array[16] __aligned(64);
int main(int argc, char** argv)
{
@@ -62,9 +75,13 @@ int main(int argc, char** argv)
easprintf(&ptr, "%s", "papa");
strsep(NULL, "\0");
stresep(NULL, " \t", '\0');;
+ printf("%p\n", __UNCONST(ptr));
free(ptr);
+ ptr = NULL;
+ ereallocarr(&ptr, 10, 32);
getopt(0, NULL, NULL);
raise_default_signal(15);
+ reallocarr(NULL, 0, 0);
reallocarray(NULL, 0, 0);
fparseln(NULL, NULL, NULL, "\\\\#", 0);
vis(NULL, 0, 0, 0);
@@ -93,6 +110,14 @@ int main(int argc, char** argv)
group_from_gid(0, 0);
uid_from_user(NULL, NULL);
gid_from_group(NULL, NULL);
+ printf("cube(2)=%d\n", cube(2));
+ printf("aligned_array: %p\n", &aligned_array);
+ printf("MIN(1,2), MIN(1,2): %d, %d\n", MIN(1,2), MAX(1,2));
+ printf("arraycount(aligned_array)=%d\n", __arraycount(aligned_array));
+ strtoi("5", NULL, 10, 0, 9, NULL);
+ strtou("5", NULL, 10, 0, 9, NULL);
+ estrtoi("5", 10, 0, 9);
+ estrtou("5", 10, 0, 9);
return 0;
}