diff options
author | Brian Koropoff <bkoropoff@gmail.com> | 2011-03-15 15:35:14 +0800 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2011-06-03 18:44:14 +0200 |
commit | d790802dfa92ea145ef0da18f790609db2fccaeb (patch) | |
tree | 330e00aa62cb5a797890e491ae02291e647526a7 | |
parent | 0760036ff9167812c9498ed5a519147ea952fa11 (diff) | |
download | klibc-d790802dfa92ea145ef0da18f790609db2fccaeb.tar.gz |
[klibc] [SHELL] Port to Solaris
- Solaris lacks paths.h and the various _PATH_* #defines.
Check for them in configure.ac and fall back on the
usual suspects when they are missing.
- Older Solaris lacks isblank(), and versions that have it
use a macro. Check for the declaration in configure.ac
and fall back on a naive version when missing.
- Older Solaris does not support %jd (intmax_t) in format
strings, but it does support the PRIdMAX macro from inttypes.h.
Do a configure check for PRIdMAX and use it in the code.
If it doesn't exist, define it to "lld" when sizeof(long long)
equals sizeof(intmax_t) as this is more likely to work on
older systems. Otherwise, use "jd" and hope for the best.
- Older Solaris lacks stdint.h, but inttypes.h provides the
same types and works on all platforms I've tried dash on,
so just use it instead.
- Older Solaris doesn't like it when vsnprintf() is passed
a NULL buffer (in violation of the POSIX spec, of course).
Pass a 1-byte dummy buffer instead.
- Solaris lacks tempfile and mktemp programs. Fall back on a
"good-enough" custom function in mkbuiltins.
Signed-off-by: Brian Koropoff <bkoropoff@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ minor merge fixup -maks ]
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/dash/arith_yacc.c | 1 | ||||
-rw-r--r-- | usr/dash/bltin/test.c | 2 | ||||
-rw-r--r-- | usr/dash/cd.c | 1 | ||||
-rw-r--r-- | usr/dash/exec.c | 2 | ||||
-rw-r--r-- | usr/dash/expand.c | 4 | ||||
-rw-r--r-- | usr/dash/expand.h | 2 | ||||
-rw-r--r-- | usr/dash/histedit.c | 2 | ||||
-rw-r--r-- | usr/dash/jobs.c | 2 | ||||
-rw-r--r-- | usr/dash/jobs.h | 2 | ||||
-rw-r--r-- | usr/dash/miscbltin.c | 4 | ||||
-rw-r--r-- | usr/dash/mkbuiltins | 15 | ||||
-rw-r--r-- | usr/dash/mystring.c | 2 | ||||
-rw-r--r-- | usr/dash/mystring.h | 2 | ||||
-rw-r--r-- | usr/dash/output.c | 14 | ||||
-rw-r--r-- | usr/dash/system.c | 8 | ||||
-rw-r--r-- | usr/dash/system.h | 4 | ||||
-rw-r--r-- | usr/dash/var.c | 4 | ||||
-rw-r--r-- | usr/dash/var.h | 2 |
18 files changed, 60 insertions, 13 deletions
diff --git a/usr/dash/arith_yacc.c b/usr/dash/arith_yacc.c index 6c5a72009c5fa..bf2183034acc3 100644 --- a/usr/dash/arith_yacc.c +++ b/usr/dash/arith_yacc.c @@ -33,7 +33,6 @@ */ #include <inttypes.h> -#include <stdint.h> #include <stdlib.h> #include "arith_yacc.h" #include "expand.h" diff --git a/usr/dash/bltin/test.c b/usr/dash/bltin/test.c index 7888f38eeb969..90135e14e1bd5 100644 --- a/usr/dash/bltin/test.c +++ b/usr/dash/bltin/test.c @@ -12,7 +12,7 @@ #include <sys/types.h> #include <fcntl.h> -#include <stdint.h> +#include <inttypes.h> #include <stdlib.h> #include <string.h> #include <unistd.h> diff --git a/usr/dash/cd.c b/usr/dash/cd.c index ba9a1bc00f305..89c6c30c09153 100644 --- a/usr/dash/cd.c +++ b/usr/dash/cd.c @@ -37,6 +37,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <limits.h> /* * The cd and pwd commands. diff --git a/usr/dash/exec.c b/usr/dash/exec.c index b2734203924c7..194088bd5f333 100644 --- a/usr/dash/exec.c +++ b/usr/dash/exec.c @@ -37,7 +37,9 @@ #include <unistd.h> #include <fcntl.h> #include <stdlib.h> +#ifdef HAVE_PATHS_H #include <paths.h> +#endif /* * When commands are first encountered, they are entered in a hash table. diff --git a/usr/dash/expand.c b/usr/dash/expand.c index e177ee6114a09..cebeabe69dc72 100644 --- a/usr/dash/expand.c +++ b/usr/dash/expand.c @@ -42,7 +42,7 @@ #endif #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <limits.h> #include <string.h> #include <fnmatch.h> @@ -1691,7 +1691,7 @@ cvtnum(intmax_t num) int len = max_int_length(sizeof(num)); expdest = makestrspace(len, expdest); - len = fmtstr(expdest, len, "%jd", num); + len = fmtstr(expdest, len, "%" PRIdMAX, num); STADJUST(len, expdest); return len; } diff --git a/usr/dash/expand.h b/usr/dash/expand.h index 214c172374841..9cf1276fd2167 100644 --- a/usr/dash/expand.h +++ b/usr/dash/expand.h @@ -37,7 +37,7 @@ #ifndef DASH_STRLIST_H #define DASH_STRLIST_H -#include <stdint.h> +#include <inttypes.h> struct strlist { struct strlist *next; diff --git a/usr/dash/histedit.c b/usr/dash/histedit.c index 9a1e533f7d9e2..b27d6294ce08e 100644 --- a/usr/dash/histedit.c +++ b/usr/dash/histedit.c @@ -33,7 +33,9 @@ */ #include <sys/param.h> +#ifdef HAVE_PATHS_H #include <paths.h> +#endif #include <stdio.h> #include <stdlib.h> #include <unistd.h> diff --git a/usr/dash/jobs.c b/usr/dash/jobs.c index b3ed163dfdc2b..23b1b9d9a638d 100644 --- a/usr/dash/jobs.c +++ b/usr/dash/jobs.c @@ -36,7 +36,9 @@ #include <signal.h> #include <unistd.h> #include <stdlib.h> +#ifdef HAVE_PATHS_H #include <paths.h> +#endif #include <sys/types.h> #include <sys/param.h> #ifdef BSD diff --git a/usr/dash/jobs.h b/usr/dash/jobs.h index 9c095eae31e2d..953ee87127b11 100644 --- a/usr/dash/jobs.h +++ b/usr/dash/jobs.h @@ -34,7 +34,7 @@ * @(#)jobs.h 8.2 (Berkeley) 5/4/95 */ -#include <stdint.h> +#include <inttypes.h> #include <sys/types.h> /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ diff --git a/usr/dash/miscbltin.c b/usr/dash/miscbltin.c index ece66ced0220c..8be613a428b96 100644 --- a/usr/dash/miscbltin.c +++ b/usr/dash/miscbltin.c @@ -44,7 +44,7 @@ #include <unistd.h> #include <stdlib.h> #include <ctype.h> -#include <stdint.h> +#include <inttypes.h> #include <time.h> /* strtotimeval() */ #include "shell.h" @@ -465,7 +465,7 @@ static void printlim(enum limtype how, const struct rlimit *limit, out1fmt("unlimited\n"); else { val /= l->factor; - out1fmt("%jd\n", (intmax_t) val); + out1fmt("%" PRIdMAX "\n", (intmax_t) val); } } diff --git a/usr/dash/mkbuiltins b/usr/dash/mkbuiltins index 99107c2bd68cb..f562ae2216cf9 100644 --- a/usr/dash/mkbuiltins +++ b/usr/dash/mkbuiltins @@ -36,7 +36,20 @@ # @(#)mkbuiltins 8.2 (Berkeley) 5/4/95 tempfile=tempfile -if ! type tempfile > /dev/null 2>&1; then +if ! type tempfile > /dev/null 2>&1 && ! type mktemp > /dev/null 2>&1; then + _my_tempfile() + { + local index=0 + while test -f "${TMPDIR:-/tmp}/builtin.$$.$index"; do + index=`expr $index + 1` + done + + touch "${TMPDIR:-/tmp}/builtin.$$.$index" + echo "${TMPDIR:-/tmp}/builtin.$$.$index" + } + + tempfile="_my_tempfile" +elif ! type tempfile > /dev/null 2>&1; then tempfile="mktemp ${TMPDIR:-/tmp}/builtin.XXXXXX" fi diff --git a/usr/dash/mystring.c b/usr/dash/mystring.c index bbb6b776ce996..0106bd27d2fea 100644 --- a/usr/dash/mystring.c +++ b/usr/dash/mystring.c @@ -46,7 +46,7 @@ #include <errno.h> #include <inttypes.h> #include <limits.h> -#include <stdint.h> +#include <inttypes.h> #include <stdlib.h> #include "shell.h" #include "syntax.h" diff --git a/usr/dash/mystring.h b/usr/dash/mystring.h index 352252376abfe..083ea98cff7e0 100644 --- a/usr/dash/mystring.h +++ b/usr/dash/mystring.h @@ -34,7 +34,7 @@ * @(#)mystring.h 8.2 (Berkeley) 5/4/95 */ -#include <stdint.h> +#include <inttypes.h> #include <string.h> extern const char snlfmt[]; diff --git a/usr/dash/output.c b/usr/dash/output.c index 2f9b5c4c57c22..f62e7eab0b4eb 100644 --- a/usr/dash/output.c +++ b/usr/dash/output.c @@ -378,6 +378,20 @@ xvsnprintf(char *outbuf, size_t length, const char *fmt, va_list ap) { int ret; +#ifdef __sun + /* + * vsnprintf() on older versions of Solaris returns -1 when + * passed a length of 0. To avoid this, use a dummy + * 1-character buffer instead. + */ + char dummy[1]; + + if (length == 0) { + outbuf = dummy; + length = sizeof(dummy); + } +#endif + INTOFF; ret = vsnprintf(outbuf, length, fmt, ap); INTON; diff --git a/usr/dash/system.c b/usr/dash/system.c index e5bcddc06a0d8..aa1df8ac6e35e 100644 --- a/usr/dash/system.c +++ b/usr/dash/system.c @@ -170,9 +170,11 @@ int isupper(int c) { } +#if HAVE_DECL_ISBLANK int isblank(int c) { return _isblank(c); } +#endif int isgraph(int c) { @@ -189,3 +191,9 @@ int isxdigit(int c) { return _isxdigit(c); } #endif + +#if !HAVE_DECL_ISBLANK +int isblank(int c) { + return c == ' ' || c == '\t'; +} +#endif diff --git a/usr/dash/system.h b/usr/dash/system.h index 9056e163cab44..c8424f75d6c23 100644 --- a/usr/dash/system.h +++ b/usr/dash/system.h @@ -90,6 +90,10 @@ static inline int killpg(pid_t pid, int signal) long sysconf(int) __attribute__((__noreturn__)); #endif +#if !HAVE_DECL_ISBLANK +int isblank(int c); +#endif + /* * A trick to suppress uninitialized variable warning without generating any * code diff --git a/usr/dash/var.c b/usr/dash/var.c index 25c221667b5a9..aec10769af306 100644 --- a/usr/dash/var.c +++ b/usr/dash/var.c @@ -34,7 +34,9 @@ #include <unistd.h> #include <stdlib.h> +#ifdef HAVE_PATHS_H #include <paths.h> +#endif /* * Shell variables. @@ -223,7 +225,7 @@ intmax_t setvarint(const char *name, intmax_t val, int flags) int len = max_int_length(sizeof(val)); char buf[len]; - fmtstr(buf, len, "%jd", val); + fmtstr(buf, len, "%" PRIdMAX, val); setvar(name, buf, flags); return val; } diff --git a/usr/dash/var.h b/usr/dash/var.h index afdd0f6ade478..3e9568a2dc380 100644 --- a/usr/dash/var.h +++ b/usr/dash/var.h @@ -34,7 +34,7 @@ * @(#)var.h 8.2 (Berkeley) 5/4/95 */ -#include <stdint.h> +#include <inttypes.h> /* * Shell variables. |