Author: vedge
Date: 2012-07-18 22:03:52 -0400 (Wed, 18 Jul 2012)
New Revision: 959

Added:
   trunk/BSDBuild/gethostbyname.pm
   trunk/BSDBuild/getpwnam_r.pm
   trunk/BSDBuild/sockopts.pm
Modified:
   trunk/BSDBuild/Makefile
   trunk/BSDBuild/getpwuid.pm
Log:
add tests for getpwnam_r(), setsockopt()/getsockopt() and gethostbyname()



Modified: trunk/BSDBuild/Makefile
===================================================================
--- trunk/BSDBuild/Makefile     2012-07-13 11:13:08 UTC (rev 958)
+++ trunk/BSDBuild/Makefile     2012-07-19 02:03:52 UTC (rev 959)
@@ -36,6 +36,7 @@
        arc4random.pm \
        pctr.pm \
        getpwuid.pm \
+       getpwnam_r.pm \
        getuid.pm \
        md5.pm \
        sha1.pm \
@@ -56,6 +57,7 @@
        perl.pm \
        libidn.pm \
        getaddrinfo.pm \
+       gethostbyname.pm \
        glu.pm \
        ode.pm \
        sse.pm \
@@ -104,7 +106,8 @@
        xinerama.pm \
        portaudio.pm \
        mysql.pm \
-       cocoa.pm
+       cocoa.pm \
+       sockopts.pm
 
 all:
 

Added: trunk/BSDBuild/gethostbyname.pm
===================================================================
--- trunk/BSDBuild/gethostbyname.pm                             (rev 0)
+++ trunk/BSDBuild/gethostbyname.pm     2012-07-19 02:03:52 UTC (rev 959)
@@ -0,0 +1,65 @@
+# vim:ts=4
+#
+# Copyright (c) 2012 Hypertriton, Inc. <http://www.hypertriton.com/>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution..
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..
+
+sub Test
+{
+       TryCompile 'HAVE_GETHOSTBYNAME', << 'EOF';
+#include <string.h>
+#include <netdb.h>
+
+int
+main(int argc, char *argv[])
+{
+       struct hostent *hp;
+       const char *host = "localhost";
+
+       hp = gethostbyname(host);
+       return (hp == NULL);
+}
+EOF
+}
+
+sub Emul
+{
+       my ($os, $osrel, $machine) = @_;
+
+       if ($os eq 'linux' || $os eq 'darwin' || $os =~ /^(open|net|free)bsd/) {
+               MkDefine('HAVE_GETHOSTBYNAME', 'yes');
+               MkSaveDefine('HAVE_GETHOSTBYNAME');
+       } else {
+               MkSaveUndef('HAVE_GETHOSTBYNAME');
+       }
+       return (1);
+}
+
+BEGIN
+{
+       $TESTS{'gethostbyname'} = \&Test;
+       $DEPS{'gethostbyname'} = 'cc';
+       $EMUL{'gethostbyname'} = \&Emul;
+       $DESCR{'gethostbyname'} = 'the gethostbyname() function';
+}
+
+;1

Added: trunk/BSDBuild/getpwnam_r.pm
===================================================================
--- trunk/BSDBuild/getpwnam_r.pm                                (rev 0)
+++ trunk/BSDBuild/getpwnam_r.pm        2012-07-19 02:03:52 UTC (rev 959)
@@ -0,0 +1,78 @@
+# vim:ts=4
+#
+# Copyright (c) 2012 Hypertriton Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution..
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..
+
+sub Test
+{
+       TryCompile 'HAVE_GETPWNAM_R', << 'EOF';
+#include <sys/types.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+int
+main(int argc, char *argv[])
+{
+       struct passwd pw, *res;
+       char *buf;
+       size_t bufSize;
+       int rv;
+
+       bufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
+       if (bufSize == -1) { bufSize = 16384; }
+       if ((buf = malloc(bufSize)) == NULL) { return (1); }
+
+       rv = getpwnam_r("foo", &pw, buf, bufSize, &res);
+       if (res == NULL) {
+               return (rv == 0);
+       }
+       return (pw.pw_class != NULL && pw.pw_gecos != NULL && pw.pw_dir != 
NULL);
+}
+EOF
+}
+
+sub Emul
+{
+       my ($os, $osrel, $machine) = @_;
+
+       if ($os eq 'linux' || $os eq 'darwin' || $os =~ /^(open|net|free)bsd$/) 
{
+               MkDefine('HAVE_GETPWNAM_R', 'yes');
+               MkSaveDefine('HAVE_GETPWNAM_R');
+       } else {
+               MkSaveUndef('HAVE_GETPWNAM_R');
+       PWNAM_R}
+       return (1);
+}
+
+BEGIN
+{
+       $DESCR{'getpwnam_r'} = 'the getpwnam_r() interface';
+       $DEPS{'getpwnam_r'} = 'cc';
+       $TESTS{'getpwnam_r'} = \&Test;
+       $EMUL{'getpwnam_r'} = \&Emul;
+}
+
+;1

