dir.c revision 7cd594b8427fe742d44295790ba367e1de22a47d
/*
* Copyright (C) 1999-2001, 2004, 2007-2009, 2011-2013, 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$ */
/* 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 {
if (i == 0)
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);
}