dir.h 1.9 KB
/*
 * dir.h: as one might suggest here are definitions and prototypes for
 *        posix/dir.c
 *
 * Copyright (C) 2006 Georg Steffers
 *
 * Author:    Georg Steffers [GST] <georg.steffers@aschendorff.de>
 * Developer:
 *
 * Changes (for this file only):
 *   (2006-06-12) [GST] Started this changelog...well the program is
 *                      ready since some weeks right now.
 */
#ifndef DIR_H
#define DIR_H

#include <sys/stat.h>
#include <dirent.h>

#include <scot/dir_common.h>
#include <scot/event_listener.h>

struct scot_dir
{
	struct scot_event_listener el;

	DIR *                      handle;
	const char *               path;

	int                        notify_handle;
};

/* abstraction for file information and an directory handle */
#define FILE_DATA       struct dirent_stat
#define DIR_HANDLE      DIR *
/* #define DIR_HANDLE      struct scot_dir * */

/* abstraction for checking if a file is a directory */
#define IS_DIRECTORY(file_data) (S_ISDIR ((file_data).stat.st_mode))

/* abstraction for getting the filename of a directory entry. */
#define DIRENT_FNAME(file_data) ((file_data).file->d_name)

/* !!!FIXME!!! is there any place where this is already defined in posix? */
#ifndef MAX_PATH
#  define MAX_PATH   2000
#endif /* MAX_PATH */

/* structure for all available information about the directory entry. */
struct dirent_stat
{
	char                       path [MAX_PATH+1];
	struct dirent *            file;
	struct stat                stat;
};


/* the last parameter is posix specific. It defines if stat should
 * follow symlinks or not. Under Windows it is ignored. */
DIR_HANDLE get_dir_first (const char *, FILE_DATA *, int);
int        get_dir_next  (DIR_HANDLE, const char *, FILE_DATA *, int);

/*
DIR_HANDLE scot_dir_new  (const char *);
void       scot_dir_free (DIR_HANDLE);

int get_dir_first (DIR_HANDLE, FILE_DATA *, int);
int get_dir_next  (DIR_HANDLE, FILE_DATA *, int);
*/

#endif /* DIR_H */