/*
* Copyright ©2026 Soham Pardeshi. All rights reserved.
* Permission is hereby granted to students registered for University of
* Washington CSE 333 for use solely during Summer Quarter 2026 for
* purposes of the course. No other use, copying, distribution, or
* modification is permitted without prior written consent. Copyrights
* for third-party components of this work must be honored. Instructors
* interested in reusing these course materials should contact the author.
*/
#ifndef DIRUTIL_H_
#define DIRUTIL_H_
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// An iterator over the entries of a directory provided by the POSIX API.
// The entries "." and ".." are skipped.
typedef struct dir_iter DirIter;
// Allocates a new iterator over the entries of the directory 'dirname',
// positioned at the first entry (if any). Returns NULL on error.
DirIter* DirIter_Allocate(const char* dirname);
// Frees all resources associated with the iterator.
void DirIter_Free(DirIter* iter);
// Returns true if the iterator is pointing at an entry, or false if the
// end of the directory has been reached.
bool DirIter_IsValid(DirIter* iter);
// Advances the iterator to the next entry. Returns true if the iterator
// is pointing at an entry afterwards, or false if the end of the
// directory has been reached.
// REQUIRES: DirIter_IsValid(iter)
bool DirIter_Next(DirIter* iter);
// Returns the name of the entry the iterator is pointing at (just the
// name, not the full path). The returned string is only valid until the
// next call to DirIter_Next() or DirIter_Free(); do not free it yourself.
// REQUIRES: DirIter_IsValid(iter)
const char* DirIter_Get(DirIter* iter);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // DIRUTIL_H_