Added.
[silc.git] / lib / silcutil / silcfileutil.c
index c57cc42beb0457ea33b07c1f317a80457e0fb010..c28ba38ffcbf41b9faed74c2a3b327da3b7b393f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2007 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -82,7 +82,9 @@ int silc_file_writefile(const char *filename, const char *buffer,
     return -1;
   }
 
+#ifdef SILC_UNIX
   fsync(fd);
+#endif /* SILC_UNIX */
 
   return silc_file_close(fd);
 }
@@ -112,7 +114,9 @@ int silc_file_writefile_mode(const char *filename, const char *buffer,
     return -1;
   }
 
+#ifdef SILC_UNIX
   fsync(fd);
+#endif /* SILC_UNIX */
 
   return silc_file_close(fd);
 }
@@ -120,10 +124,11 @@ int silc_file_writefile_mode(const char *filename, const char *buffer,
 /* Reads a file to a buffer. The allocated buffer is returned. Length of
    the file read is returned to the return_len argument. */
 
-char *silc_file_readfile(const char *filename, SilcUInt32 *return_len)
+char *silc_file_readfile(const char *filename, SilcUInt32 *return_len,
+                        SilcStack stack)
 {
   int fd;
-  char *buffer;
+  unsigned char *buffer;
   int filelen;
 
   fd = silc_file_open(filename, O_RDONLY);
@@ -150,7 +155,7 @@ char *silc_file_readfile(const char *filename, SilcUInt32 *return_len)
     return NULL;
   }
 
-  buffer = silc_calloc(filelen + 1, sizeof(char));
+  buffer = silc_calloc(filelen + 1, sizeof(*buffer));
 
   if ((silc_file_read(fd, buffer, filelen)) == -1) {
     memset(buffer, 0, sizeof(buffer));
@@ -166,7 +171,7 @@ char *silc_file_readfile(const char *filename, SilcUInt32 *return_len)
   if (return_len)
     *return_len = filelen;
 
-  return buffer;
+  return (char *)buffer;
 }
 
 /* Returns the size of `filename'. Returns 0 on error. */
@@ -176,11 +181,15 @@ SilcUInt64 silc_file_size(const char *filename)
   int ret;
   struct stat stats;
 
-#ifndef SILC_WIN32
+#ifdef SILC_WIN32
+  ret = stat(filename, &stats);
+#endif /* SILC_WIN32 */
+#ifdef SILC_UNIX
   ret = lstat(filename, &stats);
-#else
+#endif /* SILC_UNIX */
+#ifdef SILC_SYMBIAN
   ret = stat(filename, &stats);
-#endif
+#endif /* SILC_SYMBIAN */
   if (ret < 0)
     return 0;