GnomeVFSC語言統(tǒng)一文件系統(tǒng)接口
GnomeVFS 是一個 C 語言的庫,提供了統(tǒng)一的接口用來訪問各種不同的文件系統(tǒng),支持包括:WebDAV, ftp, 本地文件系統(tǒng), gzip, bzip2, cdda 等多種文件系統(tǒng)。
示例代碼:
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;
}
評論
圖片
表情
