dir.c revision 0874abad14e3e9ecfc3dc1a1a2b9969f2f027724
/*
* Copyright (C) 2004, 2007-2009 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.19 2011/03/11 06:11:27 marka Exp $ */
/* Principal Authors: DCL */
#include <config.h>
#include <string.h>
#include <direct.h>
#include <process.h>
#include <io.h>
#include <isc/assertions.h>
#include "errno2result.h"
static isc_result_t
start_directory(isc_dir_t *p);
void
}
/*
* 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 (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.
*/
if (dir->entry_filled)
/*
* start_directory() already filled in the first entry.
*/
else {
/*
* Fetch next file in directory.
*/
/*
* Either the last file has been processed or
* an error has occurred. The former is not
* really an error, but the latter is.
*/
if (GetLastError() == ERROR_NO_MORE_FILES)
return (ISC_R_NOMORE);
else
return (ISC_R_UNEXPECTED);
}
/*
* Make sure that the space for the name is long enough.
*/
return (ISC_R_SUCCESS);
}
/*
* Close directory stream.
*/
void
}
/*
* Reposition directory stream at start.
*/
/*
* NT cannot reposition the seek pointer to the beginning of the
* the directory stream, but rather the directory needs to be
* closed and reopened. The latter might fail.
*/
return (result);
}
/*
* Initialize isc_dir_t structure with new directory. The function
* returns 0 on failure and nonzero on success.
*
* Note:
* - Be sure to close previous stream before opening new one
*/
static isc_result_t
{
/*
* Open stream and retrieve first file.
*/
/*
* Something went wrong but we don't know what. GetLastError()
* could give us more information about the error, but the
* MSDN documentation is frustratingly thin about what
* possible errors could have resulted. (Score one for
* the Unix manual pages.) So there is just this lame error
* instead of being able to differentiate ISC_R_NOTFOUND
* from ISC_R_UNEXPECTED.
*/
return (ISC_R_FAILURE);
}
/*
* Make sure that the space for the name is long enough.
*/
/*
* Fill in the data for the first entry of the directory.
*/
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_chroot(const char *dirname) {
return (ISC_R_NOTIMPLEMENTED);
}
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 & 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);
}