Index: pjproject/trunk/build/m-powerpc.mak
===================================================================
--- pjproject/trunk/build/m-powerpc.mak	(revision 338)
+++ pjproject/trunk/build/m-powerpc.mak	(revision 338)
@@ -0,0 +1,4 @@
+export M_CFLAGS := $(CC_DEF)PJ_M_POWERPC=1
+export M_CXXFLAGS :=
+export M_LDFLAGS :=
+export M_SOURCES :=
Index: pjproject/trunk/build/os-darwinos.mak
===================================================================
--- pjproject/trunk/build/os-darwinos.mak	(revision 338)
+++ pjproject/trunk/build/os-darwinos.mak	(revision 338)
@@ -0,0 +1,9 @@
+export OS_CFLAGS   := $(CC_DEF)PJ_DARWINOS=1
+
+export OS_CXXFLAGS := 
+
+export OS_LDFLAGS  := $(CC_LIB)pthread$(LIBEXT2) 
+
+export OS_SOURCES  := 
+
+
Index: pjproject/trunk/configure
===================================================================
--- pjproject/trunk/configure	(revision 337)
+++ pjproject/trunk/configure	(revision 338)
@@ -4,5 +4,5 @@
 # Detect machine
 #
-MACHINE=`uname -m`
+MACHINE=`uname -p`
 
 if echo $MACHINE | grep sun4u > /dev/null; then
@@ -12,6 +12,8 @@
 elif echo $MACHINE | grep alpha > /dev/null; then
     MACHINE_NAME=alpha
+elif echo $MACHINE | grep powerpc > /dev/null; then
+    MACHINE_NAME=powerpc
 else
-    echo "Unable to detect processor type ('uname -m' == '$MACHINE')"
+    echo "Unable to detect processor type ('uname -p' == '$MACHINE')"
     exit 1
 fi
@@ -45,4 +47,7 @@
     OS_NAME=win32
     HOST_NAME=mingw
+elif echo $SYSTEM | grep -i darwin > /dev/null; then
+    OS_NAME=darwinos
+    HOST_NAME=unix
 else
     echo "Unable to detect system type ('uname -s' == '$SYSTEM')"
Index: pjproject/trunk/pjlib/build/Makefile
===================================================================
--- pjproject/trunk/pjlib/build/Makefile	(revision 337)
+++ pjproject/trunk/pjlib/build/Makefile	(revision 338)
@@ -23,5 +23,5 @@
 export PJLIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
 	array.o config.o ctype.o errno.o except.o fifobuf.o guid.o \
-	hash.o list.o lock.o log.o \
+	hash.o list.o lock.o log.o os_time_common.o \
 	pool.o pool_caching.o rand.o \
 	rbtree.o string.o timer.o \
Index: pjproject/trunk/pjlib/build/os-darwinos.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-darwinos.mak	(revision 338)
+++ pjproject/trunk/pjlib/build/os-darwinos.mak	(revision 338)
@@ -0,0 +1,37 @@
+#
+# PJLIB OS specific configuration for Darwin/MacOSX target. 
+#
+
+#
+# PJLIB_OBJS specified here are object files to be included in PJLIB
+# (the library) for this specific operating system. Object files common 
+# to all operating systems should go in Makefile instead.
+#
+export PJLIB_OBJS += 	addr_resolv_sock.o guid_simple.o \
+			log_writer_stdout.o os_core_unix.o \
+			os_error_unix.o os_time_unix.o \
+			os_timestamp_common.o os_timestamp_linux.o \
+			pool_policy_malloc.o sock_bsd.o sock_select.o
+
+export PJLIB_OBJS += ioqueue_select.o 
+#export PJLIB_OBJS += ioqueue_epoll.o
+
+export PJLIB_OBJS += file_access_unistd.o file_io_ansi.o
+
+#
+# TEST_OBJS are operating system specific object files to be included in
+# the test application.
+#
+export TEST_OBJS +=	main.o
+
+#
+# Additional LDFLAGS for pjlib-test
+#
+export TEST_LDFLAGS += -lm 
+
+#
+# TARGETS are make targets in the Makefile, to be executed for this given
+# operating system.
+#
+export TARGETS	    =	pjlib pjlib-test
+
Index: pjproject/trunk/pjlib/build/os-linux.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-linux.mak	(revision 337)
+++ pjproject/trunk/pjlib/build/os-linux.mak	(revision 338)
@@ -10,5 +10,5 @@
 export PJLIB_OBJS += 	addr_resolv_sock.o guid_simple.o \
 			log_writer_stdout.o os_core_unix.o \
-			os_error_unix.o os_time_ansi.o \
+			os_error_unix.o os_time_unix.o \
 			os_timestamp_common.o os_timestamp_linux.o \
 			os_time_ansi.o \
