dir.c revision 04260c5c48d234734863f0222e207b6564cd41a8
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Copyright (C) 1999-2001 Internet Software Consortium.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * copyright notice and this permission notice appear in all copies.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson/* $Id: dir.c,v 1.18 2001/06/08 23:50:31 tale Exp $ */
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson/* Principal Authors: DCL */
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson#define ISC_DIR_MAGIC ISC_MAGIC('D', 'I', 'R', '*')
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson#define VALID_DIR(dir) ISC_MAGIC_VALID(dir, ISC_DIR_MAGIC)
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Allocate workspace and open directory stream. If either one fails,
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * NULL will be returned.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafssonisc_dir_open(isc_dir_t *dir, const char *dirname) {
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Open stream.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Return previously retrieved file or get next one. Unix's dirent has
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * separate open and read functions, but the Win32 and DOS interfaces open
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * the dir stream and reads the first file in one operation.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson REQUIRE(VALID_DIR(dir) && dir->handle != NULL);
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Fetch next file in directory.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Make sure that the space for the name is long enough.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson if (sizeof(dir->entry.name) <= strlen(entry->d_name))
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson * Some dirents have d_namlen, but it is not portable.
e7a4f58d55042cbc981a70b5071aaea46b9ebf7fAndreas Gustafsson dir->entry.length = strlen(entry->d_name);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
char *cwd;
} else if (end_sep) {
return (result);
int pid;
return (result);