source: trunk/openjdk/jdk/src/share/instrument/JarFacade.c

Last change on this file was 333, checked in by dmik, 14 years ago

jdk: Fix a whole bunch of warnings and a few build errors.

GCC is more strict than MSVC.

File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#include <string.h>
27#include <stdlib.h>
28
29#ifdef __EMX__
30#include <strings.h> // strcasecmp
31#endif
32
33#include "jni.h"
34#include "manifest_info.h"
35#include "JarFacade.h"
36
37typedef struct {
38 jarAttribute* head;
39 jarAttribute* tail;
40} iterationContext;
41
42static void
43doAttribute(const char* name, const char* value, void* user_data) {
44 iterationContext* context = (iterationContext*) user_data;
45
46 jarAttribute* attribute = (jarAttribute*)malloc(sizeof(jarAttribute));
47 if (attribute != NULL) {
48 attribute->name = strdup(name);
49 if (attribute->name == NULL) {
50 free(attribute);
51 } else {
52 attribute->value = strdup(value);
53 if (attribute->value == NULL) {
54 free(attribute->name);
55 free(attribute);
56 } else {
57 attribute->next = NULL;
58 if (context->head == NULL) {
59 context->head = attribute;
60 } else {
61 context->tail->next = attribute;
62 }
63 context->tail = attribute;
64 }
65 }
66
67 }
68}
69
70/*
71 * Return a list of attributes from the main section of the given JAR
72 * file. Returns NULL if there is an error or there aren't any attributes.
73 */
74jarAttribute*
75readAttributes(const char* jarfile)
76{
77 int rc;
78 iterationContext context = { NULL, NULL };
79
80 rc = JLI_ManifestIterate(jarfile, doAttribute, (void*)&context);
81
82 if (rc == 0) {
83 return context.head;
84 } else {
85 freeAttributes(context.head);
86 return NULL;
87 }
88}
89
90
91/*
92 * Free a list of attributes
93 */
94void
95freeAttributes(jarAttribute* head) {
96 while (head != NULL) {
97 jarAttribute* next = (jarAttribute*)head->next;
98 free(head->name);
99 free(head->value);
100 free(head);
101 head = next;
102 }
103}
104
105/*
106 * Get the value of an attribute in an attribute list. Returns NULL
107 * if attribute not found.
108 */
109char*
110getAttribute(const jarAttribute* attributes, const char* name) {
111 while (attributes != NULL) {
112 if (strcasecmp(attributes->name, name) == 0) {
113 return attributes->value;
114 }
115 attributes = (jarAttribute*)attributes->next;
116 }
117 return NULL;
118}
Note: See TracBrowser for help on using the repository browser.