~ubuntu-branches/ubuntu/oneiric/jabberd2/oneiric-security

« back to all changes in this revision

Viewing changes to subst/dirent.c

  • Committer: Bazaar Package Importer
  • Author(s): Nicolai Spohrer
  • Date: 2008-08-12 16:13:43 UTC
  • mfrom: (1.1.3 upstream) (0.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20080812161343-6trz3r97dtevxd17
Tags: 2.2.1-1ubuntu1
* Merge with Debian unstable (LP: #257130), remaining changes:
  - debian/control:
    + Modify Maintainer field as per spec
    + Depend on libdb4.6-dev instead of libdb4.4-dev
    + Added Conflicts and Replaces: ..., jabber for jabberd2
  - debian/rules: Added libtoolize call (jabberd2 ships with
     an older ltmain.sh version that conflicts with the
     current libtool version)
  - debian/init: create /var/run/jabber directory with correct
     permissions
* Dropped changes:
  - Debian already depends on libpq-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
    Implementation of POSIX directory browsing functions and types for Win32.
4
 
 
5
 
    Author:  Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com)
6
 
    History: Created March 1997. Updated June 2003.
7
 
    Rights:  See end of file.
8
 
 
9
 
*/
10
 
 
11
 
#ifdef HAVE_CONFIG_H
12
 
# include "config.h"
13
 
#endif
14
 
 
15
 
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_SYS_NDIR_H)
16
 
#ifdef HAVE__FINDFIRST
17
 
 
18
 
#include "dirent.h"
19
 
 
20
 
#include <errno.h>
21
 
#include <io.h> /* _findfirst and _findnext set errno iff they return -1 */
22
 
#include <stdlib.h>
23
 
#include <string.h>
24
 
 
25
 
#ifdef __cplusplus
26
 
extern "C"
27
 
{
28
 
#endif
29
 
 
30
 
struct DIR
31
 
{
32
 
    long                handle; /* -1 for failed rewind */
33
 
    struct _finddata_t  info;
34
 
    struct dirent       result; /* d_name null iff first time */
35
 
    char                *name;  /* null-terminated char string */
36
 
};
37
 
 
38
 
DIR *opendir(const char *name)
39
 
{
40
 
    DIR *dir = 0;
41
 
 
42
 
    if(name && name[0])
43
 
    {
44
 
        size_t base_length = strlen(name);
45
 
        const char *all = /* search pattern must end with suitable wildcard */
46
 
            strchr("/\\", name[base_length - 1]) ? "*" : "/*";
47
 
 
48
 
        if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
49
 
           (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
50
 
        {
51
 
            strcat(strcpy(dir->name, name), all);
52
 
 
53
 
            if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1)
54
 
            {
55
 
                dir->result.d_name = 0;
56
 
            }
57
 
            else /* rollback */
58
 
            {
59
 
                free(dir->name);
60
 
                free(dir);
61
 
                dir = 0;
62
 
            }
63
 
        }
64
 
        else /* rollback */
65
 
        {
66
 
            free(dir);
67
 
            dir   = 0;
68
 
            errno = ENOMEM;
69
 
        }
70
 
    }
71
 
    else
72
 
    {
73
 
        errno = EINVAL;
74
 
    }
75
 
 
76
 
    return dir;
77
 
}
78
 
 
79
 
int closedir(DIR *dir)
80
 
{
81
 
    int result = -1;
82
 
 
83
 
    if(dir)
84
 
    {
85
 
        if(dir->handle != -1)
86
 
        {
87
 
            result = _findclose(dir->handle);
88
 
        }
89
 
 
90
 
        free(dir->name);
91
 
        free(dir);
92
 
    }
93
 
 
94
 
    if(result == -1) /* map all errors to EBADF */
95
 
    {
96
 
        errno = EBADF;
97
 
    }
98
 
 
99
 
    return result;
100
 
}
101
 
 
102
 
struct dirent *readdir(DIR *dir)
103
 
{
104
 
    struct dirent *result = 0;
105
 
 
106
 
    if(dir && dir->handle != -1)
107
 
    {
108
 
        if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
109
 
        {
110
 
            result         = &dir->result;
111
 
            result->d_name = dir->info.name;
112
 
        }
113
 
    }
114
 
    else
115
 
    {
116
 
        errno = EBADF;
117
 
    }
118
 
 
119
 
    return result;
120
 
}
121
 
 
122
 
void rewinddir(DIR *dir)
123
 
{
124
 
    if(dir && dir->handle != -1)
125
 
    {
126
 
        _findclose(dir->handle);
127
 
        dir->handle = (long) _findfirst(dir->name, &dir->info);
128
 
        dir->result.d_name = 0;
129
 
    }
130
 
    else
131
 
    {
132
 
        errno = EBADF;
133
 
    }
134
 
}
135
 
 
136
 
#ifdef __cplusplus
137
 
}
138
 
#endif
139
 
 
140
 
#endif
141
 
#endif
142
 
 
143
 
/*
144
 
 
145
 
    Copyright Kevlin Henney, 1997, 2003. All rights reserved.
146
 
 
147
 
    Permission to use, copy, modify, and distribute this software and its
148
 
    documentation for any purpose is hereby granted without fee, provided
149
 
    that this copyright and permissions notice appear in all copies and
150
 
    derivatives.
151
 
    
152
 
    This software is supplied "as is" without express or implied warranty.
153
 
 
154
 
    But that said, if there are any problems please get in touch.
155
 
 
156
 
*/