Index: pjproject/trunk/pjlib/build/os-sunos.mak
===================================================================
--- pjproject/trunk/pjlib/build/os-sunos.mak	(revision 337)
+++ pjproject/trunk/pjlib/build/os-sunos.mak	(revision 338)
@@ -10,5 +10,5 @@
 export PJLIB_OBJS += 	addr_resolv_sock.o guid_simple.o \
 			log_writer_stdout.o os_core_unix.o \
-			os_error_unix.o os_time_ansi.o \
+			os_error_unix.o os_time_unix.o \
 			os_timestamp_common.o os_timestamp_linux.o \
 			os_time_ansi.o \
Index: pjproject/trunk/pjlib/include/pj/compat/errno.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/errno.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/errno.h	(revision 338)
@@ -27,7 +27,5 @@
 #   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;
@@ -37,5 +35,5 @@
 #else
 
-#   error "Please define pj_os_err_type for this platform here!"
+#   error "Please define how to get errno for this platform here!"
 
 #endif
Index: pjproject/trunk/pjlib/include/pj/compat/m_powerpc.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/m_powerpc.h	(revision 338)
+++ pjproject/trunk/pjlib/include/pj/compat/m_powerpc.h	(revision 338)
@@ -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__ */
+
Index: pjproject/trunk/pjlib/include/pj/compat/os_darwinos.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_darwinos.h	(revision 338)
+++ pjproject/trunk/pjlib/include/pj/compat/os_darwinos.h	(revision 338)
@@ -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__ */
+
Index: pjproject/trunk/pjlib/include/pj/compat/os_linux.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_linux.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_linux.h	(revision 338)
@@ -44,4 +44,5 @@
 #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
@@ -54,4 +55,9 @@
 
 #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
Index: pjproject/trunk/pjlib/include/pj/compat/os_linux_kernel.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_linux_kernel.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_linux_kernel.h	(revision 338)
@@ -44,4 +44,5 @@
 #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
@@ -54,4 +55,5 @@
 
 #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
Index: pjproject/trunk/pjlib/include/pj/compat/os_palmos.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_palmos.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_palmos.h	(revision 338)
@@ -53,4 +53,9 @@
 
 #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
Index: pjproject/trunk/pjlib/include/pj/compat/os_sunos.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_sunos.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_sunos.h	(revision 338)
@@ -44,4 +44,5 @@
 #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
@@ -54,4 +55,9 @@
 
 #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
Index: pjproject/trunk/pjlib/include/pj/compat/os_win32.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_win32.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_win32.h	(revision 338)
@@ -50,4 +50,5 @@
 #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
@@ -60,4 +61,9 @@
 
 #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
Index: pjproject/trunk/pjlib/include/pj/compat/os_win32_wince.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/os_win32_wince.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/os_win32_wince.h	(revision 338)
@@ -48,4 +48,5 @@
 #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 */
@@ -58,4 +59,9 @@
 
 #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
@@ -98,2 +104,3 @@
 
 #endif	/* __PJ_COMPAT_OS_WIN32_WINCE_H__ */
+
Index: pjproject/trunk/pjlib/include/pj/compat/time.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/compat/time.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/compat/time.h	(revision 338)
@@ -29,4 +29,8 @@
 #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>
@@ -35,2 +39,3 @@
 
 #endif	/* __PJ_COMPAT_TIME_H__ */
+
Index: pjproject/trunk/pjlib/include/pj/config.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/config.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/config.h	(revision 338)
@@ -52,4 +52,6 @@
 #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."
@@ -70,4 +72,6 @@
 #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."
@@ -247,5 +251,6 @@
  * 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
Index: pjproject/trunk/pjlib/include/pj/sock.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/sock.h	(revision 337)
+++ pjproject/trunk/pjlib/include/pj/sock.h	(revision 338)
@@ -157,8 +157,18 @@
 /**
  * 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;
@@ -176,8 +186,18 @@
 /**
  * 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.		    */
@@ -213,8 +233,18 @@
 /**
  * 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	    */
Index: pjproject/trunk/pjlib/src/pj/guid_simple.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/guid_simple.c	(revision 337)
+++ pjproject/trunk/pjlib/src/pj/guid_simple.c	(revision 338)
@@ -21,5 +21,4 @@
 #include <pj/rand.h>
 #include <pj/string.h>
-#include <pj/compat/sprintf.h>
 
 const unsigned PJ_GUID_STRING_LENGTH=20;
Index: pjproject/trunk/pjlib/src/pj/os_core_unix.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 337)
+++ pjproject/trunk/pjlib/src/pj/os_core_unix.c	(revision 338)
@@ -25,5 +25,4 @@
 #include <pj/string.h>
 #include <pj/guid.h>
-#include <pj/compat/sprintf.h>
 #include <pj/except.h>
 #include <pj/errno.h>
