OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [java/] [net/] [natVMURLConnection.cc] - Blame information for rev 780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 758 jeremybenn
/* Copyright (C) 2006, 2007  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
#include <config.h>
10
 
11
#include <java/net/VMURLConnection.h>
12
#include <gcj/cni.h>
13
#include <java/lang/UnsupportedOperationException.h>
14
#include <stdio.h>
15
 
16
#if defined (HAVE_MAGIC_T) && defined (HAVE_MAGIC_H) && defined (USE_LTDL)
17
 
18
#include <magic.h>
19
#include <ltdl.h>
20
 
21
static magic_t cookie;
22
 
23
static magic_t (*p_magic_open)(int flags);
24
static int (*p_magic_load)(magic_t cookie, const char *filename);
25
static void (*p_magic_close)(magic_t cookie);
26
static const char * (*p_magic_buffer) (magic_t cookie, const void *buffer,
27
                                       size_t length);
28
 
29
#endif /* HAVE_MAGIC_T && HAVE_MAGIC_H && defined (USE_LTDL) */
30
 
31
void
32
java::net::VMURLConnection::init ()
33
{
34
#if defined (HAVE_MAGIC_T) && defined (HAVE_MAGIC_H) && defined (USE_LTDL)
35
  lt_dlhandle handle = lt_dlopenext ("libmagic.so");
36
  if (!handle)
37
    return;
38
 
39
  p_magic_open = (typeof (p_magic_open))lt_dlsym(handle, "magic_open");
40
  if (p_magic_open == NULL)
41
    return;
42
  p_magic_buffer = (typeof (p_magic_buffer))lt_dlsym(handle, "magic_buffer");
43
  if (p_magic_buffer == NULL)
44
    return;
45
  p_magic_close = (typeof (p_magic_close))lt_dlsym(handle, "magic_close");
46
  if (p_magic_close == NULL)
47
    return;
48
  p_magic_load = (typeof (p_magic_load))lt_dlsym(handle, "magic_load");
49
  if (p_magic_load == NULL)
50
    return;
51
 
52
  cookie = p_magic_open (MAGIC_MIME);
53
  if (cookie == (magic_t) NULL)
54
    return;
55
  if (p_magic_load (cookie, NULL) == -1)
56
    {
57
      p_magic_close (cookie);
58
      cookie = (magic_t) NULL;
59
    }
60
#endif /* HAVE_MAGIC_T && HAVE_MAGIC_H  && defined (USE_LTDL) */
61
}
62
 
63
::java::lang::String *
64
java::net::VMURLConnection::guessContentTypeFromBuffer (jbyteArray bytes __attribute__ ((unused)),
65
                                                        jint valid __attribute__ ((unused)))
66
{
67
#if defined (HAVE_MAGIC_T) && defined (HAVE_MAGIC_H) && defined (USE_LTDL)
68
  const char *result;
69
 
70
  if (cookie == (magic_t) NULL)
71
    return NULL;
72
 
73
  result = p_magic_buffer (cookie, elements(bytes), valid);
74
 
75
  if (result == NULL)
76
    return NULL;
77
  return _Jv_NewStringUTF (result);
78
#else
79
  return NULL;
80
#endif /* HAVE_MAGIC_T && HAVE_MAGIC_H  && defined (USE_LTDL) */
81
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.