Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added replacements for missing system/library calls

  • Loading branch information...
commit b1b799a49bccbfb79242edc2a2aa40ace49137f5 1 parent 027ccad
rtv authored
View
8 configure.in
@@ -1,7 +1,7 @@
dnl -----------------------------------------------------------------------
dnl Stage Autoconf script
-dnl $Id: configure.in,v 1.31 2002-12-04 22:44:32 rtv Exp $
+dnl $Id: configure.in,v 1.32 2002-12-05 01:50:22 rtv Exp $
dnl -----------------------------------------------------------------------
dnl Process this file with autoconf to produce a configure script.
@@ -44,11 +44,14 @@ dnl Checks for header files.
AC_CHECK_HEADERS(stdint.h strings.h values.h)
dnl Checks for library functions.
-AC_REPLACE_FUNCS(poll dirname)
AC_CHECK_LIB(z, gzopen)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)
+dnl build mplementations of these in libreplace.a if these are
+dnl missing
+AC_REPLACE_FUNCS(poll dirname scandir)
+
dnl Test for socklen_t and define it to int if it's not there.
dnl Note that we can't simply dnl use AC_CHECK_TYPE because socklen_t
dnl isn't in the standard headers (autoconf-2.5 has better methods for this)
@@ -139,6 +142,7 @@ with_tests=yes)
AM_CONDITIONAL(WITH_TESTS, test x$with_tests = xyes)
AC_OUTPUT(Makefile
+ replace/Makefile
src/Makefile
src/models/Makefile
src/gnome2/Makefile
View
7 replace/Makefile.am
@@ -0,0 +1,7 @@
+noinst_LIBRARIES = libreplace.a
+
+libreplace_a_LIBADD = @LIBOBJS@
+
+libreplace_a_SOURCES = dummy.c
+
+EXTRA_DIST = dirname.c poll.c replace.h scandir.c
View
58 replace/dirname.c
@@ -0,0 +1,58 @@
+/* dirname - return directory part of PATH.
+ Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * $Id: dirname.c,v 1.1 2002-12-05 01:50:22 rtv Exp $
+ *
+ * taken from glibc, modified slightly for standalone compilation, and used as
+ * a fallback implementation when dirname() is not available. - BPG
+ */
+
+#include <string.h>
+
+char *
+dirname (char *path)
+{
+ static const char dot[] = ".";
+ char *last_slash;
+
+ /* Find last '/'. */
+ last_slash = path != NULL ? strrchr (path, '/') : NULL;
+
+ if (last_slash == path)
+ /* The last slash is the first character in the string. We have to
+ return "/". */
+ ++last_slash;
+ else if (last_slash != NULL && last_slash[1] == '\0')
+ /* The '/' is the last character, we have to look further. */
+ last_slash = memchr (path, last_slash - path, '/');
+
+ if (last_slash != NULL)
+ /* Terminate the path. */
+ last_slash[0] = '\0';
+ else
+ /* This assignment is ill-designed but the XPG specs require to
+ return a string containing "." in any case no directory part is
+ found and so a static and constant string is required. */
+ path = (char *) dot;
+
+ return path;
+}
+
View
7 replace/dummy.c
@@ -0,0 +1,7 @@
+/* a dummy function so that libreplace.a is never empty, even when nothing
+ * needs to be replaced */
+int player_dummy(void)
+{
+ return(0);
+}
+
View
199 replace/poll.c
@@ -0,0 +1,199 @@
+/* Copyright (C) 1994, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * $Id: poll.c,v 1.1 2002-12-05 01:50:22 rtv Exp $
+ *
+ * taken from glibc, modified slightly for standalone compilation, and used as
+ * a fallback implementation when poll() is not available. - BPG
+ */
+
+#include "replace.h"
+
+//#include <alloca.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/param.h>
+#include <unistd.h>
+
+/* Poll the file descriptors described by the NFDS structures starting at
+ FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for
+ an event to occur; if TIMEOUT is -1, block until an event occurs.
+ Returns the number of file descriptors with events, zero if timed out,
+ or -1 for errors. */
+
+int
+poll(struct pollfd* fds, unsigned long int nfds, int timeout)
+{
+ static int max_fd_size;
+ struct timeval tv;
+ fd_set *rset, *wset, *xset;
+ struct pollfd *f;
+ int ready;
+ int maxfd = 0;
+ int bytes;
+
+ if (!max_fd_size)
+ max_fd_size = getdtablesize ();
+
+ bytes = howmany (max_fd_size, NFDBITS);
+ rset = alloca (bytes);
+ wset = alloca (bytes);
+ xset = alloca (bytes);
+
+ /* We can't call FD_ZERO, since FD_ZERO only works with sets
+ of exactly FD_SETSIZE size. */
+ bzero (rset, bytes);
+ bzero (wset, bytes);
+ bzero (xset, bytes);
+
+ for (f = fds; f < &fds[nfds]; ++f)
+ {
+ f->revents = 0;
+ if (f->fd >= 0)
+ {
+ if (f->fd >= max_fd_size)
+ {
+ /* The user provides a file descriptor number which is higher
+ than the maximum we got from the `getdtablesize' call.
+ Maybe this is ok so enlarge the arrays. */
+ fd_set *nrset, *nwset, *nxset;
+ int nbytes;
+
+ max_fd_size = roundup (f->fd, NFDBITS);
+ nbytes = howmany (max_fd_size, NFDBITS);
+
+ nrset = alloca (nbytes);
+ nwset = alloca (nbytes);
+ nxset = alloca (nbytes);
+
+ bzero ((char *) nrset + bytes, nbytes - bytes);
+ bzero ((char *) nwset + bytes, nbytes - bytes);
+ bzero ((char *) nxset + bytes, nbytes - bytes);
+
+ rset = memcpy (nrset, rset, bytes);
+ wset = memcpy (nwset, wset, bytes);
+ xset = memcpy (nxset, xset, bytes);
+
+ bytes = nbytes;
+ }
+
+ if (f->events & POLLIN)
+ FD_SET (f->fd, rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, xset);
+ if (f->fd > maxfd && (f->events & (POLLIN|POLLOUT|POLLPRI)))
+ maxfd = f->fd;
+ }
+ }
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+
+ while (1)
+ {
+ ready = select (maxfd + 1, rset, wset, xset,
+ timeout == -1 ? NULL : &tv);
+
+ /* It might be that one or more of the file descriptors is invalid.
+ We now try to find and mark them and then try again. */
+ if (ready == -1 && errno == EBADF)
+ {
+ fd_set *sngl_rset = alloca (bytes);
+ fd_set *sngl_wset = alloca (bytes);
+ fd_set *sngl_xset = alloca (bytes);
+ struct timeval sngl_tv;
+
+ /* Clear the original set. */
+ bzero (rset, bytes);
+ bzero (wset, bytes);
+ bzero (xset, bytes);
+
+ /* This means we don't wait for input. */
+ sngl_tv.tv_sec = 0;
+ sngl_tv.tv_usec = 0;
+
+ maxfd = -1;
+
+ /* Reset the return value. */
+ ready = 0;
+
+ for (f = fds; f < &fds[nfds]; ++f)
+ if (f->fd != -1 && (f->events & (POLLIN|POLLOUT|POLLPRI))
+ && (f->revents & POLLNVAL) == 0)
+ {
+ int n;
+
+ bzero (sngl_rset, bytes);
+ bzero (sngl_wset, bytes);
+ bzero (sngl_xset, bytes);
+
+ if (f->events & POLLIN)
+ FD_SET (f->fd, sngl_rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, sngl_wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, sngl_xset);
+
+ n = select (f->fd + 1, sngl_rset, sngl_wset, sngl_xset,
+ &sngl_tv);
+ if (n != -1)
+ {
+ /* This descriptor is ok. */
+ if (f->events & POLLIN)
+ FD_SET (f->fd, rset);
+ if (f->events & POLLOUT)
+ FD_SET (f->fd, wset);
+ if (f->events & POLLPRI)
+ FD_SET (f->fd, xset);
+ if (f->fd > maxfd)
+ maxfd = f->fd;
+ if (n > 0)
+ /* Count it as being available. */
+ ++ready;
+ }
+ else if (errno == EBADF)
+ f->revents |= POLLNVAL;
+ }
+ /* Try again. */
+ continue;
+ }
+
+ break;
+ }
+
+ if (ready > 0)
+ for (f = fds; f < &fds[nfds]; ++f)
+ {
+ if (f->fd >= 0)
+ {
+ if (FD_ISSET (f->fd, rset))
+ f->revents |= POLLIN;
+ if (FD_ISSET (f->fd, wset))
+ f->revents |= POLLOUT;
+ if (FD_ISSET (f->fd, xset))
+ f->revents |= POLLPRI;
+ }
+ }
+
+ return ready;
+}
View
98 replace/replace.h
@@ -0,0 +1,98 @@
+/* $Id: replace.h,v 1.1 2002-12-05 01:50:22 rtv Exp $
+ *
+ * replacement function prototypes
+ */
+
+#ifndef _REPLACE_H
+#define _REPLACE_H
+
+
+#if HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
+/* Compatibility definitions for System V `poll' interface.
+ Copyright (C) 1994,96,97,98,99,2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !HAVE_POLL
+/* Event types that can be polled for. These bits may be set in `events'
+ to indicate the interesting event types; they will appear in `revents'
+ to indicate the status of the file descriptor. */
+#define POLLIN 01 /* There is data to read. */
+#define POLLPRI 02 /* There is urgent data to read. */
+#define POLLOUT 04 /* Writing now will not block. */
+
+/* Some aliases. */
+#define POLLWRNORM POLLOUT
+#define POLLRDNORM POLLIN
+#define POLLRDBAND POLLPRI
+
+/* Event types always implicitly polled for. These bits need not be set in
+ `events', but they will appear in `revents' to indicate the status of
+ the file descriptor. */
+#define POLLERR 010 /* Error condition. */
+#define POLLHUP 020 /* Hung up. */
+#define POLLNVAL 040 /* Invalid polling request. */
+
+/* Canonical number of polling requests to read in at a time in poll. */
+#define NPOLLFILE 30
+
+/* Data structure describing a polling request. */
+struct pollfd
+ {
+ int fd; /* File descriptor to poll. */
+ short int events; /* Types of events poller cares about. */
+ short int revents; /* Types of events that actually occurred. */
+ };
+
+
+/* Poll the file descriptors described by the NFDS structures starting at
+ FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for
+ an event to occur; if TIMEOUT is -1, block until an event occurs.
+ Returns the number of file descriptors with events, zero if timed out,
+ or -1 for errors. */
+int poll (struct pollfd *fds, unsigned long int nfds, int timeout);
+#else
+#include <sys/poll.h> /* for poll(2) */
+#endif // !HAVE_POLL
+
+#if !HAVE_SCANDIR
+#include <sys/types.h>
+#include <dirent.h>
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*compar)(const struct dirent **, const struct dirent **));
+#endif //!HAVE_SCANDIR
+
+#if !HAVE_DIRNAME
+ char * dirname (char *path);
+#else
+ #include <libgen.h> // for dirname(3)
+#endif // !HAVE_DIRNAME
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
View
100 replace/scandir.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 1992-1998, 2000 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * $Id: scandir.c,v 1.1 2002-12-05 01:50:22 rtv Exp $
+ *
+ * taken from glibc, modified slightly for standalone compilation, and used as
+ * a fallback implementation when scandir() is not available. - BPG
+ */
+
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int
+scandir(dir, namelist, select, cmp)
+ const char *dir;
+ struct dirent ***namelist;
+ int (*select) (const struct dirent *);
+ int (*cmp) (const void *, const void *);
+{
+ DIR *dp = opendir (dir);
+ struct dirent **v = NULL;
+ size_t vsize = 0, i;
+ struct dirent *d;
+ int save;
+
+ if (dp == NULL)
+ return -1;
+
+ save = errno;
+ errno = 0;
+
+ i = 0;
+ while ((d = readdir (dp)) != NULL)
+ if (select == NULL || (*select) (d))
+ {
+ struct dirent *vnew;
+ size_t dsize;
+
+ /* Ignore errors from select or readdir */
+ errno = 0;
+
+ if (i == vsize)
+ {
+ struct dirent **new;
+ if (vsize == 0)
+ vsize = 10;
+ else
+ vsize *= 2;
+ new = (struct dirent **) realloc (v, vsize * sizeof (*v));
+ if (new == NULL)
+ break;
+ v = new;
+ }
+
+ dsize = &d->d_name[strlen(d->d_name)+1] - (char *) d;
+ vnew = (struct dirent *) malloc (dsize);
+ if (vnew == NULL)
+ break;
+
+ v[i++] = (struct dirent *) memcpy (vnew, d, dsize);
+ }
+
+ if (errno != 0)
+ {
+ save = errno;
+ (void) closedir (dp);
+ while (i > 0)
+ free (v[--i]);
+ free (v);
+ errno = save;
+ return -1;
+ }
+
+ (void) closedir (dp);
+ errno = save;
+
+ /* Sort the list if we have a comparison function to sort with. */
+ if (cmp != NULL)
+ qsort (v, i, sizeof (*v), cmp);
+ *namelist = v;
+ return i;
+}
View
1  src/models/regularmcldevice_clustering.cc
@@ -25,6 +25,7 @@
#include "regularmcldevice.hh"
+#include <math.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
Please sign in to comment.
Something went wrong with that request. Please try again.