GnomeVFS - C语言统一文件系统接口


未知
跨平台
C/C++

软件简介

GnomeVFS 是一个 C 语言的库,提供了统一的接口用来访问各种不同的文件系统,支持包括:WebDAV, ftp, 本地文件系统, gzip,
bzip2, cdda 等多种文件系统。

示例代码:

static GnomeVFSResult  
do_read (GnomeVFSMethod       *method,  
          GnomeVFSMethodHandle *method_handle,  
          gpointer              buffer,  
          GnomeVFSFileSize      bytes,  
          GnomeVFSFileSize     *bytes_read,  
          GnomeVFSContext      *context)  
{  
   FileHandle *handle = (FileHandle *) method_handle;  
   if (!handle->str) {  
      /* This is the first pass, get the content string. */  
      handle->str = g_strdup (handle->fnode->content);  
      handle->size = handle->fnode->size;  
      handle->bytes_written = 0;  
   }  
   if (handle->bytes_written >= handle->len) {  
       /* The whole file is read, return EOF. */  
       *bytes_read = 0;  
      return GNOME_VFS_ERROR_EOF;  
    }  
   *bytes_read = MIN (bytes, handle->size - handle->bytes_written);  
   memcpy (buffer, handle->str + handle->bytes_written, *bytes_read);  
   handle->bytes_written += *bytes_read;  
   return GNOME_VFS_OK;  
}