Mercurial > code
diff directory.h @ 150:d08c18d8a6ef
Welcom directory.[ch]
author | markand <devnull@localhost> |
---|---|
date | Wed, 23 May 2012 21:29:16 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/directory.h Wed May 23 21:29:16 2012 +0200 @@ -0,0 +1,61 @@ +/* + * directory.h -- portable way to open directories + * + * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _DIRECTORY_H_ +#define _DIRECTORY_H_ + +struct directory { + int nents; /* number of entries */ + + struct { + char *name; /* entry name */ + int length; /* length of entry */ + int type; /* type of entry */ + } *ents; +}; + +#if defined(_WIN32) + +# include <windows.h> + +enum { + DIRECTORY_DIR = FILE_ATTRIBUTE_DIRECTORY, + DIRECTORY_FILE = FILE_ATTRIBUTE_NORMAL +}; + +#else + +# include <dirent.h> + +enum { + DIRECTORY_DIR = DT_DIR, + DIRECTORY_FILE = DT_REG +}; + +#endif + +struct directory * +directory_open(const char *); + +const char * +directory_error(void); + +void +directory_free(struct directory *); + +#endif /* _DIRECTORY_H_ */