"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / gsf / gsf-zip-utils.c
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * gsf-zip-utils.c: tools for zip archive output.
4  *
5  * Copyright (C) 2002-2006 Jon K Hellan (hellan@acm.org)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2.1 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Outc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21
22 #include <gsf-config.h>
23 #include <gsf/gsf.h>
24 #include <sys/types.h>
25 #include <string.h>
26 #include "gsf-zip-impl.h"
27
28 /**
29  * SECTION:zip
30  * @Short_description: Utilities for reading and writing ZIP/JAR files
31  * @Title: Zip files
32  *
33  * #GsfInfile and #GsfOutfile support for zip files.
34  **/
35
36 /* Doesn't do much, but include for symmetry */
37 GsfZipDirent*
38 gsf_zip_dirent_new (void)
39 {
40         return g_new0 (GsfZipDirent, 1);
41 }
42
43 void
44 gsf_zip_dirent_free (GsfZipDirent *dirent)
45 {
46         g_return_if_fail (dirent != NULL);
47
48         g_free (dirent->name);
49         dirent->name = NULL;
50
51         g_free (dirent);
52 }
53
54 GsfZipVDir *
55 gsf_vdir_new (char const *name, gboolean is_directory, GsfZipDirent *dirent)
56 {
57         GsfZipVDir *vdir = g_new (GsfZipVDir, 1);
58
59         vdir->name = g_strdup (name);
60         vdir->is_directory = is_directory;
61         vdir->dirent = dirent;
62         vdir->children = NULL;
63         return vdir;
64 }
65
66 void
67 gsf_vdir_free (GsfZipVDir *vdir, gboolean free_dirent)
68 {
69         GSList *l;
70
71         if (!vdir)
72                 return;
73
74         for (l = vdir->children; l; l = l->next)
75                 gsf_vdir_free ((GsfZipVDir *)l->data, free_dirent);
76
77         g_slist_free (vdir->children);
78         g_free (vdir->name);
79         if (free_dirent && vdir->dirent)
80                 gsf_zip_dirent_free (vdir->dirent);
81         g_free (vdir);
82 }
83
84 void
85 gsf_vdir_add_child (GsfZipVDir *vdir, GsfZipVDir *child)
86 {
87         GSList *tail = g_slist_append (NULL, child);
88         if (vdir->children)
89                 vdir->last_child->next = tail;
90         else
91                 vdir->children = tail;
92         vdir->last_child = tail;
93 }