[Asterisk-cvs] asterisk dlfcn.c,NONE,1.1 poll.c,NONE,1.1 Makefile,1.40,1.41 dns.c,1.1,1.2 enum.c,1.10,1.11 io.c,1.1.1.1,1.2 loader.c,1.7,1.8 srv.c,1.4,1.5

markster at lists.digium.com markster at lists.digium.com
Sun Oct 26 12:24:43 CST 2003


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv12438

Modified Files:
	Makefile dns.c enum.c io.c loader.c srv.c 
Added Files:
	dlfcn.c poll.c 
Log Message:
Make it build and run on MacOS X


--- NEW FILE: dlfcn.c ---
/*
Copyright (c) 2002 Jorge Acereda  <jacereda at users.sourceforge.net> &
                   Peter O'Gorman <ogorman at users.sourceforge.net>
                   
Portions may be copyright others, see the AUTHORS file included with this
distribution.                  

Maintained by Peter O'Gorman <ogorman at users.sourceforge.net>

Bug Reports and other queries should go to <ogorman at users.sourceforge.net>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

[...1274 lines suppressed...]
	dolock();
	malloc_sym = malloc(sym_len + 2);
	if (malloc_sym)
	{
		sprintf(malloc_sym, "_%s", symbol);
		rv.d = dlsymIntern(handle, malloc_sym, 1);
		free(malloc_sym);
	}
	else
	{
		error("Unable to allocate memory");
		goto dlfuncerror;
	}
	dounlock();
	return rv.f;
  dlfuncerror:
	dounlock();
	return NULL;
}
#endif

--- NEW FILE: poll.c ---
/*---------------------------------------------------------------------------*\
  $Id: poll.c,v 1.1 2003/10/26 18:50:48 markster Exp $

  NAME

	poll - select(2)-based poll() emulation function for BSD systems.

  SYNOPSIS
	#include "poll.h"

	struct pollfd
	{
	    int     fd;
	    short   events;
	    short   revents;
	}

	int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)

  DESCRIPTION

	This file, and the accompanying "poll.h", implement the System V
	poll(2) system call for BSD systems (which typically do not provide
	poll()).  Poll() provides a method for multiplexing input and output
	on multiple open file descriptors; in traditional BSD systems, that
	capability is provided by select().  While the semantics of select()
	differ from those of poll(), poll() can be readily emulated in terms
	of select() -- which is how this function is implemented.

  REFERENCES
	Stevens, W. Richard. Unix Network Programming.  Prentice-Hall, 1990.

  NOTES
	1. This software requires an ANSI C compiler.

  LICENSE

	This software is released under the following license:

		Copyright (c) 1995-2002 Brian M. Clapper
		All rights reserved.

		Redistribution and use in source and binary forms are
		permitted provided that: (1) source distributions retain
		this entire copyright notice and comment; (2) modifications
		made to the software are prominently mentioned, and a copy
		of the original software (or a pointer to its location) are
		included; and (3) distributions including binaries display
		the following acknowledgement: "This product includes
		software developed by Brian M. Clapper <bmc at clapper.org>"
		in the documentation or other materials provided with the
		distribution. The name of the author may not be used to
		endorse or promote products derived from this software
		without specific prior written permission.

		THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
		OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
		IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
		PARTICULAR PURPOSE.

	Effectively, this means you can do what you want with the software
	except remove this notice or take advantage of the author's name.
	If you modify the software and redistribute your modified version,
	you must indicate that your version is a modification of the
	original, and you must provide either a pointer to or a copy of the
	original.
\*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*\
				 Includes
\*---------------------------------------------------------------------------*/

#include <unistd.h>			     /* standard Unix definitions */
#include <sys/types.h>                       /* system types */
#include <sys/time.h>                        /* time definitions */
#include <assert.h>                          /* assertion macros */
#include <string.h>                          /* string functions */

#include <asterisk/poll-compat.h>                            /* this package */

/*---------------------------------------------------------------------------*\
				  Macros
\*---------------------------------------------------------------------------*/

#ifndef MAX
#define MAX(a,b)	((a) > (b) ? (a) : (b))
#endif


/*---------------------------------------------------------------------------*\
			     Private Functions
\*---------------------------------------------------------------------------*/

static int map_poll_spec
#if __STDC__ > 0
			(struct pollfd *pArray,
			  unsigned long  n_fds,
			  fd_set        *pReadSet,
			  fd_set        *pWriteSet,
			  fd_set        *pExceptSet)
