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
This commit is contained in:
parent
a942e89f3a
commit
9fe944471a
10 changed files with 49 additions and 110 deletions
|
@ -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) */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue