dir.c revision febf5f8b55abb2e6e840488a29a5ef4e20654f67
/*
* Copyright (C) 1999, 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, 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.
*/
/* $Id: dir.c,v 1.11 2000/07/27 02:04:34 tale Exp $ */
/* Principal Authors: DCL */
#include <config.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include "errno2result.h"
void
}
/*
* Allocate workspace and open directory stream. If either one fails,
* NULL will be returned.
*/
/*
* Open stream.
*/
return isc__errno2result(errno);
return (result);
}
/*
* 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);
}
/*
* Close directory stream.
*/
void
}
/*
* Reposition directory stream at start.
*/
return (ISC_R_SUCCESS);
}
isc_dir_chdir(const char *dirname) {
/*
* Change the current directory to 'dirname'.
*/
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
}
isc_dir_createunique(char *templet) {
char *x;
char *p;
int i;
int pid;
/*
* 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))
*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);
}