Revision: 54057
http://brlcad.svn.sourceforge.net/brlcad/?rev=54057&view=rev
Author: caen23
Date: 2012-12-13 19:20:26 +0000 (Thu, 13 Dec 2012)
Log Message:
-----------
Implement portable bu_gethostname() function (GCI:
http://www.google-melange.com/gci/task/view/google/gci2012/7992229)
Modified Paths:
--------------
brlcad/trunk/include/bu.h
brlcad/trunk/src/libbu/CMakeLists.txt
brlcad/trunk/src/libbu/tests/CMakeLists.txt
Added Paths:
-----------
brlcad/trunk/src/libbu/gethostname.c
brlcad/trunk/src/libbu/tests/bu_gethostname.c
Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h 2012-12-13 14:46:20 UTC (rev 54056)
+++ brlcad/trunk/include/bu.h 2012-12-13 19:20:26 UTC (rev 54057)
@@ -6223,6 +6223,12 @@
*/
BU_EXPORT extern int bu_str_isprint(const char *cp);
+/** @file libbu/gethostname.c
+ *
+ * Portable gethostname()
+ *
+ */
+BU_EXPORT extern int bu_gethostname(char *, size_t);
__END_DECLS
Modified: brlcad/trunk/src/libbu/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/CMakeLists.txt 2012-12-13 14:46:20 UTC (rev
54056)
+++ brlcad/trunk/src/libbu/CMakeLists.txt 2012-12-13 19:20:26 UTC (rev
54057)
@@ -37,6 +37,7 @@
fnmatch.c
fopen_uniq.c
getcwd.c
+ gethostname.c
getopt.c
globals.c
hash.c
Added: brlcad/trunk/src/libbu/gethostname.c
===================================================================
--- brlcad/trunk/src/libbu/gethostname.c (rev 0)
+++ brlcad/trunk/src/libbu/gethostname.c 2012-12-13 19:20:26 UTC (rev
54057)
@@ -0,0 +1,57 @@
+/* G E T H O S T N A M E . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2012 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+#include "common.h"
+
+#include "bio.h"
+#include "bin.h"
+
+#include "bu.h"
+
+/**
+ * Windows requires some initialisations before gethostname() can be used.
+ */
+int
+bu_gethostname(char *hostname, size_t hostlen)
+{
+ int status;
+
+#if defined(WIN32)
+ WSADATA wsaData;
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
+
+ status = gethostname(hostname, hostlen);
+
+#if defined(WIN32)
+ WSACleanup();
+#endif
+
+ return status;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbu/gethostname.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: brlcad/trunk/src/libbu/tests/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-12-13 14:46:20 UTC (rev
54056)
+++ brlcad/trunk/src/libbu/tests/CMakeLists.txt 2012-12-13 19:20:26 UTC (rev
54057)
@@ -1,4 +1,5 @@
BRLCAD_ADDEXEC(tester_bu_sscanf bu_sscanf.c libbu NO_INSTALL LOCAL)
+BRLCAD_ADDEXEC(tester_bu_gethostname bu_gethostname.c libbu NO_INSTALL LOCAL)
#
# ************ basename.c tests *************
Added: brlcad/trunk/src/libbu/tests/bu_gethostname.c
===================================================================
--- brlcad/trunk/src/libbu/tests/bu_gethostname.c
(rev 0)
+++ brlcad/trunk/src/libbu/tests/bu_gethostname.c 2012-12-13 19:20:26 UTC
(rev 54057)
@@ -0,0 +1,50 @@
+/* T E S T _ G E T H O S T N A M E . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2011-2012 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#include "common.h"
+
+#include <stdio.h>
+
+#include "bu.h"
+
+
+int
+main(void)
+{
+ char host[100];
+ int status;
+
+ status = bu_gethostname(host, 100);
+ printf("%s\n", host);
+ printf("%d\n", status);
+
+ return status;
+}
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/trunk/src/libbu/tests/bu_gethostname.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits