Browse Source

Add stat() function to IsoFileSource interface.

release-1.5.4.branch
Vreixo Formoso 14 years ago
parent
commit
b35e090c1b
  1. 40
      src/fs_local.c
  2. 16
      src/fsource.h

40
src/fs_local.c

@ -99,6 +99,45 @@ int lfs_lstat(IsoFileSource *src, struct stat *info)
}
return ISO_SUCCESS;
}
static
int lfs_stat(IsoFileSource *src, struct stat *info)
{
_LocalFsFileSource *data;
if (src == NULL || info == NULL) {
return ISO_NULL_POINTER;
}
data = src->data;
if (stat(data->path, info) != 0) {
int err;
/* error, choose an appropriate return code */
switch(errno) {
case EACCES:
err = ISO_FILE_ACCESS_DENIED;
break;
case ENOTDIR:
case ENAMETOOLONG:
case ELOOP:
err = ISO_FILE_BAD_PATH;
break;
case ENOENT:
err = ISO_FILE_DOESNT_EXIST;
break;
case EFAULT:
case ENOMEM:
err = ISO_MEM_ERROR;
break;
default:
err = ISO_FILE_ERROR;
break;
}
return err;
}
return ISO_SUCCESS;
}
static
int lfs_open(IsoFileSource *src)
@ -391,6 +430,7 @@ int iso_file_source_new_lfs(const char *path, IsoFileSource **src)
lfs_src->get_path = lfs_get_path;
lfs_src->get_name = lfs_get_name;
lfs_src->lstat = lfs_lstat;
lfs_src->stat = lfs_stat;
lfs_src->open = lfs_open;
lfs_src->close = lfs_close;
lfs_src->read = lfs_read;

16
src/fsource.h

@ -82,6 +82,22 @@ struct Iso_File_Source
* ISO_NULL_POINTER
*/
int (*lstat)(IsoFileSource *src, struct stat *info);
/**
* Get information about the file. If the file is a symlink, the info
* returned refers to the destination.
*
* @return
* 1 success, < 0 error
* Error codes:
* ISO_FILE_ACCESS_DENIED
* ISO_FILE_BAD_PATH
* ISO_FILE_DOESNT_EXIST
* ISO_MEM_ERROR
* ISO_FILE_ERROR
* ISO_NULL_POINTER
*/
int (*stat)(IsoFileSource *src, struct stat *info);
/**
* Opens the source.

Loading…
Cancel
Save