mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-27 03:51:16 -05:00
REQUIRE that parameters are not NULL in many functions [RT #1470]
This commit is contained in:
parent
024550401d
commit
bb5de15290
1 changed files with 30 additions and 4 deletions
|
|
@ -15,7 +15,7 @@
|
|||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: file.c,v 1.35 2001/06/08 21:53:49 tale Exp $ */
|
||||
/* $Id: file.c,v 1.36 2001/07/10 04:23:01 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
|
@ -47,6 +47,9 @@ static isc_result_t
|
|||
file_stats(const char *file, struct stat *stats) {
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
REQUIRE(file != NULL);
|
||||
REQUIRE(stats != NULL);
|
||||
|
||||
if (stat(file, stats) != 0)
|
||||
result = isc__errno2result(errno);
|
||||
|
||||
|
|
@ -58,7 +61,8 @@ isc_file_getmodtime(const char *file, isc_time_t *time) {
|
|||
isc_result_t result;
|
||||
struct stat stats;
|
||||
|
||||
REQUIRE(file != NULL && time != NULL);
|
||||
REQUIRE(file != NULL);
|
||||
REQUIRE(time != NULL);
|
||||
|
||||
result = file_stats(file, &stats);
|
||||
|
||||
|
|
@ -126,6 +130,8 @@ isc_file_template(const char *path, const char *templet, char *buf,
|
|||
size_t buflen) {
|
||||
char *s;
|
||||
|
||||
REQUIRE(path != NULL);
|
||||
REQUIRE(templet != NULL);
|
||||
REQUIRE(buf != NULL);
|
||||
|
||||
s = strrchr(templet, '/');
|
||||
|
|
@ -157,6 +163,9 @@ isc_file_renameunique(const char *file, char *templet) {
|
|||
int res = 0;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
|
||||
REQUIRE(file != NULL);
|
||||
REQUIRE(templet != NULL);
|
||||
|
||||
fd = mkstemp(templet);
|
||||
if (fd == -1) {
|
||||
result = isc__errno2result(errno);
|
||||
|
|
@ -207,6 +216,8 @@ isc_result_t
|
|||
isc_file_remove(const char *filename) {
|
||||
int r;
|
||||
|
||||
REQUIRE(filename != NULL);
|
||||
|
||||
r = unlink(filename);
|
||||
if (r == 0)
|
||||
return (ISC_R_SUCCESS);
|
||||
|
|
@ -218,6 +229,9 @@ isc_result_t
|
|||
isc_file_rename(const char *oldname, const char *newname) {
|
||||
int r;
|
||||
|
||||
REQUIRE(oldname != NULL);
|
||||
REQUIRE(newname != NULL);
|
||||
|
||||
r = rename(oldname, newname);
|
||||
if (r == 0)
|
||||
return (ISC_R_SUCCESS);
|
||||
|
|
@ -229,16 +243,20 @@ isc_boolean_t
|
|||
isc_file_exists(const char *pathname) {
|
||||
struct stat stats;
|
||||
|
||||
REQUIRE(pathname != NULL);
|
||||
|
||||
return (ISC_TF(file_stats(pathname, &stats) == ISC_R_SUCCESS));
|
||||
}
|
||||
|
||||
isc_boolean_t
|
||||
isc_file_isabsolute(const char *filename) {
|
||||
REQUIRE(filename != NULL);
|
||||
return (ISC_TF(filename[0] == '/'));
|
||||
}
|
||||
|
||||
isc_boolean_t
|
||||
isc_file_iscurrentdir(const char *filename) {
|
||||
REQUIRE(filename != NULL);
|
||||
return (ISC_TF(filename[0] == '.' && filename[1] == '\0'));
|
||||
}
|
||||
|
||||
|
|
@ -246,6 +264,8 @@ const char *
|
|||
isc_file_basename(const char *filename) {
|
||||
char *s;
|
||||
|
||||
REQUIRE(filename != NULL);
|
||||
|
||||
s = strrchr(filename, '/');
|
||||
if (s == NULL)
|
||||
return (filename);
|
||||
|
|
@ -255,8 +275,14 @@ isc_file_basename(const char *filename) {
|
|||
|
||||
isc_result_t
|
||||
isc_file_progname(const char *filename, char *buf, size_t buflen) {
|
||||
const char *base = isc_file_basename(filename);
|
||||
size_t len = strlen(base) + 1;
|
||||
const char *base;
|
||||
size_t len;
|
||||
|
||||
REQUIRE(filename != NULL);
|
||||
REQUIRE(buf != NULL);
|
||||
|
||||
base = isc_file_basename(filename);
|
||||
len = strlen(base) + 1;
|
||||
|
||||
if (len > buflen)
|
||||
return (ISC_R_NOSPACE);
|
||||
|
|
|
|||
Loading…
Reference in a new issue