Modified: trunk/BSDBuild/getpwuid.pm
===================================================================
--- trunk/BSDBuild/getpwuid.pm  2012-07-13 11:13:08 UTC (rev 958)
+++ trunk/BSDBuild/getpwuid.pm  2012-07-19 02:03:52 UTC (rev 959)
@@ -39,7 +39,7 @@
        uid_t uid = 0;
 
        pwd = getpwuid(uid);
-       return (pwd != NULL);
+       return (pwd != NULL && pwd->pw_gecos != NULL && pwd->pw_class != NULL);
 }
 EOF
 }

Added: trunk/BSDBuild/sockopts.pm
===================================================================
--- trunk/BSDBuild/sockopts.pm                          (rev 0)
+++ trunk/BSDBuild/sockopts.pm  2012-07-19 02:03:52 UTC (rev 959)
@@ -0,0 +1,133 @@
+# vim:ts=4
+#
+# Copyright (c) 2012 Hypertriton, Inc. <http://www.hypertriton.com/>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution..
+# 
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE..
+
+sub CheckBoolOption
+{
+       my $opt = shift;
+
+       MkPrintN("checking for $opt...");
+       TryCompile "HAVE_$opt", << "EOF";
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+int
+main(int argc, char *argv[])
+{
+       int fd = 0, val = 1, rv;
+       socklen_t valLen = sizeof(val);
+       rv = setsockopt(fd, SOL_SOCKET, $opt, &val, valLen);
+       return (rv != 0);
+}
+EOF
+}
+
+sub Test
+{
+       TryCompile 'HAVE_SETSOCKOPT', << 'EOF';
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <fcntl.h>
+int
+main(int argc, char *argv[])
+{
+       int fd = 0, rv;
+       struct timeval tv;
+       socklen_t tvLen = sizeof(tv);
+       tv.tv_sec = 1; tv.tv_usec = 0;
+       rv = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, tvLen);
+       return (rv != 0);
+}
+EOF
+       MkIfTrue('${HAVE_SETSOCKOPT}');
+               CheckBoolOption('SO_OOBINLINE');
+               CheckBoolOption('SO_REUSEPORT');
+               CheckBoolOption('SO_TIMESTAMP');
+               CheckBoolOption('SO_NOSIGPIPE');
+
+               MkPrintN('checking for SO_LINGER...');
+               TryCompile 'HAVE_SO_LINGER', << 'EOF';
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+int
+main(int argc, char *argv[])
+{
+       int fd = 0, rv;
+       struct linger ling;
+       socklen_t lingLen = sizeof(ling);
+       ling.l_onoff = 1; ling.l_linger = 1;
+       rv = setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, lingLen);
+       return (rv != 0);
+}
+EOF
+               MkPrintN('checking for SO_ACCEPTFILTER...');
+               TryCompile 'HAVE_SO_ACCEPTFILTER', << 'EOF';
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+int
+main(int argc, char *argv[])
+{
+       int fd = 0, rv;
+       struct accept_filter_arg afa;
+       socklen_t afaLen = sizeof(afa);
+       afa.af_name[0] = '\0';
+       afa.af_arg[0] = '\0';
+       rv = setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, afaLen);
+       return (rv != 0);
+}
+EOF
+       MkEndif;
+}
+
+sub Emul
+{
+       my ($os, $osrel, $machine) = @_;
+
+       if ($os eq 'linux' || $os eq 'darwin' || $os =~ /^(open|net|free)bsd/) {
+               MkDefine('HAVE_SETSOCKOPT', 'yes');
+               MkSaveDefine('HAVE_SETSOCKOPT');
+       } else {
+               MkSaveUndef('HAVE_SETSOCKOPT');
+       }
+       MkSaveUndef('HAVE_SO_OOBINLINE');
+       MkSaveUndef('HAVE_SO_REUSEPORT');
+       MkSaveUndef('HAVE_SO_TIMESTAMP');
+       MkSaveUndef('HAVE_SO_NOSIGPIPE');
+       MkSaveUndef('HAVE_SO_LINGER');
+       MkSaveUndef('HAVE_SO_ACCEPTFILTER');
+       return (1);
+}
+
+BEGIN
+{
+       $TESTS{'sockopts'} = \&Test;
+       $DEPS{'sockopts'} = 'cc';
+       $EMUL{'sockopts'} = \&Emul;
+       $DESCR{'sockopts'} = 'the setsockopt() interface';
+}
+
+;1

_______________________________________________
BSDBuild-Commits mailing list
BSDBuild-Commits@hypertriton.com
http://mail231.csoft.net/mailman/listinfo/bsdbuild-commits

Reply via email to