view directory.h @ 169:29531c2f8213

Update nsock
author David Demelier <markand@malikania.fr>
date Mon, 26 Aug 2013 22:23:06 +0200
parents d08c18d8a6ef
children
line wrap: on
line source

/*
 * 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_ */