[vlc-devel] commit: xcb_window: Use sysconf to discover HOST_NAME_MAX. (Alexis Ballier )
git version control
git at videolan.org
Sat Jul 11 12:18:22 CEST 2009
vlc | branch: master | Alexis Ballier <aballier at gentoo.org> | Fri Jul 10 15:04:42 2009 +0200| [a73ea66ebb2b60d1e2e83a9ab17feefb8ad15e16] | committer: Rémi Denis-Courmont
xcb_window: Use sysconf to discover HOST_NAME_MAX.
POSIX does not mandate HOST_NAME_MAX to be defined and FreeBSD does not
define it to encourage people to use sysconf() for discovering its
value. If sysconf fails, fallback to _POSIX_HOST_NAME_MAX.
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net> (with minor changes)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a73ea66ebb2b60d1e2e83a9ab17feefb8ad15e16
---
modules/video_output/xcb/window.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index 0ec23dd..d8db243 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -27,8 +27,8 @@
#include <stdarg.h>
#include <assert.h>
#include <poll.h>
-#include <unistd.h> /* gethostname() */
-#include <limits.h> /* HOST_NAME_MAX */
+#include <unistd.h> /* gethostname() and sysconf() */
+#include <limits.h> /* _POSIX_HOST_NAME_MAX */
#include <xcb/xcb.h>
typedef xcb_atom_t Atom;
@@ -96,13 +96,18 @@ void set_ascii_prop (xcb_connection_t *conn, xcb_window_t window,
static inline
void set_hostname_prop (xcb_connection_t *conn, xcb_window_t window)
{
- char hostname[HOST_NAME_MAX];
+ char* hostname;
+ long host_name_max = sysconf (_SC_HOST_NAME_MAX);
+ if (host_name_max <= 0) host_name_max = _POSIX_HOST_NAME_MAX;
+ hostname = malloc (host_name_max);
+ if(!hostname) return;
- if (gethostname (hostname, sizeof (hostname)) == 0)
+ if (gethostname (hostname, host_name_max) == 0)
{
- hostname[sizeof (hostname) - 1] = '\0';
+ hostname[host_name_max - 1] = '\0';
set_ascii_prop (conn, window, XA_WM_CLIENT_MACHINE, hostname);
}
+ free(hostname);
}
static inline
More information about the vlc-devel
mailing list