From 7ec4fcdab215d619ab28156144a0dde26161bc62 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 22 Jun 2008 22:54:43 +0300 Subject: [PATCH] Accept silc_file_stat and silc_file_fstat with the stat struct as NULL --- lib/silcutil/silcfileutil.c | 13 +++++-------- lib/silcutil/silcfileutil.h | 5 ++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/silcutil/silcfileutil.c b/lib/silcutil/silcfileutil.c index e21da72d..12e9f203 100644 --- a/lib/silcutil/silcfileutil.c +++ b/lib/silcutil/silcfileutil.c @@ -303,7 +303,7 @@ SilcBool silc_file_stat(const char *filename, SilcBool follow_symlinks, { struct stat status; - if (silc_unlikely(!filename || !return_stat)) { + if (silc_unlikely(!filename)) { silc_set_errno(SILC_ERR_INVALID_ARGUMENT); return FALSE; } @@ -329,7 +329,8 @@ SilcBool silc_file_stat(const char *filename, SilcBool follow_symlinks, #endif /* HAVE_LSTAT */ } - silc_file_fill_stat(&status, return_stat); + if (return_stat) + silc_file_fill_stat(&status, return_stat); return TRUE; } @@ -340,17 +341,13 @@ SilcBool silc_file_fstat(int fd, SilcFileStat return_stat) { struct stat status; - if (silc_unlikely(!return_stat)) { - silc_set_errno(SILC_ERR_INVALID_ARGUMENT); - return FALSE; - } - if (silc_unlikely(fstat(fd, &status) != 0)) { silc_set_errno_posix(errno); return FALSE; } - silc_file_fill_stat(&status, return_stat); + if (return_stat) + silc_file_fill_stat(&status, return_stat); return TRUE; } diff --git a/lib/silcutil/silcfileutil.h b/lib/silcutil/silcfileutil.h index 08245538..3bdf3ff9 100644 --- a/lib/silcutil/silcfileutil.h +++ b/lib/silcutil/silcfileutil.h @@ -217,8 +217,7 @@ char *silc_file_readfile(const char *filename, SilcUInt32 *return_len, * * DESCRIPTION * - * Writes a buffer to the file. If the file is created specific mode is - * set to the file. + * Writes a buffer to the file. Returns 0 on success and -1 on error. * ***/ int silc_file_writefile(const char *filename, const char *buffer, @@ -234,7 +233,7 @@ int silc_file_writefile(const char *filename, const char *buffer, * DESCRIPTION * * Writes a buffer to the file. If the file is created the specified `mode' - * is set to the file. + * is set to the file. Returns 0 on success and -1 on error. * ***/ int silc_file_writefile_mode(const char *filename, const char *buffer, -- 2.24.0