Accept silc_file_stat and silc_file_fstat with the stat struct as NULL
authorPekka Riikonen <priikone@silcnet.org>
Sun, 22 Jun 2008 19:54:43 +0000 (22:54 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Sun, 22 Jun 2008 19:54:43 +0000 (22:54 +0300)
lib/silcutil/silcfileutil.c
lib/silcutil/silcfileutil.h

index e21da72db217e0040b8c34001ca5b5b19c5b7af0..12e9f203a9f78b02c425c4e6126025c128a1195b 100644 (file)
@@ -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;
 }
index 0824553804a32a497b216e565b6f3d2aa4fe7f8c..3bdf3ff9b2b645d109d5f35348ec51ab235e7f68 100644 (file)
@@ -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,