~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/os/os_dir.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1997-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "db_config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char revid[] = "$Id$";
12
 
#endif /* not lint */
13
 
 
14
 
#ifndef NO_SYSTEM_INCLUDES
15
 
#include <sys/types.h>
16
 
 
17
 
#if HAVE_DIRENT_H
18
 
# include <dirent.h>
19
 
# define NAMLEN(dirent) strlen((dirent)->d_name)
20
 
#else
21
 
# define dirent direct
22
 
# define NAMLEN(dirent) (dirent)->d_namlen
23
 
# if HAVE_SYS_NDIR_H
24
 
#  include <sys/ndir.h>
25
 
# endif
26
 
# if HAVE_SYS_DIR_H
27
 
#  include <sys/dir.h>
28
 
# endif
29
 
# if HAVE_NDIR_H
30
 
#  include <ndir.h>
31
 
# endif
32
 
#endif
33
 
 
34
 
#endif
35
 
 
36
 
#include "db_int.h"
37
 
 
38
 
/*
39
 
 * __os_dirlist --
40
 
 *      Return a list of the files in a directory.
41
 
 *
42
 
 * PUBLIC: int __os_dirlist __P((DB_ENV *, const char *, char ***, int *));
43
 
 */
44
 
int
45
 
__os_dirlist(dbenv, dir, namesp, cntp)
46
 
        DB_ENV *dbenv;
47
 
        const char *dir;
48
 
        char ***namesp;
49
 
        int *cntp;
50
 
{
51
 
        struct dirent *dp;
52
 
        DIR *dirp;
53
 
        int arraysz, cnt, ret;
54
 
        char **names;
55
 
 
56
 
        if (DB_GLOBAL(j_dirlist) != NULL)
57
 
                return (DB_GLOBAL(j_dirlist)(dir, namesp, cntp));
58
 
 
59
 
#ifdef HAVE_VXWORKS
60
 
        if ((dirp = opendir((char *)dir)) == NULL)
61
 
#else
62
 
        if ((dirp = opendir(dir)) == NULL)
63
 
#endif
64
 
                return (__os_get_errno());
65
 
        names = NULL;
66
 
        for (arraysz = cnt = 0; (dp = readdir(dirp)) != NULL; ++cnt) {
67
 
                if (cnt >= arraysz) {
68
 
                        arraysz += 100;
69
 
                        if ((ret = __os_realloc(dbenv,
70
 
                            arraysz * sizeof(names[0]), &names)) != 0)
71
 
                                goto nomem;
72
 
                }
73
 
                if ((ret = __os_strdup(dbenv, dp->d_name, &names[cnt])) != 0)
74
 
                        goto nomem;
75
 
        }
76
 
        (void)closedir(dirp);
77
 
 
78
 
        *namesp = names;
79
 
        *cntp = cnt;
80
 
        return (0);
81
 
 
82
 
nomem:  if (names != NULL)
83
 
                __os_dirfree(dbenv, names, cnt);
84
 
        if (dirp != NULL)
85
 
                (void)closedir(dirp);
86
 
        return (ret);
87
 
}
88
 
 
89
 
/*
90
 
 * __os_dirfree --
91
 
 *      Free the list of files.
92
 
 *
93
 
 * PUBLIC: void __os_dirfree __P((DB_ENV *, char **, int));
94
 
 */
95
 
void
96
 
__os_dirfree(dbenv, names, cnt)
97
 
        DB_ENV *dbenv;
98
 
        char **names;
99
 
        int cnt;
100
 
{
101
 
        if (DB_GLOBAL(j_dirfree) != NULL)
102
 
                DB_GLOBAL(j_dirfree)(names, cnt);
103
 
        else {
104
 
                while (cnt > 0)
105
 
                        __os_free(dbenv, names[--cnt]);
106
 
                __os_free(dbenv, names);
107
 
        }
108
 
}