1258945Sroberto/* 2258945Sroberto * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC") 3258945Sroberto * Copyright (C) 1999-2001 Internet Software Consortium. 4258945Sroberto * 5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any 6258945Sroberto * purpose with or without fee is hereby granted, provided that the above 7258945Sroberto * copyright notice and this permission notice appear in all copies. 8258945Sroberto * 9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11258945Sroberto * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15258945Sroberto * PERFORMANCE OF THIS SOFTWARE. 16258945Sroberto */ 17258945Sroberto 18258945Sroberto/* $Id: dir.h,v 1.21 2007/06/19 23:47:19 tbox Exp $ */ 19258945Sroberto 20258945Sroberto/* Principal Authors: DCL */ 21258945Sroberto 22258945Sroberto#ifndef ISC_DIR_H 23258945Sroberto#define ISC_DIR_H 1 24258945Sroberto 25258945Sroberto/*! \file */ 26258945Sroberto 27258945Sroberto#include <sys/types.h> /* Required on some systems. */ 28258945Sroberto#include <dirent.h> 29258945Sroberto 30258945Sroberto#include <isc/lang.h> 31258945Sroberto#include <isc/result.h> 32258945Sroberto 33258945Sroberto#define ISC_DIR_NAMEMAX 256 34258945Sroberto#define ISC_DIR_PATHMAX 1024 35258945Sroberto 36258945Sroberto/*% Directory Entry */ 37258945Srobertotypedef struct isc_direntry { 38258945Sroberto /*! 39258945Sroberto * Ideally, this should be NAME_MAX, but AIX does not define it by 40258945Sroberto * default and dynamically allocating the space based on pathconf() 41258945Sroberto * complicates things undesirably, as does adding special conditionals 42258945Sroberto * just for AIX. So a comfortably sized buffer is chosen instead. 43258945Sroberto */ 44258945Sroberto char name[ISC_DIR_NAMEMAX]; 45258945Sroberto unsigned int length; 46258945Sroberto} isc_direntry_t; 47258945Sroberto 48258945Sroberto/*% Directory */ 49258945Srobertotypedef struct isc_dir { 50258945Sroberto unsigned int magic; 51258945Sroberto /*! 52258945Sroberto * As with isc_direntry_t->name, making this "right" for all systems 53258945Sroberto * is slightly problematic because AIX does not define PATH_MAX. 54258945Sroberto */ 55258945Sroberto char dirname[ISC_DIR_PATHMAX]; 56258945Sroberto isc_direntry_t entry; 57258945Sroberto DIR * handle; 58258945Sroberto} isc_dir_t; 59258945Sroberto 60258945SrobertoISC_LANG_BEGINDECLS 61258945Sroberto 62258945Srobertovoid 63258945Srobertoisc_dir_init(isc_dir_t *dir); 64258945Sroberto 65258945Srobertoisc_result_t 66258945Srobertoisc_dir_open(isc_dir_t *dir, const char *dirname); 67258945Sroberto 68258945Srobertoisc_result_t 69258945Srobertoisc_dir_read(isc_dir_t *dir); 70258945Sroberto 71258945Srobertoisc_result_t 72258945Srobertoisc_dir_reset(isc_dir_t *dir); 73258945Sroberto 74258945Srobertovoid 75258945Srobertoisc_dir_close(isc_dir_t *dir); 76258945Sroberto 77258945Srobertoisc_result_t 78258945Srobertoisc_dir_chdir(const char *dirname); 79258945Sroberto 80258945Srobertoisc_result_t 81258945Srobertoisc_dir_chroot(const char *dirname); 82258945Sroberto 83258945Srobertoisc_result_t 84258945Srobertoisc_dir_createunique(char *templet); 85258945Sroberto/*!< 86258945Sroberto * Use a templet (such as from isc_file_mktemplate()) to create a uniquely 87258945Sroberto * named, empty directory. The templet string is modified in place. 88258945Sroberto * If result == ISC_R_SUCCESS, it is the name of the directory that was 89258945Sroberto * created. 90258945Sroberto */ 91258945Sroberto 92258945SrobertoISC_LANG_ENDDECLS 93258945Sroberto 94258945Sroberto#endif /* ISC_DIR_H */ 95