mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 01:54:24 +03:00
lib/vfs/interface.c: fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
a2d32c22bb
commit
4667a9be0d
@ -178,7 +178,7 @@ mc_def_ungetlocalcopy (const vfs_path_t * filename_vpath,
|
||||
if (fdin != -1)
|
||||
close (fdin);
|
||||
unlink (local);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -193,12 +193,13 @@ mc_open (const vfs_path_t * vpath, int flags, ...)
|
||||
const vfs_path_element_t *path_element;
|
||||
|
||||
if (vpath == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
/* Get the mode flag */
|
||||
if (flags & O_CREAT)
|
||||
if ((flags & O_CREAT) != 0)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, flags);
|
||||
/* We have to use PROMOTED_MODE_T instead of mode_t. Doing 'va_arg (ap, mode_t)'
|
||||
* fails on systems where 'mode_t' is smaller than 'int' because of C's "default
|
||||
@ -211,6 +212,7 @@ mc_open (const vfs_path_t * vpath, int flags, ...)
|
||||
if (vfs_path_element_valid (path_element) && path_element->class->open != NULL)
|
||||
{
|
||||
void *info;
|
||||
|
||||
/* open must be supported */
|
||||
info = path_element->class->open (vpath, flags, mode);
|
||||
if (info == NULL)
|
||||
@ -235,13 +237,11 @@ int mc_##name inarg \
|
||||
const vfs_path_element_t *path_element; \
|
||||
\
|
||||
if (vpath == NULL) \
|
||||
return -1; \
|
||||
return (-1); \
|
||||
\
|
||||
path_element = vfs_path_get_by_index (vpath, -1); \
|
||||
if (!vfs_path_element_valid (path_element)) \
|
||||
{ \
|
||||
return -1; \
|
||||
} \
|
||||
return (-1); \
|
||||
\
|
||||
result = path_element->class->name != NULL ? path_element->class->name callarg : -1; \
|
||||
if (result == -1) \
|
||||
@ -268,7 +268,7 @@ mc_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
|
||||
int result = -1;
|
||||
|
||||
if (vpath1 == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (vpath1 != NULL)
|
||||
{
|
||||
@ -300,11 +300,14 @@ ssize_t mc_##name (int handle, C void *buf, size_t count) \
|
||||
struct vfs_class *vfs; \
|
||||
void *fsinfo = NULL; \
|
||||
int result; \
|
||||
\
|
||||
if (handle == -1) \
|
||||
return -1; \
|
||||
return (-1); \
|
||||
\
|
||||
vfs = vfs_class_find_by_handle (handle, &fsinfo); \
|
||||
if (vfs == NULL) \
|
||||
return -1; \
|
||||
return (-1); \
|
||||
\
|
||||
result = vfs->name != NULL ? vfs->name (fsinfo, buf, count) : -1; \
|
||||
if (result == -1) \
|
||||
errno = vfs->name != NULL ? vfs_ferrno (vfs) : E_NOTSUPP; \
|
||||
@ -328,7 +331,7 @@ int mc_##name (const vfs_path_t *vpath1, const vfs_path_t *vpath2) \
|
||||
const vfs_path_element_t *path_element2; \
|
||||
\
|
||||
if (vpath1 == NULL || vpath2 == NULL) \
|
||||
return -1; \
|
||||
return (-1); \
|
||||
\
|
||||
path_element1 = vfs_path_get_by_index (vpath1, (-1)); \
|
||||
path_element2 = vfs_path_get_by_index (vpath2, (-1)); \
|
||||
@ -337,12 +340,11 @@ int mc_##name (const vfs_path_t *vpath1, const vfs_path_t *vpath2) \
|
||||
path_element1->class != path_element2->class) \
|
||||
{ \
|
||||
errno = EXDEV; \
|
||||
return -1; \
|
||||
}\
|
||||
return (-1); \
|
||||
} \
|
||||
\
|
||||
result = path_element1->class->name != NULL \
|
||||
? path_element1->class->name (vpath1, vpath2) \
|
||||
: -1; \
|
||||
? path_element1->class->name (vpath1, vpath2) : -1; \
|
||||
if (result == -1) \
|
||||
errno = path_element1->class->name != NULL ? vfs_ferrno (path_element1->class) : E_NOTSUPP; \
|
||||
return result; \
|
||||
@ -396,18 +398,18 @@ mc_close (int handle)
|
||||
int result;
|
||||
|
||||
if (handle == -1)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
vfs = vfs_class_find_by_handle (handle, &fsinfo);
|
||||
if (vfs == NULL || fsinfo == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (handle < 3)
|
||||
return close (handle);
|
||||
|
||||
if (!vfs->close)
|
||||
if (vfs->close == NULL)
|
||||
vfs_die ("VFS must support close.\n");
|
||||
result = (*vfs->close) (fsinfo);
|
||||
result = vfs->close (fsinfo);
|
||||
vfs_free_handle (handle);
|
||||
if (result == -1)
|
||||
errno = vfs_ferrno (vfs);
|
||||
@ -428,15 +430,13 @@ mc_opendir (const vfs_path_t * vpath)
|
||||
return NULL;
|
||||
|
||||
path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, -1);
|
||||
|
||||
if (!vfs_path_element_valid (path_element))
|
||||
{
|
||||
errno = E_NOTSUPP;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info = path_element->class->opendir ? (*path_element->class->opendir) (vpath) : NULL;
|
||||
|
||||
info = path_element->class->opendir ? path_element->class->opendir (vpath) : NULL;
|
||||
if (info == NULL)
|
||||
{
|
||||
errno = path_element->class->opendir ? vfs_ferrno (path_element->class) : E_NOTSUPP;
|
||||
@ -470,7 +470,7 @@ mc_readdir (DIR * dirp)
|
||||
struct dirent *entry = NULL;
|
||||
vfs_path_element_t *vfs_path_element;
|
||||
|
||||
if (!mc_readdir_result)
|
||||
if (mc_readdir_result == NULL)
|
||||
{
|
||||
/* We can't just allocate struct dirent as (see man dirent.h)
|
||||
* struct dirent has VERY nonnaive semantics of allocating
|
||||
@ -485,11 +485,12 @@ mc_readdir (DIR * dirp)
|
||||
mc_readdir_result = (struct dirent *) g_malloc (sizeof (struct dirent) + MAXNAMLEN + 1);
|
||||
}
|
||||
|
||||
if (!dirp)
|
||||
if (dirp == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = *(int *) dirp;
|
||||
|
||||
vfs = vfs_class_find_by_handle (handle, &fsinfo);
|
||||
@ -497,9 +498,9 @@ mc_readdir (DIR * dirp)
|
||||
return NULL;
|
||||
|
||||
vfs_path_element = (vfs_path_element_t *) fsinfo;
|
||||
if (vfs->readdir)
|
||||
if (vfs->readdir != NULL)
|
||||
{
|
||||
entry = (*vfs->readdir) (vfs_path_element->dir.info);
|
||||
entry = vfs->readdir (vfs_path_element->dir.info);
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -562,13 +563,12 @@ mc_stat (const vfs_path_t * vpath, struct stat *buf)
|
||||
const vfs_path_element_t *path_element;
|
||||
|
||||
if (vpath == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
path_element = vfs_path_get_by_index (vpath, -1);
|
||||
|
||||
if (vfs_path_element_valid (path_element))
|
||||
{
|
||||
result = path_element->class->stat ? (*path_element->class->stat) (vpath, buf) : -1;
|
||||
result = path_element->class->stat ? path_element->class->stat (vpath, buf) : -1;
|
||||
if (result == -1)
|
||||
errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP;
|
||||
}
|
||||
@ -585,13 +585,12 @@ mc_lstat (const vfs_path_t * vpath, struct stat *buf)
|
||||
const vfs_path_element_t *path_element;
|
||||
|
||||
if (vpath == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
path_element = vfs_path_get_by_index (vpath, -1);
|
||||
|
||||
if (vfs_path_element_valid (path_element))
|
||||
{
|
||||
result = path_element->class->lstat ? (*path_element->class->lstat) (vpath, buf) : -1;
|
||||
result = path_element->class->lstat ? path_element->class->lstat (vpath, buf) : -1;
|
||||
if (result == -1)
|
||||
errno = path_element->class->name ? vfs_ferrno (path_element->class) : E_NOTSUPP;
|
||||
}
|
||||
@ -609,13 +608,13 @@ mc_fstat (int handle, struct stat *buf)
|
||||
int result;
|
||||
|
||||
if (handle == -1)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
vfs = vfs_class_find_by_handle (handle, &fsinfo);
|
||||
if (vfs == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
result = vfs->fstat ? (*vfs->fstat) (fsinfo, buf) : -1;
|
||||
result = vfs->fstat ? vfs->fstat (fsinfo, buf) : -1;
|
||||
if (result == -1)
|
||||
errno = vfs->fstat ? vfs_ferrno (vfs) : E_NOTSUPP;
|
||||
return result;
|
||||
@ -633,7 +632,6 @@ mc_getlocalcopy (const vfs_path_t * pathname_vpath)
|
||||
return NULL;
|
||||
|
||||
path_element = vfs_path_get_by_index (pathname_vpath, -1);
|
||||
|
||||
if (vfs_path_element_valid (path_element))
|
||||
{
|
||||
result = path_element->class->getlocalcopy != NULL ?
|
||||
@ -651,20 +649,19 @@ int
|
||||
mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_vpath,
|
||||
gboolean has_changed)
|
||||
{
|
||||
int return_value = -1;
|
||||
int result = -1;
|
||||
const vfs_path_element_t *path_element;
|
||||
|
||||
if (pathname_vpath == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
path_element = vfs_path_get_by_index (pathname_vpath, -1);
|
||||
|
||||
if (vfs_path_element_valid (path_element))
|
||||
return_value = path_element->class->ungetlocalcopy != NULL ?
|
||||
result = path_element->class->ungetlocalcopy != NULL ?
|
||||
path_element->class->ungetlocalcopy (pathname_vpath, local_vpath, has_changed) :
|
||||
mc_def_ungetlocalcopy (pathname_vpath, local_vpath, has_changed);
|
||||
|
||||
return return_value;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -686,7 +683,7 @@ mc_chdir (const vfs_path_t * vpath)
|
||||
vfs_path_t *cd_vpath;
|
||||
|
||||
if (vpath == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (vpath->relative)
|
||||
cd_vpath = vfs_path_to_absolute (vpath);
|
||||
@ -694,14 +691,11 @@ mc_chdir (const vfs_path_t * vpath)
|
||||
cd_vpath = vfs_path_clone (vpath);
|
||||
|
||||
path_element = vfs_path_get_by_index (cd_vpath, -1);
|
||||
|
||||
if (!vfs_path_element_valid (path_element) || path_element->class->chdir == NULL)
|
||||
{
|
||||
goto error_end;
|
||||
}
|
||||
|
||||
result = (*path_element->class->chdir) (cd_vpath);
|
||||
|
||||
result = path_element->class->chdir (cd_vpath);
|
||||
if (result == -1)
|
||||
{
|
||||
errno = vfs_ferrno (path_element->class);
|
||||
@ -750,7 +744,7 @@ mc_chdir (const vfs_path_t * vpath)
|
||||
|
||||
error_end:
|
||||
vfs_path_free (cd_vpath);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -763,13 +757,13 @@ mc_lseek (int fd, off_t offset, int whence)
|
||||
off_t result;
|
||||
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
vfs = vfs_class_find_by_handle (fd, &fsinfo);
|
||||
if (vfs == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
result = vfs->lseek ? (*vfs->lseek) (fsinfo, offset, whence) : -1;
|
||||
result = vfs->lseek ? vfs->lseek (fsinfo, offset, whence) : -1;
|
||||
if (result == -1)
|
||||
errno = vfs->lseek ? vfs_ferrno (vfs) : E_NOTSUPP;
|
||||
return result;
|
||||
@ -840,7 +834,7 @@ mc_tmpdir (void)
|
||||
const char *error = NULL;
|
||||
|
||||
/* Check if already correctly initialized */
|
||||
if (tmpdir && lstat (tmpdir, &st) == 0 && S_ISDIR (st.st_mode) &&
|
||||
if (tmpdir != NULL && lstat (tmpdir, &st) == 0 && S_ISDIR (st.st_mode) &&
|
||||
st.st_uid == getuid () && (st.st_mode & 0777) == 0700)
|
||||
return tmpdir;
|
||||
|
||||
@ -849,8 +843,7 @@ mc_tmpdir (void)
|
||||
sys_tmp = TMPDIR_DEFAULT;
|
||||
|
||||
pwd = getpwuid (getuid ());
|
||||
|
||||
if (pwd)
|
||||
if (pwd != NULL)
|
||||
g_snprintf (buffer, sizeof (buffer), "%s/mc-%s", sys_tmp, pwd->pw_name);
|
||||
else
|
||||
g_snprintf (buffer, sizeof (buffer), "%s/mc-%lu", sys_tmp, (unsigned long) getuid ());
|
||||
@ -886,7 +879,7 @@ mc_tmpdir (void)
|
||||
gboolean fallback_ok = FALSE;
|
||||
vfs_path_t *test_vpath;
|
||||
|
||||
if (*error)
|
||||
if (*error != '\0')
|
||||
fprintf (stderr, error, buffer);
|
||||
|
||||
/* Test if sys_tmp is suitable for temporary files */
|
||||
@ -924,7 +917,7 @@ mc_tmpdir (void)
|
||||
|
||||
tmpdir = buffer;
|
||||
|
||||
if (!error)
|
||||
if (error == NULL)
|
||||
g_setenv ("MC_TMPDIR", tmpdir, TRUE);
|
||||
|
||||
return tmpdir;
|
||||
|
Loading…
Reference in New Issue
Block a user