summaryrefslogtreecommitdiff
path: root/libjava/java/net/natVMURLConnection.cc
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/java/net/natVMURLConnection.cc
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/java/net/natVMURLConnection.cc')
-rw-r--r--libjava/java/net/natVMURLConnection.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/libjava/java/net/natVMURLConnection.cc b/libjava/java/net/natVMURLConnection.cc
new file mode 100644
index 000000000..0a30a2197
--- /dev/null
+++ b/libjava/java/net/natVMURLConnection.cc
@@ -0,0 +1,81 @@
+/* Copyright (C) 2006, 2007 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <java/net/VMURLConnection.h>
+#include <gcj/cni.h>
+#include <java/lang/UnsupportedOperationException.h>
+#include <stdio.h>
+
+#if defined (HAVE_MAGIC_T) && defined (HAVE_MAGIC_H) && defined (USE_LTDL)
+
+#include <magic.h>
+#include <ltdl.h>
+
+static magic_t cookie;
+
+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_T && HAVE_MAGIC_H && defined (USE_LTDL) */
+
+void
+java::net::VMURLConnection::init ()
+{
+#if defined (HAVE_MAGIC_T) && 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 (p_magic_load (cookie, NULL) == -1)
+ {
+ p_magic_close (cookie);
+ cookie = (magic_t) NULL;
+ }
+#endif /* HAVE_MAGIC_T && HAVE_MAGIC_H && defined (USE_LTDL) */
+}
+
+::java::lang::String *
+java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray bytes __attribute__ ((unused)),
+ jint valid __attribute__ ((unused)))
+{
+#if defined (HAVE_MAGIC_T) && defined (HAVE_MAGIC_H) && defined (USE_LTDL)
+ const char *result;
+
+ if (cookie == (magic_t) NULL)
+ return NULL;
+
+ result = p_magic_buffer (cookie, elements(bytes), valid);
+
+ if (result == NULL)
+ return NULL;
+ return _Jv_NewStringUTF (result);
+#else
+ return NULL;
+#endif /* HAVE_MAGIC_T && HAVE_MAGIC_H && defined (USE_LTDL) */
+}