/*
* Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* to whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
* OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
* 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.
*
* Except as contained in this notice, the name of a copyright holder
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* of the copyright holder.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* If file-system access is to be excluded, this module has no function,
* so all of its code should be excluded.
*/
#ifndef WITHOUT_FILE_SYSTEM
/*
* Standard includes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/*
* Operating system includes.
*/
#include <unistd.h>
#include <dirent.h>
#include "direader.h"
#include "errmsg.h"
/*
* Use the reentrant POSIX threads version of readdir()?
*/
#endif
/*
* Objects of the following type are used to maintain the resources
* needed to read directories.
*/
struct DirReader {
#ifdef USE_READDIR_R
/* readdir() */
#endif
};
static int _dr_path_is_dir(const char *pathname);
/*.......................................................................
* Create a new DirReader object.
*
* Output:
* return DirReader * The new object, or NULL on error.
*/
{
/*
* Allocate the container.
*/
if(!dr) {
return NULL;
};
/*
* Before attempting any operation that might fail, initialize the
* container at least up to the point at which it can safely be passed
* to _del_DirReader().
*/
#ifdef USE_READDIR_R
dr->buffer_dim = 0;
#endif
/*
* Allocate a place to record error messages.
*/
return _del_DirReader(dr);
return dr;
}
/*.......................................................................
* Delete a DirReader object.
*
* Input:
* dr DirReader * The object to be deleted.
* Output:
* return DirReader * The deleted object (always NULL).
*/
{
if(dr) {
#ifdef USE_READDIR_R
#endif
};
return NULL;
}
/*.......................................................................
* Open a new directory.
*
* Input:
* dr DirReader * The directory reader resource object.
* path const char * The directory to be opened.
* errmsg char ** If an error occurs and errmsg isn't NULL, a
* pointer to an error description will be assigned
* to *errmsg.
* Output:
* return int 0 - OK.
* 1 - Error (see *errmsg for a description).
*/
{
/*
* If a directory is already open, close it first.
*/
(void) _dr_close_dir(dr);
/*
* Is the path a directory?
*/
if(!_dr_path_is_dir(path)) {
if(errmsg) {
};
return 1;
};
/*
* Attempt to open the directory.
*/
if(!dir) {
if(errmsg) {
};
return 1;
};
/*
* If using POSIX threads, allocate a buffer for readdir_r().
*/
#ifdef USE_READDIR_R
{
#ifdef NAME_MAX
if(name_max < 0)
#endif
if(name_max < 0) {
if(errmsg) {
};
return 1;
};
/*
* How big a buffer do we need to allocate?
*/
/*
* Extend the buffer?
*/
if(!buffer) {
if(errmsg) {
};
return 1;
};
};
};
#endif
/*
* Record the successfully opened directory.
*/
return 0;
}
/*.......................................................................
* If the DirReader object is currently contains an open directory,
* close it.
*
* Input:
* dr DirReader * The directory reader resource object.
*/
{
};
}
/*.......................................................................
* Read the next file from the directory opened with _dr_open_dir().
*
* Input:
* dr DirReader * The directory reader resource object.
* Output:
* return char * The name of the new file, or NULL if we reached
* the end of the directory.
*/
{
/*
* Are we currently reading a directory?
*/
/*
* Read the next directory entry.
*/
#ifdef USE_READDIR_R
#else
#endif
};
/*
* When the end of a directory is reached, close it.
*/
return NULL;
}
/*.......................................................................
* Return 1 if the specified pathname refers to a directory.
*
* Input:
* pathname const char * The path to test.
* Output:
* return int 0 - Not a directory.
* 1 - pathname[] refers to a directory.
*/
{
/*
* Look up the file attributes.
*/
return 0;
/*
* Is the file a directory?
*/
}
#endif /* ifndef WITHOUT_FILE_SYSTEM */