From f9cfe6031288acf02cbdf95d370ecb38f5a929dc Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Thu, 17 Mar 2005 23:12:15 +0000
Subject: [PATCH] Add support for Solaris/x86 (bug #3064)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5199 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_zap.c             |  4 +++-
 channels/iax2-parser.c          |  2 +-
 db1-ast/hash/hash.c             |  4 ++++
 include/asterisk/channel.h      |  3 +++
 include/asterisk/logger.h       |  4 +++-
 include/asterisk/utils.h        |  3 +++
 include/solaris-compat/compat.h | 34 +++++++++++++++++++++++----------
 mkpkgconfig                     | 12 ++++++------
 res/res_agi.c                   |  3 +++
 rtp.c                           |  4 +---
 strcompat.c                     |  9 +++++++++
 utils.c                         |  1 +
 utils/Makefile                  |  5 ++++-
 utils/smsq.c                    |  5 +++++
 14 files changed, 70 insertions(+), 23 deletions(-)

diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index 2df1590f9b..b77776d75b 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -1055,7 +1055,7 @@ static int str2r2prot(char *swtype)
 }
 #endif
 
-static char *sig2str(int sig)
+static char *zap_sig2str(int sig)
 {
 	static char buf[256];
 	switch(sig) {
@@ -1111,6 +1111,8 @@ static char *sig2str(int sig)
 	}
 }
 
+#define sig2str zap_sig2str
+
 static int conf_add(struct zt_pvt *p, struct zt_subchannel *c, int index, int slavechannel)
 {
 	/* If the conference already exists, and we're already in it
diff --git a/channels/iax2-parser.c b/channels/iax2-parser.c
index edc15ec07d..66a69b447e 100755
--- a/channels/iax2-parser.c
+++ b/channels/iax2-parser.c
@@ -30,7 +30,7 @@ static int frames = 0;
 static int iframes = 0;
 static int oframes = 0;
 
-#ifdef SOLARIS
+#if defined(SOLARIS) && defined(__sparc__)
 static unsigned int get_uint32(unsigned char *p)
 {
   return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
diff --git a/db1-ast/hash/hash.c b/db1-ast/hash/hash.c
index 99592eac51..349af6c630 100755
--- a/db1-ast/hash/hash.c
+++ b/db1-ast/hash/hash.c
@@ -51,6 +51,10 @@ static char sccsid[] = "@(#)hash.c	8.9 (Berkeley) 6/16/94";
 #include <assert.h>
 #endif
 
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#endif
+
 #include <db.h>
 #include "hash.h"
 #include "page.h"
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 1ebcb30644..25b483b11b 100755
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -14,6 +14,9 @@
 #ifndef _ASTERISK_CHANNEL_H
 #define _ASTERISK_CHANNEL_H
 
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#endif
 #include <asterisk/frame.h>
 #include <asterisk/sched.h>
 #include <asterisk/chanvars.h>
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index 1f7eab5301..2e8a786b58 100755
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -13,7 +13,9 @@
 
 #ifndef _LOGGER_H
 #define _LOGGER_H
-
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#endif
 #include <stdarg.h>
 
 #if defined(__cplusplus) || defined(c_plusplus)
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 590815320a..b1b71d73e0 100755
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -12,6 +12,9 @@
 #ifndef _ASTERISK_UTIL_H
 #define _ASTERISK_UTIL_H
 
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#endif
 #include <netinet/in.h>
 #include <netdb.h>
 #include <pthread.h>
diff --git a/include/solaris-compat/compat.h b/include/solaris-compat/compat.h
index 6b304b2bae..3f448117df 100755
--- a/include/solaris-compat/compat.h
+++ b/include/solaris-compat/compat.h
@@ -8,18 +8,29 @@
 #define __P(p) p
 #endif
 
-#define LITTLE_ENDIAN 1234
-#define BIG_ENDIAN 4321
-
-#define __LITTLE_ENDIAN 1234
-#define __BIG_ENDIAN 4321
+#include <alloca.h>
+#include <strings.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <netinet/in.h>
+
+#ifndef BYTE_ORDER
+#define LITTLE_ENDIAN	1234
+#define BIG_ENDIAN	4321
 
 #ifdef __sparc__
-#define BYTE_ORDER BIG_ENDIAN
-#define __BYTE_ORDER BIG_ENDIAN
+#define BYTE_ORDER	BIG_ENDIAN
 #else
-#define BYTE_ORDER LITTLE_ENDIAN
-#define ____BYTE_ORDER BIG_ENDIAN
+#define BYTE_ORDER	LITTLE_ENDIAN
+#endif
+#endif
+
+#ifndef __BYTE_ORDER
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
+#define __BIG_ENDIAN BIG_ENDIAN
+#define __BYTE_ORDER BYTE_ORDER
 #endif
 
 #ifndef __BIT_TYPES_DEFINED__
@@ -29,6 +40,9 @@ typedef unsigned short	u_int16_t;
 typedef unsigned int	u_int32_t;
 #endif
 
+char* strsep(char** str, const char* delims);
+uint64_t
+strtoq(const char *nptr, char **endptr, int base);
 int setenv(const char *name, const char *value, int overwrite);
-
+int unsetenv(const char *name);
 #endif
diff --git a/mkpkgconfig b/mkpkgconfig
index 3b097a9fe6..0ae2a24bf9 100755
--- a/mkpkgconfig
+++ b/mkpkgconfig
@@ -15,12 +15,12 @@ fi
 
 ## Clean out CFLAGS for the spec file.
 
-LOCAL_CFLAGS=$(echo $CFLAGS | sed -e 's/\s*-pipe\s*//g' | sed -e 's/-[Wmp]\S*\s*//g' | \
-  sed -r -e 's/-I(include|\.\.\/include) //g' |
-  sed -e 's/-DINSTALL_PREFIX=\S* //g' |
-  sed -r -e 's/-DASTERISK_VERSION=\S* //g' |
-  sed -r -e 's/-DAST(ETCDIR|LIBDIR|VARLIBDIR|VARRUNDIR|SPOOLDIR|LOGDIR|CONFPATH|MODDIR|AGIDIR)=\S* //g'
-)
+LOCAL_CFLAGS=`echo $CFLAGS | sed -e 's/\s*-pipe\s*//g' | sed -e 's/-[Wmp]\S*\s*//g' | \
+  sed -r -e 's/-I(include|\.\.\/include) //g' | \
+  sed -e 's/-DINSTALL_PREFIX=\S* //g' | \
+  sed -r -e 's/-DASTERISK_VERSION=\S* //g' | \
+  sed -r -e 's/-DAST(ETCDIR|LIBDIR|VARLIBDIR|VARRUNDIR|SPOOLDIR|LOGDIR|CONFPATH|MODDIR|AGIDIR)=\S* //g'`
+
 
 cat <<EOF > $PPATH/asterisk.pc
 install_prefix=$INSTALL_PREFIX
