file.c revision 5b1c7ef35bb495820360182b5192689f33f1cc7d
/*
* Copyright (C) 2004, 2005, 2007, 2009, 2011-2015 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2002 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.
*/
/*
* Portions Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <time.h> /* Required for utimes on some platforms. */
#include <unistd.h> /* Required for mkstemp on NetBSD. */
#ifdef HAVE_SYS_MMAN_H
#endif
#include "errno2result.h"
/*
* XXXDCL As the API for accessing file statistics undoubtedly gets expanded,
* it might be good to provide a mechanism that allows for the results
* of a previous stat() to be used again without having to do another stat,
* such as perl's mechanism of using "_" in place of a file name to indicate
* that the results of the last stat should be used. But then you get into
* annoying MP issues. BTW, Win32 has stat().
*/
static isc_result_t
return (result);
}
static isc_result_t
return (result);
}
if (result == ISC_R_SUCCESS)
return (result);
}
if (result == ISC_R_SUCCESS)
return (result);
}
if (result == ISC_R_SUCCESS)
/*
* XXXDCL some operating systems provide nanoseconds, too,
*/
return (result);
}
if (result == ISC_R_SUCCESS)
return (result);
}
/*
* tv_sec is at least a 32 bit quantity on all platforms we're
* dealing with, but it is signed on most (all?) of them,
* so we need to make sure the high bit isn't set. This unfortunately
* loses when either:
* * tv_sec becomes a signed 64 bit integer but long is 32 bits
* and isc_time_seconds > LONG_MAX, or
* * isc_time_seconds is changed to be > 32 bits but long is 32 bits
* and isc_time_seconds has at least 33 significant bits.
*/
/*
* Here is the real check for the high bit being set.
*/
return (ISC_R_RANGE);
/*
* isc_time_nanoseconds guarantees a value that divided by 1000 will
* fit into the minimum possible size tv_usec field. Unfortunately,
* we don't know what that type is so can't cast directly ... but
* we can at least cast to signed so the IRIX compiler shuts up.
*/
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
}
}
{
const char *s;
if (s != NULL)
templet = s + 1;
if (s != NULL) {
return (ISC_R_NOSPACE);
} else {
return (ISC_R_NOSPACE);
}
return (ISC_R_SUCCESS);
}
static const char alphnum[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
char *x;
char *cp;
while (*cp != '\0')
cp++;
return (ISC_R_FAILURE);
x = cp--;
x = cp--;
}
return (isc__errno2result(errno));
for (cp = x;;) {
const char *t;
if (*cp == '\0')
return (ISC_R_FAILURE);
if (t == NULL || *++t == '\0')
else {
*cp = *t;
break;
}
}
}
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
}
}
}
int fd;
FILE *f;
char *x;
char *cp;
while (*cp != '\0')
cp++;
return (ISC_R_FAILURE);
x = cp--;
x = cp--;
}
return (isc__errno2result(errno));
for (cp = x;;) {
char *t;
if (*cp == '\0')
return (ISC_R_FAILURE);
if (t == NULL || *++t == '\0')
else {
*cp = *t;
break;
}
}
}
if (f == NULL) {
"remove '%s': failed", templet);
}
} else
*fp = f;
return (result);
}
}
}
}
isc_file_remove(const char *filename) {
int r;
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
int r;
if (r == 0)
return (ISC_R_SUCCESS);
else
return (isc__errno2result(errno));
}
isc_file_exists(const char *pathname) {
}
isc_file_isplainfile(const char *filename) {
/*
* This function returns success if filename is a plain file.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isplainfilefd(int fd) {
/*
* This function returns success if filename is a plain file.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isdirectory(const char *filename) {
/*
* This function returns success if filename exists and is a
* directory.
*/
return(isc__errno2result(errno));
return(ISC_R_INVALIDFILE);
return(ISC_R_SUCCESS);
}
isc_file_isabsolute(const char *filename) {
}
isc_file_iscurrentdir(const char *filename) {
}
isc_file_ischdiridempotent(const char *filename) {
if (isc_file_isabsolute(filename))
return (ISC_TRUE);
return (ISC_TRUE);
return (ISC_FALSE);
}
const char *
isc_file_basename(const char *filename) {
const char *s;
if (s == NULL)
return (filename);
return (s + 1);
}
const char *base;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
/*
* Put the absolute name of the current directory into 'dirname', which is
* a buffer of at least 'length' characters. End the string with the
* appropriate path separator, such that the final product could be
* concatenated with a relative pathname to make a valid pathname string.
*/
static isc_result_t
char *cwd;
else
} else {
}
return (result);
}
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
return (result);
}
int flags;
FILE *f;
int fd;
if (result == ISC_R_SUCCESS) {
return (ISC_R_INVALIDFILE);
} else if (result == ISC_R_FILENOTFOUND) {
} else
return (result);
if (fd == -1)
return (isc__errno2result(errno));
if (f == NULL) {
return (result);
}
*fp = f;
return (ISC_R_SUCCESS);
}
char const **basename)
{
char *dir;
return (ISC_R_INVALIDFILE);
} else {
}
return (ISC_R_NOMEMORY);
if (*file == '\0') {
return (ISC_R_INVALIDFILE);
}
return (ISC_R_SUCCESS);
}
void *
{
#ifdef HAVE_MMAP
#else
void *buf;
return (NULL);
}
return (buf);
#endif
}
int
#ifdef HAVE_MMAP
#else
return (0);
#endif
}
#define DISALLOW "\\/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
{
size_t l = 0;
/*
* allow room for a full sha256 hash (64 chars
* plus null terminator)
*/
if (l < 65U)
l = 65;
return (ISC_R_NOSPACE);
/* Check whether the full-length SHA256 hash filename exists */
if (isc_file_exists(buf)) {
return (ISC_R_SUCCESS);
}
/* Check for a truncated SHA256 hash filename */
if (isc_file_exists(buf)) {
return (ISC_R_SUCCESS);
}
/*
* If neither hash filename already exists, then we'll use
* the original base name if it has no disallowed characters,
* or the truncated hash name if it does.
*/
return (ISC_R_SUCCESS);
}
return (ISC_R_SUCCESS);
}