Ported pjlib to PowerPC/MacOS

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@338 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/include/pj/compat/errno.h b/pjlib/include/pj/compat/errno.h
index 8c86daa..a385efc 100644
--- a/pjlib/include/pj/compat/errno.h
+++ b/pjlib/include/pj/compat/errno.h
@@ -26,9 +26,7 @@
 #   define pj_get_native_os_error()	    GetLastError()
 #   define pj_get_native_netos_error()	    WSAGetLastError()
 
-#elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \
-      (defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0) || \
-      (defined(PJ_SUNOS) && PJ_SUNOS != 0)
+#elif defined(PJ_HAS_ERRNO_VAR) && PJ_HAS_ERRNO_VAR!= 0
 
     typedef int pj_os_err_type;
 #   define pj_get_native_os_error()	    (errno)
@@ -36,7 +34,7 @@
 
 #else
 
-#   error "Please define pj_os_err_type for this platform here!"
+#   error "Please define how to get errno for this platform here!"
 
 #endif
 
diff --git a/pjlib/include/pj/compat/m_powerpc.h b/pjlib/include/pj/compat/m_powerpc.h
new file mode 100644
index 0000000..49a9208
--- /dev/null
+++ b/pjlib/include/pj/compat/m_powerpc.h
@@ -0,0 +1,35 @@
+/* $Id$ */
+/* 
+ * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#ifndef __PJ_COMPAT_M_POWERPC_H__
+#define __PJ_COMPAT_M_POWERPC_H__
+
+/**
+ * @file m_ppc.h
+ * @brief Describes PowerPC family processor specifics.
+ */
+
+#define PJ_M_NAME		"powerpc"
+
+#define PJ_HAS_PENTIUM		0
+#define PJ_IS_LITTLE_ENDIAN	0
+#define PJ_IS_BIG_ENDIAN	1
+
+
+#endif	/* __PJ_COMPAT_M_POWERPC_H__ */
+
diff --git a/pjlib/include/pj/compat/os_darwinos.h b/pjlib/include/pj/compat/os_darwinos.h
new file mode 100644
index 0000000..9a0f90b
--- /dev/null
+++ b/pjlib/include/pj/compat/os_darwinos.h
@@ -0,0 +1,110 @@
+/* $Id$ */
+/* 
+ * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#ifndef __PJ_COMPAT_OS_DARWINOS_H__
+#define __PJ_COMPAT_OS_DARWINOS_H__
+
+/**
+ * @file os_darwinos.h
+ * @brief Describes Darwin/MacOSX operating system specifics.
+ */
+
+#define PJ_OS_NAME		    "darwin"
+
+#define PJ_HAS_ARPA_INET_H	    1
+#define PJ_HAS_ASSERT_H		    1
+#define PJ_HAS_CTYPE_H		    1
+#define PJ_HAS_ERRNO_H		    1
+#define PJ_HAS_LINUX_SOCKET_H	    0
+#define PJ_HAS_MALLOC_H		    0
+#define PJ_HAS_NETDB_H		    1
+#define PJ_HAS_NETINET_IN_H	    1
+#define PJ_HAS_SETJMP_H		    1
+#define PJ_HAS_STDARG_H		    1
+#define PJ_HAS_STDDEF_H		    1
+#define PJ_HAS_STDIO_H		    1
+#define PJ_HAS_STDLIB_H		    1
+#define PJ_HAS_STRING_H		    1
+#define PJ_HAS_SYS_IOCTL_H	    1
+#define PJ_HAS_SYS_SELECT_H	    1
+#define PJ_HAS_SYS_SOCKET_H	    1
+#define PJ_HAS_SYS_TIME_H	    1
+#define PJ_HAS_SYS_TIMEB_H	    1
+#define PJ_HAS_SYS_TYPES_H	    1
+#define PJ_HAS_TIME_H		    1
+#define PJ_HAS_UNISTD_H		    1
+
+#define PJ_HAS_MSWSOCK_H	    0
+#define PJ_HAS_WINSOCK_H	    0
+#define PJ_HAS_WINSOCK2_H	    0
+
+/* Is errno a good way to retrieve OS errors?
+ */
+#define PJ_HAS_ERRNO_VAR	    1
+
+/* Has inet_aton() ?
+ */   
+#define PJ_SOCK_HAS_INET_ATON	    1
+
+/* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
+ * the status of non-blocking connect() operation.
+ */
+#define PJ_HAS_SO_ERROR             1
+
+/* This value specifies the value set in errno by the OS when a non-blocking
+ * socket recv() can not return immediate daata.
+ */
+#define PJ_BLOCKING_ERROR_VAL       EWOULDBLOCK
+
+/* This value specifies the value set in errno by the OS when a non-blocking
+ * socket connect() can not get connected immediately.
+ */
+#define PJ_BLOCKING_CONNECT_ERROR_VAL   EINPROGRESS
+
+/* Default threading is enabled, unless it's overridden. */
+#ifndef PJ_HAS_THREADS
+#  define PJ_HAS_THREADS		(1)
+#endif
+
+#define PJ_HAS_HIGH_RES_TIMER		1
+#define PJ_HAS_MALLOC			1
+#ifndef PJ_OS_HAS_CHECK_STACK
+#   define PJ_OS_HAS_CHECK_STACK        0
+#endif
+#define PJ_NATIVE_STRING_IS_UNICODE	0
+
+#define PJ_ATOMIC_VALUE_TYPE		long
+
+/*
+ * Socket related
+ */
+typedef int socklen_t;
+#define PJ_SOCKADDR_HAS_LEN		1
+
+/*
+ * gcc complains that it can not use precompiled header because
+ * the value of FD_SETSIZE that we declare in pj/config.h is
+ * different than the value in /usr/include/sys/types.h.
+ *
+ * This changes the default value for Darwin.
+ */
+#define PJ_IOQUEUE_MAX_HANDLES		1024
+
+
+#endif	/* __PJ_COMPAT_OS_DARWINOS_H__ */
+
diff --git a/pjlib/include/pj/compat/os_linux.h b/pjlib/include/pj/compat/os_linux.h
index 24faa22..fe3a29d 100644
--- a/pjlib/include/pj/compat/os_linux.h
+++ b/pjlib/include/pj/compat/os_linux.h
@@ -43,6 +43,7 @@
 #define PJ_HAS_SYS_IOCTL_H	    1
 #define PJ_HAS_SYS_SELECT_H	    1
 #define PJ_HAS_SYS_SOCKET_H	    1
