summaryrefslogtreecommitdiff
path: root/libjava/java/net
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2007-01-25 19:51:33 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2007-01-25 19:51:33 +0000
commit4c83e7cbab75ede8fd63cf0619e7b69041ae57f0 (patch)
tree248bb6af58d66aec13f6a02b9c0cce7a33cb29a2 /libjava/java/net
parent462510b284a2390f4d84c5ed620abbe077740a3a (diff)
downloadgcc-4c83e7cbab75ede8fd63cf0619e7b69041ae57f0.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121183 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/net')
-rw-r--r--libjava/java/net/natVMURLConnection.cc47
1 files changed, 36 insertions, 11 deletions
diff --git a/libjava/java/net/natVMURLConnection.cc b/libjava/java/net/natVMURLConnection.cc
index 3429bb63dba..643f90a978c 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) */
}