file.c revision 68c2ccc953059f389cefc0f8a5ce0f83be7458c9
/*
* Copyright (C) 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: file.c,v 1.9 2001/07/08 05:09:00 mayer Exp $ */
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <io.h>
#include <process.h>
#include <fcntl.h>
#include "errno2result.h"
/*
* Emulate UNIX mkstemp, which returns an open FD to the new file
*
*/
static int
int pid;
trv++;
/* extra X's get set to 0's */
while (*--trv == 'X') {
pid /= 10;
}
/*
* check the target directory; if you have six X's and it
* doesn't exist this runs for a *very* long time.
*/
break;
if (*trv == '\\') {
*trv = '\0';
return (0);
return (0);
}
*trv = '\\';
break;
}
}
for (;;) {
if (doopen) {
if ((*doopen =
<<<<<<< file.c
return (1);
=======
return(1);
>>>>>>> 1.8
return (0);
}
/* tricky little algorithm for backward compatibility */
if (!*trv)
return (0);
if (*trv == 'z')
*trv++ = 'a';
else {
*trv = 'a';
else
++*trv;
break;
}
}
}
/*NOTREACHED*/
}
int
int fd;
}
/*
* 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);
}
/*
* isc_file_safemovefile is needed to ensure that
* any file with the new name is renamed to a backup name and then the
* rename is done. If all goes well then the backup can be deleted,
* otherwise it gets renamed back.
*/
int
char buf[512];
int tmpfd;
/*
* Make sure we have something to do
*/
return (-1);
}
/*
* Rename to a backup the new file if it still exists
*/
<<<<<<< file.c
=======
>>>>>>> 1.8
<<<<<<< file.c
if (tmpfd > 0)
=======
if (tmpfd > 0)
>>>>>>> 1.8
<<<<<<< file.c
=======
if (filestatus == 0) {
>>>>>>> 1.8
}
<<<<<<< file.c
/* Now rename the file to the new name
=======
/*
* Now rename the file to the new name
>>>>>>> 1.8
*/
<<<<<<< file.c
if (filestatus == 0) {
/* Try and rename the backup back to the original name if the backup got created
=======
if (filestatus == 0) {
/*
* Try to rename the backup back to the original name
* if the backup got created
>>>>>>> 1.8
*/
if (filestatus == 0) {
}
}
return (-1);
}
/*
* Delete the backup file if it got created
*/
}
return (0);
}
if (result == ISC_R_SUCCESS)
/*
* XXXDCL some operating systems provide nanoseconds, too,
*/
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);
return (isc__errno2result(errno));
return (ISC_R_SUCCESS);
}
}
char *s;
if (s != NULL)
templet = s + 1;
if (s != NULL) {
return (ISC_R_NOSPACE);
} else {
return (ISC_R_NOSPACE);
}
return (ISC_R_SUCCESS);
}
int fd = -1;
int res = 0;
if (fd == -1) {
}
if (result == ISC_R_SUCCESS) {
if (res != 0) {
}
}
if (fd != -1)
return (result);
}
int fd;
FILE *f;
/*
* Win32 does not have mkstemp. Using emulation above.
*/
if (fd == -1)
if (result == ISC_R_SUCCESS) {
if (f == NULL) {
} 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_isabsolute(const char *filename) {
/*
* Look for c:\path\... style or \\computer\shar\path... UNC style file specs
*/
}
isc_file_iscurrentdir(const char *filename) {
}
const char *
isc_file_basename(const char *filename) {
char *s;
if (s == NULL)
return (filename);
return (s + 1);
}
const char *s;
char *p;
/*
* Strip the path from the name
*/
s = isc_file_basename(filename);
<<<<<<< file.c
if (s == NULL) {
return (ISC_R_NOSPACE);
}
=======
if (s == NULL)
return (ISC_R_NOSPACE);
>>>>>>> 1.8
/*
* Strip any and all suffixes
*/
p = strchr(s, '.');
if (p == NULL) {
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
/*
* Copy the result to the buffer
*/
len = p - s;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}