+#define PJ_HAS_SYS_TIME_H	    0
 #define PJ_HAS_SYS_TIMEB_H	    1
 #define PJ_HAS_SYS_TYPES_H	    1
 #define PJ_HAS_TIME_H		    1
@@ -53,6 +54,11 @@
 #define PJ_HAS_WINSOCK2_H	    0
 
 #define PJ_SOCK_HAS_INET_ATON	    1
+#define PJ_SOCKADDR_HAS_LEN	    0
+
+/* Is errno a good way to retrieve OS errors?
+ */
+#define PJ_HAS_ERRNO_VAR	    1
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
diff --git a/pjlib/include/pj/compat/os_linux_kernel.h b/pjlib/include/pj/compat/os_linux_kernel.h
index 502d5aa..e481248 100644
--- a/pjlib/include/pj/compat/os_linux_kernel.h
+++ b/pjlib/include/pj/compat/os_linux_kernel.h
@@ -43,6 +43,7 @@
 #define PJ_HAS_SYS_IOCTL_H	    0
 #define PJ_HAS_SYS_SELECT_H	    0
 #define PJ_HAS_SYS_SOCKET_H	    0
+#define PJ_HAS_SYS_TIME_H	    0
 #define PJ_HAS_SYS_TIMEB_H	    0
 #define PJ_HAS_SYS_TYPES_H	    0
 #define PJ_HAS_TIME_H		    0
@@ -53,6 +54,7 @@
 #define PJ_HAS_WINSOCK2_H	    0
 
 #define PJ_SOCK_HAS_INET_ATON	    0
+#define PJ_SOCKADDR_HAS_LEN	    0
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
diff --git a/pjlib/include/pj/compat/os_palmos.h b/pjlib/include/pj/compat/os_palmos.h
index e97cd66..478e871 100644
--- a/pjlib/include/pj/compat/os_palmos.h
+++ b/pjlib/include/pj/compat/os_palmos.h
@@ -52,6 +52,11 @@
 #define PJ_HAS_WINSOCK2_H	    0
 
 #define PJ_SOCK_HAS_INET_ATON	    0
