diff options
author | Andrew Haley <aph@redhat.com> | 2007-01-25 19:51:33 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-25 19:51:33 +0000 |
commit | 9fe944471ab5828c0e4564780a57173a70cc4506 (patch) | |
tree | 248bb6af58d66aec13f6a02b9c0cce7a33cb29a2 /libjava/java | |
parent | a942e89f3acac05d7099f3ae12ee6a6fd531a051 (diff) | |
download | gcc-9fe944471ab5828c0e4564780a57173a70cc4506.zip gcc-9fe944471ab5828c0e4564780a57173a70cc4506.tar.gz gcc-9fe944471ab5828c0e4564780a57173a70cc4506.tar.bz2 |
configure, [...]: Rebuilt.
2007-01-25 Andrew Haley <aph@redhat.com>
* configure, Makefile.in, include/config.h.in: Rebuilt.
* Makefile.am (libgcj_la_LIBADD): Removed $(LIBMAGIC).
* configure.ac: Don't check for libmagic.
* java/net/natVMURLConnection.cc (p_magic_open, p_magic_load,
p_magic_close, p_magic_buffer): New globals.
(init): Look up 'magic' functions.
(guessContentTypeFromBuffer): Updated.
From-SVN: r121183
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/net/natVMURLConnection.cc | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/libjava/java/net/natVMURLConnection.cc b/libjava/java/net/natVMURLConnection.cc index 3429bb6..643f90a 100644 --- a/libjava/java/net/natVMURLConnection.cc +++ b/libjava/java/net/natVMURLConnection.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 Free Software Foundation +/* Copyright (C) 2006, 2007 Free Software Foundation This file is part of libgcj. @@ -11,46 +11,71 @@ details. */ #include <java/net/VMURLConnection.h> #include <gcj/cni.h> #include <java/lang/UnsupportedOperationException.h> +#include <stdio.h> -#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) +#if defined (HAVE_MAGIC_H) && defined (USE_LTDL) #include <magic.h> +#include <ltdl.h> static magic_t cookie; -#endif /* HAVE_MAGIC_H && HAVE_MAGIC_OPEN */ +static magic_t (*p_magic_open)(int flags); +static int (*p_magic_load)(magic_t cookie, const char *filename); +static void (*p_magic_close)(magic_t cookie); +static const char * (*p_magic_buffer) (magic_t cookie, const void *buffer, + size_t length); + +#endif /* HAVE_MAGIC_H && defined (USE_LTDL) */ void java::net::VMURLConnection::init () { -#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) - cookie = magic_open (MAGIC_MIME); +#if defined (HAVE_MAGIC_H) && defined (USE_LTDL) + lt_dlhandle handle = lt_dlopenext ("libmagic.so"); + if (!handle) + return; + + p_magic_open = (typeof (p_magic_open))lt_dlsym(handle, "magic_open"); + if (p_magic_open == NULL) + return; + p_magic_buffer = (typeof (p_magic_buffer))lt_dlsym(handle, "magic_buffer"); + if (p_magic_buffer == NULL) + return; + p_magic_close = (typeof (p_magic_close))lt_dlsym(handle, "magic_close"); + if (p_magic_close == NULL) + return; + p_magic_load = (typeof (p_magic_load))lt_dlsym(handle, "magic_load"); + if (p_magic_load == NULL) + return; + + cookie = p_magic_open (MAGIC_MIME); if (cookie == (magic_t) NULL) return; - if (magic_load (cookie, NULL) == -1) + if (p_magic_load (cookie, NULL) == -1) { - magic_close (cookie); + p_magic_close (cookie); cookie = (magic_t) NULL; } -#endif /* HAVE_MAGIC_H && HAVE_MAGIC_OPEN */ +#endif /* HAVE_MAGIC_H && defined (USE_LTDL) */ } ::java::lang::String * java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray bytes, jint valid) { -#if defined (HAVE_MAGIC_H) && defined (HAVE_MAGIC_OPEN) +#if defined (HAVE_MAGIC_H) && defined (USE_LTDL) const char *result; if (cookie == (magic_t) NULL) return NULL; - result = magic_buffer (cookie, elements(bytes), valid); + result = p_magic_buffer (cookie, elements(bytes), valid); if (result == NULL) return NULL; return _Jv_NewStringUTF (result); #else return NULL; -#endif /* HAVE_MAGIC_H && HAVE_MAGIC_OPEN */ +#endif /* HAVE_MAGIC_H && defined (USE_LTDL) */ } |