DASH Shell discussions
 help / color / mirror / Atom feed
From: Brian Koropoff <bkoropoff@gmail.com>
To: dash@vger.kernel.org
Subject: [PATCH 3/3] Port to HP-UX
Date: Tue, 18 Jan 2011 21:16:02 -0800	[thread overview]
Message-ID: <1295414162.6486.5.camel@gemini> (raw)
In-Reply-To: <1295413636.4278.28.camel@gemini>

- strtoimax and strtoumax are macros and not functions,
   so switch to using AC_CHECK_DECLS in configure.ac
   to find them.

 - HP-UX lacks strsignal() and sys_siglist.  Check for
   sys_siglist in configure.ac and #ifdef around it.

 - HP-UX's vsnprintf() completely violates the standard
   by returning -1 (and neglecting to set errno) if the
   buffer is not large enough rather than returning the
   size necessary.  Work around it by (yuck) reallocating
   a dynamic buffer until it succeeds so we can return
   the expected result.

 - HP-UX needs _LARGEFILE64_SOURCE to be defined for open64()
   and friends to be available.  This seems to be safe to
   define everywhere, so do so.

 - The nl program doesn't like spaces between flags and their
   arguments, so remove them in mkbuiltins.

Signed-off-by: Brian Koropoff <bkoropoff@gmail.com>
---
 configure.ac    |   16 +++++++++++++---
 src/Makefile.am |    3 ++-
 src/mkbuiltins  |    2 +-
 src/output.c    |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/system.c    |    2 ++
 src/system.h    |    4 ++--
 6 files changed, 72 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0a60055..07c2726 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,7 +43,7 @@ AC_ARG_ENABLE(glob, AS_HELP_STRING(--enable-glob, [Use glob(3) from libc]))
 dnl Checks for libraries.
 
 dnl Checks for header files.