#else
			 (pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
			  struct pollfd *pArray;
			  unsigned long  n_fds;
			  fd_set        *pReadSet;
			  fd_set        *pWriteSet;
			  fd_set        *pExceptSet;
#endif
{
    register unsigned long  i;                   /* loop control */
    register struct	    pollfd *pCur;        /* current array element */
    register int	    max_fd = -1;         /* return value */

    /*
       Map the poll() structures into the file descriptor sets required
       by select().
    */
    for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
    {
        /* Skip any bad FDs in the array. */

        if (pCur->fd < 0)
            continue;

	if (pCur->events & POLLIN)
	{
	    /* "Input Ready" notification desired. */
	    FD_SET (pCur->fd, pReadSet);
	}

	if (pCur->events & POLLOUT)
	{
	    /* "Output Possible" notification desired. */
	    FD_SET (pCur->fd, pWriteSet);
	}

	if (pCur->events & POLLPRI)
	{
	    /*
	       "Exception Occurred" notification desired.  (Exceptions
	       include out of band data.
	    */
	    FD_SET (pCur->fd, pExceptSet);
	}

	max_fd = MAX (max_fd, pCur->fd);
    }

    return max_fd;
}

static struct timeval *map_timeout
#if __STDC__ > 0
			(int poll_timeout, struct timeval *pSelTimeout)
#else
			(poll_timeout, pSelTimeout)
			 int             poll_timeout;
			 struct timeval *pSelTimeout;
#endif
{
    struct timeval *pResult;

    /*
       Map the poll() timeout value into a select() timeout.  The possible
       values of the poll() timeout value, and their meanings, are:

       VALUE	MEANING

       -1	wait indefinitely (until signal occurs)
        0	return immediately, don't block
       >0	wait specified number of milliseconds

       select() uses a "struct timeval", which specifies the timeout in
       seconds and microseconds, so the milliseconds value has to be mapped
       accordingly.
    */

    assert (pSelTimeout != (struct timeval *) NULL);

    switch (poll_timeout)
    {
	case -1:
	    /*
	       A NULL timeout structure tells select() to wait indefinitely.
	    */
	    pResult = (struct timeval *) NULL;
	    break;

	case 0:
	    /*
	       "Return immediately" (test) is specified by all zeros in
	       a timeval structure.
	    */
	    pSelTimeout->tv_sec  = 0;
	    pSelTimeout->tv_usec = 0;
	    pResult = pSelTimeout;
	    break;

	default:
	    /* Wait the specified number of milliseconds. */
	    pSelTimeout->tv_sec  = poll_timeout / 1000; /* get seconds */
	    poll_timeout        %= 1000;                /* remove seconds */
	    pSelTimeout->tv_usec = poll_timeout * 1000; /* get microseconds */
	    pResult = pSelTimeout;
	    break;
    }


    return pResult;
}

static void map_select_results
#if __STDC__ > 0
			 (struct pollfd *pArray,
			  unsigned long  n_fds,
			  fd_set        *pReadSet,
			  fd_set        *pWriteSet,
			  fd_set        *pExceptSet)
#else
			 (pArray, n_fds, pReadSet, pWriteSet, pExceptSet)
			  struct pollfd *pArray;
			  unsigned long  n_fds;
			  fd_set        *pReadSet;
			  fd_set        *pWriteSet;
			  fd_set        *pExceptSet;
#endif
{
    register unsigned long  i;                   /* loop control */
    register struct	    pollfd *pCur;        /* current array element */

    for (i = 0, pCur = pArray; i < n_fds; i++, pCur++)
    {
        /* Skip any bad FDs in the array. */

        if (pCur->fd < 0)
            continue;

	/* Exception events take priority over input events. */

	pCur->revents = 0;
	if (FD_ISSET (pCur->fd, pExceptSet))
	    pCur->revents |= POLLPRI;

	else if (FD_ISSET (pCur->fd, pReadSet))
	    pCur->revents |= POLLIN;

	if (FD_ISSET (pCur->fd, pWriteSet))
	    pCur->revents |= POLLOUT;
    }

    return;
}

/*---------------------------------------------------------------------------*\
			     Public Functions
\*---------------------------------------------------------------------------*/

int poll

#if __STDC__ > 0
	(struct pollfd *pArray, unsigned long n_fds, int timeout)
#else
	(pArray, n_fds, timeout)
	 struct	       pollfd *pArray;
	 unsigned long n_fds;
	 int	       timeout;
#endif

{
    fd_set  read_descs;                          /* input file descs */
    fd_set  write_descs;                         /* output file descs */
    fd_set  except_descs;                        /* exception descs */
    struct  timeval stime;                       /* select() timeout value */
    int	    ready_descriptors;                   /* function result */
    int	    max_fd;                              /* maximum fd value */
    struct  timeval *pTimeout;                   /* actually passed */

    FD_ZERO (&read_descs);
    FD_ZERO (&write_descs);
    FD_ZERO (&except_descs);

    assert (pArray != (struct pollfd *) NULL);

    /* Map the poll() file descriptor list in the select() data structures. */

    max_fd = map_poll_spec (pArray, n_fds,
			    &read_descs, &write_descs, &except_descs);

    /* Map the poll() timeout value in the select() timeout structure. */

    pTimeout = map_timeout (timeout, &stime);

    /* Make the select() call. */

    ready_descriptors = select (max_fd + 1, &read_descs, &write_descs,
				&except_descs, pTimeout);

    if (ready_descriptors >= 0)
    {
	map_select_results (pArray, n_fds,
			    &read_descs, &write_descs, &except_descs);
    }

    return ready_descriptors;
}

Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/Makefile,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- Makefile	25 Oct 2003 17:56:14 -0000	1.40
+++ Makefile	26 Oct 2003 18:50:48 -0000	1.41
@@ -157,6 +157,15 @@
 	cdr.o tdd.o acl.o rtp.o manager.o asterisk.o ast_expr.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
 	astmm.o enum.o srv.o dns.o
+ifeq (${OSARCH},Darwin)
+OBJS+=poll.o dlfcn.o
+ASTLINK=-Wl,-dynamic
+SOLINK=-dynamic -bundle -undefined suppress -force_flat_namespace
+else
+ASTLINK=-Wl,-E 
+SOLINK=-shared -Xlinker -x
+endif
+
 CC=gcc
 INSTALL=install
 
@@ -223,7 +232,7 @@
 	fi
 
 asterisk: editline/libedit.a db1-ast/libdb1.a stdtime/libtime.a $(OBJS)
-	$(CC) $(DEBUG) -o asterisk -Wl,-E $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a
+	$(CC) $(DEBUG) -o asterisk $(ASTLINK) $(OBJS) $(LIBS) $(LIBEDIT) db1-ast/libdb1.a stdtime/libtime.a
 
 subdirs: 
 	for x in $(SUBDIRS); do $(MAKE) -C $$x || exit 1 ; done

Index: dns.c
===================================================================
RCS file: /usr/cvsroot/asterisk/dns.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dns.c	27 Sep 2003 00:37:07 -0000	1.1
+++ dns.c	26 Oct 2003 18:50:48 -0000	1.2
@@ -178,10 +178,12 @@
 		else
 			ret = 1;
 	}
