/strigi-0.7.7/libstreamanalyzer/lib/stgdirent.h
C Header | 111 lines | 47 code | 20 blank | 44 comment | 6 complexity | 4a69c96588b6595a3827d4724d4bae1a MD5 | raw file
Possible License(s): LGPL-2.0
1/*------------------------------------------------------------------------------
2* Copyright (C) 2003-2006 Matt J. Weinstein <weinstein@macalester.edu>
3*
4* Distributable under the terms of either the Apache License (Version 2.0) or
5* the GNU Lesser General Public License, as specified in the COPYING file.
6------------------------------------------------------------------------------*/
7#ifndef STGDIRENT_H
8#define STGDIRENT_H
9
10#ifdef HAVE_CONFIG_H
11# include "config.h"
12#endif
13
14#if !defined(HAVE_DIRENT_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H)
15
16#include <strigi/strigiconfig.h>
17#include <windows.h>
18#include <io.h>
19
20/**
21 * dirent.c
22 *
23 * Derived from DIRLIB.C by Matt J. Weinstein
24 * This note appears in the DIRLIB.H
25 * DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89
26 *
27 * Updated by Jeremy Bettis <jeremy@hksys.com>
28 * Significantly revised and rewinddir, seekdir and telldir added by Colin
29 * Cut down again & changed by Ben van Klinken
30 * Peters <colin@fu.is.saga-u.ac.jp>
31 *
32 */
33
34/** dirent structure - used by the dirent.h directory iteration functions */
35struct dirent
36{
37 unsigned short d_namlen; /* Length of name in d_name. */
38 char *d_name; /* File name. */
39};
40
41/** DIR structure - used by the dirent.h directory iteration functions*/
42struct DIR
43{
44 /** disk transfer area for this dir */
45 struct _finddata_t dd_dta;
46
47 /* dirent struct to return from dir (NOTE: this makes this thread
48 * safe as long as only one thread uses a particular DIR struct at
49 * a time) */
50 struct dirent dd_dir;
51
52 /** _findnext handle */
53 intptr_t dd_handle;
54
55 /**
56 * Status of search:
57 * 0 = not started yet (next entry to read is first entry)
58 * -1 = off the end
59 * positive = 0 based index of next entry
60 */
61 int32_t dd_stat;
62
63 /** given path for dir with search pattern (struct is extended) */
64 char dd_name[MAX_PATH];
65
66};
67
68#define DIRENT_SEARCH_SUFFIX "*"
69#define DIRENT_SLASH PATH_DELIMITERA
70
71
72/**
73* Returns a pointer to a DIR structure appropriately filled in to begin
74* searching a directory.
75*/
76DIR* strigi_opendir (const char* filespec);
77#define opendir strigi_opendir
78
79/**
80* Return a pointer to a dirent structure filled with the information on the
81* next entry in the directory.
82*/
83struct dirent* strigi_readdir (DIR* dir);
84#define readdir strigi_readdir
85
86/**
87* Frees up resources allocated by opendir.
88*/
89int32_t strigi_closedir (DIR* dir);
90#define closedir strigi_closedir
91
92
93#elif defined (HAVE_DIRENT_H)
94# include <dirent.h>
95# define NAMLEN(dirent) strlen((dirent)->d_name)
96
97#else
98# define dirent direct
99# define NAMLEN(dirent) (dirent)->d_namlen
100# if defined(HAVE_SYS_NDIR_H)
101# include <sys/ndir.h>
102# endif
103# if defined(HHAVE_SYS_DIR_H)
104# include <sys/dir.h>
105# endif
106# if defined(HHAVE_NDIR_H)
107# include <ndir.h>
108# endif
109
110#endif //HAVE_DIRENT_H
111#endif