diff --git a/res/res_agi.c b/res/res_agi.c
index 6557dc9fc7..ecf5391288 100755
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -48,6 +48,9 @@
 #include <asterisk/agi.h>
 #include "../asterisk.h"
 #include "../astconf.h"
+#ifdef SOLARIS
+#include <asterisk/astmm.h>
+#endif
 
 #define MAX_ARGS 128
 #define MAX_COMMANDS 128
diff --git a/rtp.c b/rtp.c
index 037b123a31..6ca1f916c8 100755
--- a/rtp.c
+++ b/rtp.c
@@ -1170,11 +1170,9 @@ int ast_rtp_sendcng(struct ast_rtp *rtp, int level)
 	return 0;
 }
 
-#ifdef SOLARIS
+#if defined(SOLARIS) && defined(__sparc__)
 static void put_uint32(unsigned char *buf, int i)
 {
-	unsigned char *c = (unsigned char *)&i;
-
 	buf[0] = (i>>24) & 0xff;
 	buf[1] = (i>>16) & 0xff;
 	buf[2] = (i>>8)  & 0xff;
diff --git a/strcompat.c b/strcompat.c
index 289116476c..b8f9f0e49a 100755
--- a/strcompat.c
+++ b/strcompat.c
@@ -2,6 +2,9 @@
 
 #include <sys/types.h>
 #include <stdio.h>
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#endif
 
 char* strsep(char** str, const char* delims)
 {
@@ -142,3 +145,9 @@ int setenv(const char *name, const char *value, int overwrite)
 
 	return ret;
 }
+
+int unsetenv(const char *name)
+{
+  setenv(name,"",0);
+}
+
diff --git a/utils.c b/utils.c
index 893543c15b..6d99111b18 100755
--- a/utils.c
+++ b/utils.c
@@ -164,6 +164,7 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp)
 	   integers, we break with tradition and refuse to look up a
 	   pure integer */
 	s = host;
+	res = 0;
 	while(s && *s) {
 		if (!isdigit(*s))
 			break;
diff --git a/utils/Makefile b/utils/Makefile
index dcacce210f..a3f04d10f8 100755
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -12,6 +12,9 @@ TARGET=stereorize
 
 TARGET+=$(shell if [ -f /usr/include/popt.h ]; then echo "smsq"; else if [ -f /usr/local/include/popt.h ]; then echo "smsq"; fi ; fi)
 TARGET+=$(shell if [ -f /usr/include/newt.h ]; then echo "astman"; else if [ -f /usr/local/include/newt.h ]; then echo "astman"; fi ; fi)
+ifeq (${OSARCH},SunOS)
+SOL=../strcompat.o
+endif
 
 all: depend $(TARGET)
 
@@ -32,7 +35,7 @@ stereorize: stereorize.o frame.o
 	$(CC) $(CFLAGS) -o stereorize stereorize.o frame.o -lm
 
 smsq: smsq.o
-	$(CC) $(CFLAGS) -o smsq smsq.o -lpopt
+	$(CC) $(CFLAGS) -o smsq ${SOL} smsq.o -lpopt
 
 ifneq ($(wildcard .depend),)
 include .depend
diff --git a/utils/smsq.c b/utils/smsq.c
index 9bdcfe3539..0da4c83dbe 100755
--- a/utils/smsq.c
+++ b/utils/smsq.c
@@ -9,6 +9,11 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
+#ifdef SOLARIS
+#include <solaris-compat/compat.h>
+#define     POPT_ARGFLAG_SHOW_DEFAULT 0x00800000
+#endif
+
 
 /* SMS queuing application for use with asterisk app_sms */
 /* by Adrian Kennard, 2004 - 2005 */
-- 
GitLab