-AC_CHECK_HEADERS(alloca.h paths.h)
+AC_CHECK_HEADERS(alloca.h paths.h unistd.h signal.h)
 
 dnl Check for declarations
 AC_CHECK_DECL([_PATH_BSHELL],,AC_DEFINE_UNQUOTED([_PATH_BSHELL], "/bin/sh", [Define to system shell path]),[
@@ -65,6 +65,17 @@ AC_CHECK_DECL([_PATH_TTY],,AC_DEFINE_UNQUOTED([_PATH_TTY], "/dev/tty", [Define t
 dnl Some systems lack isblank
 AC_CHECK_DECLS([isblank],,,[#include <ctype.h>])
 
+dnl strtoimax is a macro on some systems
+AC_CHECK_DECLS([strtoimax, strtoumax],,,[#include <inttypes.h>])
+
+dnl Check for sys_siglist
+AC_CHECK_DECLS([sys_siglist], [], [],
+          [#include <signal.h>
+          #ifdef HAVE_UNISTD_H
+          # include <unistd.h>
+          #endif
+          ])
+
 dnl Check for types and sizes
 AC_CHECK_SIZEOF([intmax_t])
 AC_CHECK_SIZEOF([long long int])
@@ -82,8 +93,7 @@ AC_DEFINE_UNQUOTED([INTMAX_FSTR], "$intmax_fstr", [Define to printf format strin
 dnl Checks for library functions.
 AC_CHECK_FUNCS(bsearch faccessat getpwnam getrlimit imaxdiv isalpha killpg \
 	       mempcpy \
-	       sigsetmask stpcpy strchrnul strsignal strtod strtoimax \
-	       strtoumax sysconf)
+	       sigsetmask stpcpy strchrnul strsignal strtod sysconf)
 
 if test "$enable_fnmatch" = yes; then
 	use_fnmatch=
diff --git a/src/Makefile.am b/src/Makefile.am
index ba68d55..b99daf1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,8 @@ COMMON_CFLAGS = -Wall
 COMMON_CPPFLAGS = \
 	-include $(top_builddir)/config.h \
 	-DBSD=1 -DSHELL \
-	-DIFS_BROKEN
+	-DIFS_BROKEN \
+	-D_LARGEFILE64_SOURCE
 
 AM_CFLAGS = $(COMMON_CFLAGS)
 AM_CPPFLAGS = $(COMMON_CPPFLAGS)
diff --git a/src/mkbuiltins b/src/mkbuiltins
index 495274e..f6260b2 100644
--- a/src/mkbuiltins
+++ b/src/mkbuiltins
@@ -99,7 +99,7 @@ cat <<\!
  */
 
 !
-sed 's/	-[a-z]*//' $temp2 | nl -b a -v 0 | LC_COLLATE=C sort -u -k 3,3 |
+sed 's/	-[a-z]*//' $temp2 | nl -ba -v0 | LC_COLLATE=C sort -u -k 3,3 |
 tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ |
 	awk '{	printf "#define %s (builtincmd + %d)\n", $3, $1}'
 printf '\n#define NUMBUILTINS %d\n' $(wc -l < $temp2)
diff --git a/src/output.c b/src/output.c
index 3425603..db4a8a7 100644
--- a/src/output.c
+++ b/src/output.c
@@ -372,6 +372,56 @@ __closememout(void) {
 #endif
 #endif
 
+#ifdef __hpux
+static int
+xvsnprintf(char *outbuf, size_t length, const char *fmt, va_list ap)
+{
+	int ret;
+	char* dummy = NULL;
+	char* dummy_new = NULL;
+	size_t dummy_len = 8;
+	va_list ap_mine;
+
+	if (length > 0) {
+		INTOFF;
+		va_copy(ap_mine, ap);
+                errno = 0;
+		ret = vsnprintf(outbuf, length, fmt, ap_mine);
+		va_end(ap_mine);
+		INTON;
+	} else {
+		ret = -1;
+		errno = 0;
+	}
+
+	if (ret < 0 && errno == 0) {
+		do {
+			dummy_len *= 2;
+			dummy_new = realloc(dummy, dummy_len);
+			if (!dummy_new) {
+				ret = -1;
+				errno = ENOMEM;
+				break;
+			}
+			dummy = dummy_new;
+			INTOFF;
+			va_copy(ap_mine, ap);
+                        errno = 0;
+			ret = vsnprintf(dummy, dummy_len, fmt, ap_mine);
+			va_end(ap_mine);
+			INTON;
+		} while (ret < 0 && errno == 0);
+
+		if (ret >= 0 && length) {
+			memcpy(outbuf, dummy, length);
+		}
+		if (dummy) free(dummy);
+	}
+
+	return ret;
+}
+
+#else
 
 static int
 xvsnprintf(char *outbuf, size_t length, const char *fmt, va_list ap)
@@ -397,3 +447,5 @@ xvsnprintf(char *outbuf, size_t length, const char *fmt, va_list ap)
 	INTON;
 	return ret;
 }
+
+#endif
diff --git a/src/system.c b/src/system.c
index 844a641..dbf4601 100644
--- a/src/system.c
+++ b/src/system.c
@@ -92,8 +92,10 @@ char *strsignal(int sig)
 {
 	static char buf[19];
 
+#if HAVE_DECL_SYS_SIGLIST
 	if ((unsigned)sig < NSIG && sys_siglist[sig])
 		return (char *)sys_siglist[sig];
+#endif
 	fmtstr(buf, sizeof(buf), "Signal %d", sig); 
 	return buf;
 }
diff --git a/src/system.h b/src/system.h
index e712605..b1e9b63 100644
--- a/src/system.h
+++ b/src/system.h
@@ -70,11 +70,11 @@ static inline double strtod(const char *nptr, char **endptr)
 }
 #endif
 
-#ifndef HAVE_STRTOIMAX
+#if !HAVE_DECL_STRTOIMAX
 #define strtoimax strtoll
 #endif
 
-#ifndef HAVE_STRTOUMAX
+#if !HAVE_DECL_STRTOUMAX
 #define strtoumax strtoull
 #endif
 
-- 
1.7.1



  parent reply	other threads:[~2011-01-19  5:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19  5:07 Portability patches Brian Koropoff
2011-01-19  5:15 ` [PATCH 1/3] Port to Solaris Brian Koropoff
2011-01-21 13:06   ` Jilles Tjoelker
2011-03-10 12:16     ` Herbert Xu
2011-03-13  1:18       ` Brian Koropoff
2011-03-13  1:25         ` [PATCH] " Brian Koropoff
2011-03-15  7:36           ` Herbert Xu
2011-01-19  5:15 ` [PATCH 2/3] Port to AIX Brian Koropoff
2011-03-10 12:25   ` Herbert Xu
2011-01-19  5:16 ` Brian Koropoff [this message]
2011-03-10 12:26   ` [PATCH 3/3] Port to HP-UX Herbert Xu
2011-03-12 23:54     ` Brian Koropoff
2011-03-15  7:38       ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295414162.6486.5.camel@gemini \
    --to=bkoropoff@gmail.com \
    --cc=dash@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox