Integer type name change.
[silc.git] / lib / silcsftp / sftp_fs_memory.c
index 81434c13b816260bda3359871bdcd96f1b953c4d..b60cce73cb6c9c80f6871cea83904480d3b2770a 100644 (file)
@@ -35,7 +35,7 @@ typedef struct MemFSEntryStruct {
   bool directory;                  /* TRUE if this is directory */
   SilcSFTPFSMemoryPerm perm;       /* Permissions */
   struct MemFSEntryStruct **entry;  /* Files and sub-directories */
-  uint32 entry_count;              /* Number of files and sub-directories */
+  SilcUInt32 entry_count;                  /* Number of files and sub-directories */
   struct MemFSEntryStruct *parent;  /* non-NULL if `directory' is TRUE,
                                       includes parent directory. */
   unsigned long created;           /* Time of creation */
@@ -43,7 +43,7 @@ typedef struct MemFSEntryStruct {
 
 /* File handle. */
 typedef struct {
-  uint32 handle;                   /* Handle index */
+  SilcUInt32 handle;               /* Handle index */
   int fd;                          /* Real file handle */
   MemFSEntry entry;                /* Filesystem entry */
 } *MemFSFileHandle;
@@ -53,7 +53,7 @@ typedef struct {
   MemFSEntry root;                 /* Root of the filesystem hierarchy */
   SilcSFTPFSMemoryPerm root_perm;
   MemFSFileHandle *handles;        /* Open file handles */
-  uint32 handles_count;
+  SilcUInt32 handles_count;
 } *MemFS;
 
 /* Generates absolute path from relative path that may include '.' and '..'
@@ -151,7 +151,7 @@ static bool mem_del_entry(MemFSEntry entry, bool check_perm)
    This does not check subdirectories recursively. */
 
 static MemFSEntry mem_find_entry(MemFSEntry dir, const char *name,
-                                uint32 name_len)
+                                SilcUInt32 name_len)
 {
   int i;
 
@@ -205,7 +205,7 @@ static MemFSEntry mem_find_entry_path(MemFSEntry dir, const char *p)
    not check subdirectories recursively. */
 
 static bool mem_del_entry_name(MemFSEntry dir, const char *name,
-                              uint32 name_len, bool check_perm)
+                              SilcUInt32 name_len, bool check_perm)
 {
   MemFSEntry entry;
 
@@ -277,7 +277,7 @@ static bool mem_del_handle(MemFS fs, MemFSFileHandle handle)
   if (fs->handles[handle->handle] == handle) {
     fs->handles[handle->handle] = NULL;
     if (handle->fd != -1)
-      close(handle->fd);
+      silc_file_close(handle->fd);
     silc_free(handle);
     return TRUE;
   }
@@ -287,7 +287,7 @@ static bool mem_del_handle(MemFS fs, MemFSFileHandle handle)
 
 /* Find handle by handle index. */
 
-static MemFSFileHandle mem_find_handle(MemFS fs, uint32 handle)
+static MemFSFileHandle mem_find_handle(MemFS fs, SilcUInt32 handle)
 {
   if (handle > fs->handles_count)
     return NULL;
@@ -432,10 +432,10 @@ bool silc_sftp_fs_memory_del_file(SilcSFTPFilesystem fs, void *dir,
 
 SilcSFTPHandle mem_get_handle(void *context, SilcSFTP sftp,
                              const unsigned char *data,
-                             uint32 data_len)
+                             SilcUInt32 data_len)
 {
   MemFS fs = (MemFS)context;
-  uint32 handle;
+  SilcUInt32 handle;
 
   if (data_len < 4)
     return NULL;
@@ -446,7 +446,7 @@ SilcSFTPHandle mem_get_handle(void *context, SilcSFTP sftp,
 
 unsigned char *mem_encode_handle(void *context, SilcSFTP sftp,
                                 SilcSFTPHandle handle,
-                                uint32 *handle_len)
+                                SilcUInt32 *handle_len)
 {
   unsigned char *data;
   MemFSFileHandle h = (MemFSFileHandle)handle;
@@ -514,9 +514,9 @@ void mem_open(void *context, SilcSFTP sftp,
     flags |= O_APPEND;
 
   /* Attempt to open the file for real. */
-  fd = open(entry->data + 7, flags, 
-           (attrs->flags & SILC_SFTP_ATTR_PERMISSIONS ?
-            attrs->permissions : 0600));
+  fd = silc_file_open_mode(entry->data + 7, flags, 
+                          (attrs->flags & SILC_SFTP_ATTR_PERMISSIONS ?
+                           attrs->permissions : 0600));
   if (fd == -1) {
     (*callback)(sftp, silc_sftp_map_errno(errno), NULL, callback_context);
     return;
@@ -538,7 +538,7 @@ void mem_close(void *context, SilcSFTP sftp,
   int ret;
 
   if (h->fd != -1) {
-    ret = close(h->fd);
+    ret = silc_file_close(h->fd);
     if (ret == -1) {
       (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, 
                  callback_context);
@@ -552,8 +552,8 @@ void mem_close(void *context, SilcSFTP sftp,
 
 void mem_read(void *context, SilcSFTP sftp,
              SilcSFTPHandle handle,
-             uint64 offset, 
-             uint32 len,
+             SilcUInt64 offset, 
+             SilcUInt32 len,
              SilcSFTPDataCallback callback,
              void *callback_context)
 {
@@ -568,7 +568,7 @@ void mem_read(void *context, SilcSFTP sftp,
   lseek(h->fd, (off_t)offset, SEEK_SET);
 
   /* Attempt to read */
-  ret = read(h->fd, data, len);
+  ret = silc_file_read(h->fd, data, len);
   if (ret <= 0) {
     if (!ret)
       (*callback)(sftp, SILC_SFTP_STATUS_EOF, NULL, 0, callback_context);
@@ -587,9 +587,9 @@ void mem_read(void *context, SilcSFTP sftp,
 
 void mem_write(void *context, SilcSFTP sftp,
               SilcSFTPHandle handle,
-              uint64 offset,
+              SilcUInt64 offset,
               const unsigned char *data,
-              uint32 data_len,
+              SilcUInt32 data_len,
               SilcSFTPStatusCallback callback,
               void *callback_context)
 {
@@ -599,7 +599,7 @@ void mem_write(void *context, SilcSFTP sftp,
   lseek(h->fd, (off_t)offset, SEEK_SET);
 
   /* Attempt to write */
-  ret = write(h->fd, data, data_len);
+  ret = silc_file_write(h->fd, data, data_len);
   if (ret <= 0) {
     (*callback)(sftp, silc_sftp_map_errno(errno), NULL, NULL, 
                callback_context);
@@ -661,7 +661,7 @@ void mem_opendir(void *context, SilcSFTP sftp,
   MemFSFileHandle handle;
 
   if (!path || !strlen(path))
-    path = (const char *)strdup("/");
+    path = (const char *)DIR_SEPARATOR;
 
   /* Find such directory */
   entry = mem_find_entry_path(fs->root, path);
@@ -699,7 +699,7 @@ void mem_readdir(void *context, SilcSFTP sftp,
   SilcSFTPAttributes attrs;
   int i;
   char long_name[256];
-  unsigned long filesize = 0;
+  SilcUInt64 filesize = 0;
   char *date;
   struct stat stats;
 
@@ -730,14 +730,13 @@ void mem_readdir(void *context, SilcSFTP sftp,
       *strrchr(date, ':') = '\0';
 
     if (!entry->directory)
-      if (!lstat(entry->data + 7, &stats))
-       filesize = stats.st_size;
+      filesize = silc_file_size(entry->data + 7);
 
     /* Long name format is:
        drwx------   1   324210 Apr  8 08:40 mail/
        1234567890 123 12345678 123456789012 */
     snprintf(long_name, sizeof(long_name) - 1,
-            "%c%c%c%c------ %3d %8lu %12s %s%s",
+            "%c%c%c%c------ %3d %8llu %12s %s%s",
             (entry->directory ? 'd' : '-'),
             ((entry->perm & SILC_SFTP_FS_PERM_READ) ? 'r' : '-'),
             ((entry->perm & SILC_SFTP_FS_PERM_WRITE) ? 'w' : '-'),
@@ -796,7 +795,7 @@ void mem_stat(void *context, SilcSFTP sftp,
   struct stat stats;
 
   if (!path || !strlen(path))
-    path = (const char *)strdup("/");
+    path = (const char *)DIR_SEPARATOR;
 
   /* Find such directory */
   entry = mem_find_entry_path(fs->root, path);
@@ -846,7 +845,7 @@ void mem_lstat(void *context, SilcSFTP sftp,
   struct stat stats;
 
   if (!path || !strlen(path))
-    path = (const char *)strdup("/");
+    path = (const char *)DIR_SEPARATOR;
 
   /* Find such directory */
   entry = mem_find_entry_path(fs->root, path);
@@ -861,7 +860,11 @@ void mem_lstat(void *context, SilcSFTP sftp,
   }    
 
   /* Get real stat */
+#ifndef SILC_WIN32
   ret = lstat(entry->data + 7, &stats);
+#else
+  ret = stat(entry->data + 7, &stats);
+#endif
   if (ret == -1) {
     (*callback)(sftp, silc_sftp_map_errno(errno), NULL, callback_context);
     return;
@@ -976,7 +979,7 @@ void mem_realpath(void *context, SilcSFTP sftp,
   SilcSFTPName name;
 
   if (!path || !strlen(path))
-    path = (const char *)strdup("/");
+    path = (const char *)DIR_SEPARATOR;
 
   realpath = mem_expand_path(fs->root, path);
   if (!realpath) {
@@ -1002,7 +1005,7 @@ void mem_realpath(void *context, SilcSFTP sftp,
 void mem_extended(void *context, SilcSFTP sftp,
                  const char *request,
                  const unsigned char *data,
-                 uint32 data_len,
+                 SilcUInt32 data_len,
                  SilcSFTPExtendedCallback callback,
                  void *callback_context)
 {