@@ -205,7 +204,7 @@
 
     if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1)
-	pj_sprintf(thread->obj_name, cstr_thread_name, thread->thread);
+	pj_ansi_sprintf(thread->obj_name, cstr_thread_name, thread->thread);
     else
-	pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread);
+	pj_ansi_sprintf(thread->obj_name, "thr%p", (void*)thread->thread);
     
     rc = pj_thread_local_set(thread_tls_id, thread);
@@ -315,5 +314,5 @@
     
     if (strchr(thread_name, '%')) {
-	pj_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec);
+	pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec);
     } else {
 	strncpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME);
@@ -805,5 +804,5 @@
     }
     if (strchr(name, '%')) {
-	pj_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex);
+	pj_ansi_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex);
     } else {
 	strncpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME);
@@ -1126,5 +1125,5 @@
     }
     if (strchr(name, '%')) {
-	pj_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem);
+	pj_ansi_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem);
     } else {
 	strncpy(sem->obj_name, name, PJ_MAX_OBJ_NAME);
Index: pjproject/trunk/pjlib/src/pj/os_time_ansi.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/os_time_ansi.c	(revision 337)
+++ 	(revision )
@@ -1,87 +1,0 @@
-/* $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 
- */
-#include <pj/os.h>
-#include <pj/compat/time.h>
-
-///////////////////////////////////////////////////////////////////////////////
-
-PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv)
-{
-    struct timeb tb;
-
-    PJ_CHECK_STACK();
-
-    ftime(&tb);
-    tv->sec = tb.time;
-    tv->msec = tb.millitm;
-    return PJ_SUCCESS;
-}
-
-PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
-{
-    struct tm *local_time;
-
-    PJ_CHECK_STACK();
-
-    local_time = localtime((time_t*)&tv->sec);
-
-    pt->year = local_time->tm_year+1900;
-    pt->mon = local_time->tm_mon;
-    pt->day = local_time->tm_mday;
-    pt->hour = local_time->tm_hour;
-    pt->min = local_time->tm_min;
-    pt->sec = local_time->tm_sec;
-    pt->wday = local_time->tm_wday;
-    pt->msec = tv->msec;
-
-    return PJ_SUCCESS;
-}
-
-/**
- * Encode parsed time to time value.
- */
-PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
-{
-    struct tm local_time;
-
-    local_time.tm_year = pt->year-1900;
-    local_time.tm_mon = pt->mon;
-    local_time.tm_mday = pt->day;
-    local_time.tm_hour = pt->hour;
-    local_time.tm_min = pt->min;
-    local_time.tm_sec = pt->sec;
-    local_time.tm_isdst = 0;
-    
-    tv->sec = mktime(&local_time);
-    tv->msec = pt->msec;
-
-    return PJ_SUCCESS;
-}
-
-/**
- * Convert local time to GMT.
- */
-PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
-
-/**
- * Convert GMT to local time.
- */
-PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
-
-
Index: pjproject/trunk/pjlib/src/pj/os_time_bsd.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/os_time_bsd.c	(revision 338)
+++ pjproject/trunk/pjlib/src/pj/os_time_bsd.c	(revision 338)
@@ -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 
+ */
+#include <pj/os.h>
+#include <pj/compat/time.h>
+
+///////////////////////////////////////////////////////////////////////////////
+
+PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv)
+{
+    struct timeb tb;
+
+    PJ_CHECK_STACK();
+
+    ftime(&tb);
+    tv->sec = tb.time;
+    tv->msec = tb.millitm;
+    return PJ_SUCCESS;
+}
+
Index: pjproject/trunk/pjlib/src/pj/os_time_common.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/os_time_common.c	(revision 338)
+++ pjproject/trunk/pjlib/src/pj/os_time_common.c	(revision 338)
@@ -0,0 +1,75 @@
+/* $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 
+ */
+#include <pj/os.h>
+#include <pj/compat/time.h>
+
+///////////////////////////////////////////////////////////////////////////////
+
+PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
+{
+    struct tm *local_time;
+
+    PJ_CHECK_STACK();
+
+    local_time = localtime((time_t*)&tv->sec);
+
+    pt->year = local_time->tm_year+1900;
+    pt->mon = local_time->tm_mon;
+    pt->day = local_time->tm_mday;
+    pt->hour = local_time->tm_hour;
+    pt->min = local_time->tm_min;
+    pt->sec = local_time->tm_sec;
+    pt->wday = local_time->tm_wday;
+    pt->msec = tv->msec;
+
+    return PJ_SUCCESS;
+}
+
+/**
+ * Encode parsed time to time value.
+ */
+PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
+{
+    struct tm local_time;
+
+    local_time.tm_year = pt->year-1900;
+    local_time.tm_mon = pt->mon;
+    local_time.tm_mday = pt->day;
+    local_time.tm_hour = pt->hour;
+    local_time.tm_min = pt->min;
+    local_time.tm_sec = pt->sec;
+    local_time.tm_isdst = 0;
+    
+    tv->sec = mktime(&local_time);
+    tv->msec = pt->msec;
+
+    return PJ_SUCCESS;
+}
+
+/**
+ * Convert local time to GMT.
+ */
+PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
+
+/**
+ * Convert GMT to local time.
+ */
+PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
+
+
Index: pjproject/trunk/pjlib/src/pj/os_time_unix.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/os_time_unix.c	(revision 338)
+++ pjproject/trunk/pjlib/src/pj/os_time_unix.c	(revision 338)
@@ -0,0 +1,39 @@
+/* $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 
+ */
+#include <pj/os.h>
+#include <pj/compat/time.h>
+
+#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H!=0
+#    include <unistd.h>
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+
+PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *p_tv)
+{
+    struct timeval tv;
+
+    PJ_CHECK_STACK();
+
+    gettimeofday(&tv, NULL);
+    p_tv->sec = tv.tv_sec;
+    p_tv->msec = tv.tv_usec / 1000;
+    return PJ_SUCCESS;
+}
+
Index: pjproject/trunk/pjlib/src/pj/pool_caching.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/pool_caching.c	(revision 337)
+++ pjproject/trunk/pjlib/src/pj/pool_caching.c	(revision 338)
@@ -58,5 +58,5 @@
     cp->factory.dump_status = &cpool_dump_status;
 