-#ifdef __Linux__
+#if defined(__Linux__)
 	res_nclose(&srvstate);
 #else
+#ifndef __APPLE__
 	res_close();
+#endif
 #endif
 	return ret;
 }

Index: enum.c
===================================================================
RCS file: /usr/cvsroot/asterisk/enum.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- enum.c	4 Oct 2003 21:58:16 -0000	1.10
+++ enum.c	26 Oct 2003 18:50:48 -0000	1.11
@@ -30,6 +30,11 @@
 #include <asterisk/channel.h>
 #include <asterisk/config.h>
 
+#ifdef __APPLE__
+#undef T_NAPTR
+#define T_NAPTR 35
+#endif
+
 #define TOPLEV "e164.arpa."
 
 static struct enum_search {

Index: io.c
===================================================================
RCS file: /usr/cvsroot/asterisk/io.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- io.c	12 Feb 2003 13:59:13 -0000	1.1.1.1
+++ io.c	26 Oct 2003 18:50:48 -0000	1.2
@@ -12,7 +12,6 @@
  */
 
 #include <stdio.h>
-#include <sys/poll.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <termios.h>

Index: loader.c
===================================================================
RCS file: /usr/cvsroot/asterisk/loader.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- loader.c	8 Sep 2003 16:48:06 -0000	1.7
+++ loader.c	26 Oct 2003 18:50:48 -0000	1.8
@@ -25,7 +25,11 @@
 #include <asterisk/manager.h>
 #include <asterisk/enum.h>
 #include <asterisk/rtp.h>
+#ifdef __APPLE__
+#include <asterisk/dlfcn-compat.h>
+#else
 #include <dlfcn.h>
+#endif
 #include <asterisk/md5.h>
 #include <pthread.h>
 #include "asterisk.h"

Index: srv.c
===================================================================
RCS file: /usr/cvsroot/asterisk/srv.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- srv.c	4 Oct 2003 21:58:16 -0000	1.4
+++ srv.c	26 Oct 2003 18:50:48 -0000	1.5
@@ -25,6 +25,11 @@
 #include <asterisk/dns.h>
 #include <asterisk/options.h>
 
+#ifdef __APPLE__
+#undef T_SRV
+#define T_SRV 33
+#endif
+
 struct srv {
 	unsigned short priority;
 	unsigned short weight;




More information about the svn-commits mailing list