+#define PJ_SOCKADDR_HAS_LEN	    0
+
+/* Is errno a good way to retrieve OS errors?
+ */
+#define PJ_HAS_ERRNO_VAR	    0
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
diff --git a/pjlib/include/pj/compat/os_sunos.h b/pjlib/include/pj/compat/os_sunos.h
index bbe7a75..389d66c 100644
--- a/pjlib/include/pj/compat/os_sunos.h
+++ b/pjlib/include/pj/compat/os_sunos.h
@@ -43,6 +43,7 @@
 #define PJ_HAS_SYS_IOCTL_H	    1
 #define PJ_HAS_SYS_SELECT_H	    1
 #define PJ_HAS_SYS_SOCKET_H	    1
+#define PJ_HAS_SYS_TIME_H	    0
 #define PJ_HAS_SYS_TIMEB_H	    1
 #define PJ_HAS_SYS_TYPES_H	    1
 #define PJ_HAS_TIME_H		    1
@@ -53,6 +54,11 @@
 #define PJ_HAS_WINSOCK2_H	    0
 
 #define PJ_SOCK_HAS_INET_ATON	    0
+#define PJ_SOCKADDR_HAS_LEN	    0
+
+/* Is errno a good way to retrieve OS errors?
+ */
+#define PJ_HAS_ERRNO_VAR	    1
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
diff --git a/pjlib/include/pj/compat/os_win32.h b/pjlib/include/pj/compat/os_win32.h
index 2a61764..5abfc89 100644
--- a/pjlib/include/pj/compat/os_win32.h
+++ b/pjlib/include/pj/compat/os_win32.h
@@ -49,6 +49,7 @@
 #define PJ_HAS_SYS_IOCTL_H	    0
 #define PJ_HAS_SYS_SELECT_H	    0
 #define PJ_HAS_SYS_SOCKET_H	    0
+#define PJ_HAS_SYS_TIME_H	    0
 #define PJ_HAS_SYS_TIMEB_H	    1
 #define PJ_HAS_SYS_TYPES_H	    1
 #define PJ_HAS_TIME_H		    1
@@ -59,6 +60,11 @@
 #define PJ_HAS_WINSOCK2_H	    1
 
 #define PJ_SOCK_HAS_INET_ATON	    0
+#define PJ_SOCKADDR_HAS_LEN	    0
+
+/* Is errno a good way to retrieve OS errors? (No)
+ */
+#define PJ_HAS_ERRNO_VAR	    0
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
diff --git a/pjlib/include/pj/compat/os_win32_wince.h b/pjlib/include/pj/compat/os_win32_wince.h
index 05b8918..f6d46e8 100644
--- a/pjlib/include/pj/compat/os_win32_wince.h
+++ b/pjlib/include/pj/compat/os_win32_wince.h
@@ -47,6 +47,7 @@
 #define PJ_HAS_SYS_IOCTL_H	    0
 #define PJ_HAS_SYS_SELECT_H	    0
 #define PJ_HAS_SYS_SOCKET_H	    0
+#define PJ_HAS_SYS_TIME_H	    0
 #define PJ_HAS_SYS_TIMEB_H	    0	/* Doesn't have sys/timeb.h */
 #define PJ_HAS_SYS_TYPES_H	    0	/* Doesn't have sys/types.h */
 #define PJ_HAS_TIME_H		    1
@@ -57,6 +58,11 @@
 #define PJ_HAS_WINSOCK2_H	    1
 
 #define PJ_SOCK_HAS_INET_ATON	    0
+#define PJ_SOCKADDR_HAS_LEN	    0
+
+/* Is errno a good way to retrieve OS errors? (no)
+ */
+#define PJ_HAS_ERRNO_VAR	    0
 
 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
  * the status of non-blocking connect() operation.
@@ -97,3 +103,4 @@
 #define PJ_NATIVE_STRING_IS_UNICODE 1
 
 #endif	/* __PJ_COMPAT_OS_WIN32_WINCE_H__ */
+
diff --git a/pjlib/include/pj/compat/time.h b/pjlib/include/pj/compat/time.h
index 2a2bc39..3ec73a7 100644
--- a/pjlib/include/pj/compat/time.h
+++ b/pjlib/include/pj/compat/time.h
@@ -28,9 +28,14 @@
 #  include <time.h>
 #endif
 
