diff options
Diffstat (limited to 'lib/isc/unix/file.c')
| -rw-r--r-- | lib/isc/unix/file.c | 37 | 
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index 7bb25d725f079..1b7d563d875a1 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -1,5 +1,5 @@  /* - * Copyright (C) 2004, 2005, 2007, 2009, 2011, 2012  Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2009, 2011-2014  Internet Systems Consortium, Inc. ("ISC")   * Copyright (C) 2000-2002  Internet Software Consortium.   *   * Permission to use, copy, modify, and/or distribute this software for any @@ -27,11 +27,7 @@   * 2. Redistributions in binary form must reproduce the above copyright   *    notice, this list of conditions and the following disclaimer in the   *    documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - *    must display the following acknowledgement: - *      This product includes software developed by the University of - *      California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 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.   * @@ -97,6 +93,33 @@ file_stats(const char *file, struct stat *stats) {  	return (result);  } +static isc_result_t +fd_stats(int fd, struct stat *stats) { +	isc_result_t result = ISC_R_SUCCESS; + +	REQUIRE(stats != NULL); + +	if (fstat(fd, stats) != 0) +		result = isc__errno2result(errno); + +	return (result); +} + +isc_result_t +isc_file_getsizefd(int fd, off_t *size) { +	isc_result_t result; +	struct stat stats; + +	REQUIRE(size != NULL); + +	result = fd_stats(fd, &stats); + +	if (result == ISC_R_SUCCESS) +		*size = stats.st_size; + +	return (result); +} +  isc_result_t  isc_file_mode(const char *file, mode_t *modep) {  	isc_result_t result; @@ -462,7 +485,7 @@ isc_file_progname(const char *filename, char *buf, size_t buflen) {  	if (len > buflen)  		return (ISC_R_NOSPACE); -	memcpy(buf, base, len); +	memmove(buf, base, len);  	return (ISC_R_SUCCESS);  }  | 