-    cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 128, 
+    cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 256, 
 				  0, NULL);
     i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex);
Index: pjproject/trunk/pjlib/src/pj/sock_bsd.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 337)
+++ pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 338)
@@ -83,4 +83,13 @@
 
 
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+#   define SET_LEN(addr,len) (((pj_sockaddr*)(addr))->sa_zero_len=(len))
+#   define RESET_LEN(addr)   (((pj_sockaddr*)(addr))->sa_zero_len=0)
+#else
+#   define SET_LEN(addr,len) 
+#   define RESET_LEN(addr)
+#endif
+
+
 /*
  * Convert 16-bit value from network byte order to host byte order.
@@ -191,4 +200,5 @@
                      (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL));
 
+    RESET_LEN(addr);
     addr->sin_family = AF_INET;
 
@@ -227,4 +237,5 @@
     PJ_ASSERT_RETURN(addr, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL));
 
+    RESET_LEN(addr);
     addr->sin_family = PJ_AF_INET;
     pj_sockaddr_in_set_port(addr, port);
@@ -347,4 +358,5 @@
     PJ_CHECK_STACK();
 
+    SET_LEN(&addr, sizeof(pj_sockaddr_in));
     addr.sin_family = PJ_AF_INET;
     addr.sin_addr.s_addr = pj_htonl(addr32);
@@ -386,6 +398,8 @@
     if (getpeername(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0)
 	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
-    else
-	return PJ_SUCCESS;
+    else {
+	RESET_LEN(addr);
+	return PJ_SUCCESS;
+    }
 }
 
@@ -400,6 +414,8 @@
     if (getsockname(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0)
 	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
-    else
-	return PJ_SUCCESS;
+    else {
+	RESET_LEN(addr);
+	return PJ_SUCCESS;
+    }
 }
 
@@ -484,6 +500,8 @@
     if (*len < 0) 
 	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
-    else
-	return PJ_SUCCESS;
+    else {
+	RESET_LEN(from);
+	return PJ_SUCCESS;
+    }
 }
 
@@ -575,9 +593,23 @@
     PJ_ASSERT_RETURN(newsock != NULL, PJ_EINVAL);
 
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+    if (addr) {
+	SET_LEN(addr, *addrlen);
+    }
+#endif
+    
     *newsock = accept(serverfd, (struct sockaddr*)addr, (socklen_t*)addrlen);
     if (*newsock==PJ_INVALID_SOCKET)
 	return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
-    else
-	return PJ_SUCCESS;
+    else {
+	
+#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
+	if (addr) {
+	    RESET_LEN(addr);
+	}
+#endif
+	    
+	return PJ_SUCCESS;
+    }
 }
 #endif	/* PJ_HAS_TCP */
Index: pjproject/trunk/pjlib/src/pj/sock_select.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/sock_select.c	(revision 337)
+++ pjproject/trunk/pjlib/src/pj/sock_select.c	(revision 338)
@@ -25,4 +25,8 @@
 #if defined(PJ_HAS_STRING_H) && PJ_HAS_STRING_H!=0
 #   include <string.h>
+#endif
+
+#if defined(PJ_HAS_SYS_TIME_H) && PJ_HAS_SYS_TIME_H!=0
+#   include <sys/time.h>
 #endif
 