+#if defined(PJ_HAS_SYS_TIME_H) && PJ_HAS_SYS_TIME_H != 0
+#  include <sys/time.h>
+#endif
+
 #if defined(PJ_HAS_SYS_TIMEB_H) && PJ_HAS_SYS_TIMEB_H != 0
 #  include <sys/timeb.h>
 #endif
 
 
 #endif	/* __PJ_COMPAT_TIME_H__ */
+
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h
index 607bf26..2e6995d 100644
--- a/pjlib/include/pj/config.h
+++ b/pjlib/include/pj/config.h
@@ -51,6 +51,8 @@
 #  include <pj/compat/os_palmos.h>
 #elif defined(PJ_SUNOS) && PJ_SUNOS!=0
 #  include <pj/compat/os_sunos.h>
+#elif defined(PJ_DARWINOS) && PJ_DARWINOS!=0
+#  include <pj/compat/os_darwinos.h>
 #else
 #  error "Please specify target os."
 #endif
@@ -69,6 +71,8 @@
 #   include <pj/compat/m_sparc.h>
 #elif defined (PJ_M_ARMV4) && PJ_M_ARMV4 != 0
 #   include <pj/compat/m_armv4.h>
+#elif defined (PJ_M_POWERPC) && PJ_M_POWERPC != 0
+#   include <pj/compat/m_powerpc.h>
 #else
 #  error "Please specify target machine."
 #endif
@@ -246,7 +250,8 @@
  * maximum number of socket handles passed to select() (i.e. FD_SETSIZE will 
  * be set to this value).
  *
- * Default: 256 (64 for WinCE)
+ * Default: if FD_SETSIZE is defined and the value is greather than 256,
+ *          then it will be used.  Otherwise 256 (64 for WinCE).
  */
 #ifndef PJ_IOQUEUE_MAX_HANDLES
 #   if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h
index cd15913..3e3307a 100644
--- a/pjlib/include/pj/sock.h
+++ b/pjlib/include/pj/sock.h
@@ -156,10 +156,20 @@
 
 /**
  * Structure describing a generic socket address.
+ * If PJ_SOCKADDR_HAS_LEN is not zero, then sa_zero_len member is added
+ * to this struct. As far the application is concerned, the value of
+ * this member will always be zero. Internally, PJLIB may modify the value
+ * before calling OS socket API, and reset the value back to zero before
+ * returning the struct to application.
  */
 typedef struct pj_sockaddr
 {
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+    pj_uint8_t  sa_zero_len;
+    pj_uint8_t  sa_family;
+#else
     pj_uint16_t	sa_family;	/**< Common data: address family.   */
+#endif
     char	sa_data[14];	/**< Address data.		    */
 } pj_sockaddr;
 
@@ -175,10 +185,20 @@
 
 /**
  * This structure describes Internet socket address.
+ * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added
+ * to this struct. As far the application is concerned, the value of
+ * this member will always be zero. Internally, PJLIB may modify the value
+ * before calling OS socket API, and reset the value back to zero before
+ * returning the struct to application.
  */
 struct pj_sockaddr_in
 {
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+    pj_uint8_t  sin_zero_len;	/**< Just ignore this.		    */
+    pj_uint8_t  sin_family;	/**< Address family.		    */
+#else
     pj_uint16_t	sin_family;	/**< Address family.		    */
+#endif
     pj_uint16_t	sin_port;	/**< Transport layer port number.   */
     pj_in_addr	sin_addr;	/**< IP address.		    */
     char	sin_zero[8];	/**< Padding.			    */
@@ -212,10 +232,20 @@
 
 /**
  * This structure describes IPv6 socket address.
+ * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added
+ * to this struct. As far the application is concerned, the value of
+ * this member will always be zero. Internally, PJLIB may modify the value
+ * before calling OS socket API, and reset the value back to zero before
+ * returning the struct to application.
  */
 typedef struct pj_sockaddr_in6
 {
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+    pj_uint8_t  sin_zero_len;	    /**< Just ignore this.	   */
+    pj_uint8_t  sin_family;	    /**< Address family.	   */
+#else
     pj_uint16_t	sin6_family;	    /**< Address family		    */
+#endif
     pj_uint16_t	sin6_port;	    /**< Transport layer port number. */
     pj_uint32_t	sin6_flowinfo;	    /**< IPv6 flow information	    */
     pj_in6_addr sin6_addr;	    /**< IPv6 address.		    */