dir.c revision a09e49f3f45386d7e12fce56724f1336a97207d6
/*
* Copyright (C) 1999-2001, 2004, 2005, 2007-2009, 2011, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \file
* \author Principal Authors: DCL */
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include "errno2result.h"
void
}
/*!
* \brief Allocate workspace and open directory stream. If either one fails,
* NULL will be returned.
*/
char *p;
/*
* Copy directory name. Need to have enough space for the name,
* a possible path separator, the wildcard, and the final NUL.
*/
/* XXXDCL ? */
return (ISC_R_NOSPACE);
/*
* Append path separator, if needed, and "*".
*/
*p++ = '/';
*p++ = '*';
*p = '\0';
/*
* Open stream.
*/
return isc__errno2result(errno);
return (result);
}
/*!
* \brief Return previously retrieved file or get next one.
* Unix's dirent has
* separate open and read functions, but the Win32 and DOS interfaces open
* the dir stream and reads the first file in one operation.
*/
/*
* Fetch next file in directory.
*/
return (ISC_R_NOMORE);
/*
* Make sure that the space for the name is long enough.
*/
return (ISC_R_UNEXPECTED);
/*
* Some dirents have d_namlen, but it is not portable.
*/
return (ISC_R_SUCCESS);
}
/*!
* \brief Close directory stream.
*/
void
}
/*!
* \brief Reposition directory stream at start.
*/
return (ISC_R_SUCCESS);
}
isc_dir_chdir(const char *dirname) {
/*!
* \brief Change the current directory to 'dirname'.
*/
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
}
isc_dir_chroot(const char *dirname) {
#ifdef HAVE_CHROOT
void *tmp;
#endif
#ifdef HAVE_CHROOT
/*
* Try to use getservbyname and getprotobyname before chroot.
* If WKS records are used in a zone under chroot, Name Service Switch
* may fail to load library in chroot.
* Do not report errors if it fails, we do not need any result now.
*/
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
#else
return (ISC_R_NOTIMPLEMENTED);
#endif
}
isc_dir_createunique(char *templet) {
char *x;
char *p;
int i;
int pid;
/*!
* \brief mkdtemp is not portable, so this emulates it.
*/
/*
* Replace trailing Xs with the process-id, zero-filled.
*/
x--, pid /= 10)
x++; /* Set x to start of ex-Xs. */
do {
break;
/*
* The BSD algorithm.
*/
p = x;
while (*p != '\0') {
if (isdigit(*p & 0xff))
*p = 'a';
else if (*p != 'z')
++*p;
else {
/*
* Reset character and move to next.
*/
*p++ = 'a';
continue;
}
break;
}
if (*p == '\0') {
/*
* Tried all combinations. errno should already
* be EEXIST, but ensure it is anyway for
* isc__errno2result().
*/
break;
}
} while (1);
if (i == -1)
else
return (result);
}