1
1
Avoid some else branches. Type accuracy.

Thanks Vit Rosin for original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2010-03-31 13:07:39 +04:00
родитель e70db42deb
Коммит 933aba001d

Просмотреть файл

@ -559,44 +559,42 @@ ferrno (struct vfs_class *vfs)
int
mc_open (const char *filename, int flags, ...)
{
int mode;
int mode = 0;
void *info;
va_list ap;
char *file;
struct vfs_class *vfs;
char *file = vfs_canon_and_translate (filename);
if (file != NULL)
{
struct vfs_class *vfs = vfs_get_class (file);
/* Get the mode flag */
if (flags & O_CREAT)
{
va_start (ap, flags);
mode = va_arg (ap, int);
va_end (ap);
}
else
mode = 0;
if (!vfs->open)
{
g_free (file);
errno = -EOPNOTSUPP;
return -1;
}
info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
g_free (file);
if (!info)
{
errno = ferrno (vfs);
return -1;
}
return vfs_new_handle (vfs, info);
}
else
file = vfs_canon_and_translate (filename);
if (file == NULL)
return -1;
vfs = vfs_get_class (file);
/* Get the mode flag */
if (flags & O_CREAT)
{
va_start (ap, flags);
mode = va_arg (ap, int);
va_end (ap);
}
if (vfs->open == NULL)
{
g_free (file);
errno = -EOPNOTSUPP;
return -1;
}
info = vfs->open (vfs, file, flags, mode); /* open must be supported */
g_free (file);
if (info == NULL)
{
errno = ferrno (vfs);
return -1;
}
return vfs_new_handle (vfs, info);
}
@ -606,18 +604,18 @@ int mc_##name inarg \
struct vfs_class *vfs; \
int result; \
char *mpath = vfs_canon_and_translate (path); \
if (mpath != NULL) { \
if (mpath == NULL) \
return -1; \
vfs = vfs_get_class (mpath); \
if (vfs == NULL){ \
g_free (mpath); \
return -1; \
} \
result = vfs->name ? (*vfs->name)callarg : -1; \
result = vfs->name != NULL ? vfs->name callarg : -1; \
g_free (mpath); \
if (result == -1) \
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
return result; \
} else return -1; \
}
MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode))
@ -628,7 +626,9 @@ MC_NAMEOP (unlink, (const char *path), (vfs, mpath))
MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vfs, mpath, mode))
MC_NAMEOP (rmdir, (const char *path), (vfs, mpath))
MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode, dev))
int mc_symlink (const char *name1, const char *path)
int
mc_symlink (const char *name1, const char *path)
{
struct vfs_class *vfs;
int result;
@ -637,25 +637,27 @@ MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode,
char *tmp;
mpath = vfs_canon_and_translate (path);
if (mpath != NULL)
if (mpath == NULL)
return -1;
tmp = g_strdup (name1);
lpath = vfs_translate_path_n (tmp);
g_free (tmp);
if (lpath != NULL)
{
tmp = g_strdup (name1);
lpath = vfs_translate_path_n (tmp);
g_free (tmp);
if (lpath != NULL)
{
vfs = vfs_get_class (mpath);
result = vfs->symlink ? (*vfs->symlink) (vfs, lpath, mpath) : -1;
g_free (lpath);
g_free (mpath);
if (result == -1)
errno = vfs->symlink ? ferrno (vfs) : E_NOTSUPP;
return result;
}
vfs = vfs_get_class (mpath);
result = vfs->symlink != NULL ? vfs->symlink (vfs, lpath, mpath) : -1;
g_free (lpath);
g_free (mpath);
if (result == -1)
errno = vfs->symlink != NULL ? ferrno (vfs) : E_NOTSUPP;
return result;
}
g_free (mpath);
return -1;
}
@ -665,18 +667,19 @@ ssize_t mc_##name inarg \
struct vfs_class *vfs; \
int result; \
if (handle == -1) \
return -1; \
return -1; \
vfs = vfs_op (handle); \
if (vfs == NULL) \
return -1; \
result = vfs->name ? (*vfs->name)callarg : -1; \
return -1; \
result = vfs->name != NULL ? vfs->name callarg : -1; \
if (result == -1) \
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
return result; \
}
MC_HANDLEOP (read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count))
MC_HANDLEOP (write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
#define MC_RENAMEOP(name) \
int mc_##name (const char *fname1, const char *fname2) \
{ \
@ -684,31 +687,33 @@ int mc_##name (const char *fname1, const char *fname2) \
int result; \
char *name2, *name1; \
name1 = vfs_canon_and_translate (fname1); \
if (name1 != NULL) { \
name2 = vfs_canon_and_translate (fname2); \
if (name2 != NULL) { \
vfs = vfs_get_class (name1); \
if (vfs != vfs_get_class (name2)){ \
errno = EXDEV; \
g_free (name1); \
g_free (name2); \
return -1; \
} \
result = vfs->name ? (*vfs->name)(vfs, name1, name2) : -1; \
g_free (name1); \
g_free (name2); \
if (result == -1) \
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
return result; \
} else { \
if (name1 == NULL) \
return -1; \
name2 = vfs_canon_and_translate (fname2); \
if (name2 == NULL) { \
g_free (name1); \
return -1; \
} \
} else return -1; \
vfs = vfs_get_class (name1); \
if (vfs != vfs_get_class (name2)) \
{ \
errno = EXDEV; \
g_free (name1); \
g_free (name2); \
return -1; \
} \
result = vfs->name != NULL ? vfs->name (vfs, name1, name2) : -1; \
g_free (name1); \
g_free (name2); \
if (result == -1) \
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
return result; \
}
MC_RENAMEOP (link) MC_RENAMEOP (rename)
int
mc_ctl (int handle, int ctlop, void *arg)
MC_RENAMEOP (link) MC_RENAMEOP (rename)
int
mc_ctl (int handle, int ctlop, void *arg)
{
struct vfs_class *vfs = vfs_op (handle);
@ -722,22 +727,21 @@ int
mc_setctl (const char *path, int ctlop, void *arg)
{
struct vfs_class *vfs;
int result;
int result = -1;
char *mpath;
if (!path)
if (path == NULL)
vfs_die ("You don't want to pass NULL to mc_setctl.");
mpath = vfs_canon_and_translate (path);
if (mpath != NULL)
{
vfs = vfs_get_class (mpath);
result = vfs->setctl ? (*vfs->setctl) (vfs, mpath, ctlop, arg) : 0;
result = vfs->setctl != NULL ? vfs->setctl (vfs, mpath, ctlop, arg) : 0;
g_free (mpath);
return result;
}
else
return -1;
return result;
}
int
@ -1187,14 +1191,12 @@ vfs_file_class_flags (const char *filename)
char *fname;
fname = vfs_canon_and_translate (filename);
if (fname != NULL)
{
vfs = vfs_get_class (fname);
g_free (fname);
return vfs->flags;
}
else
if (fname == NULL)
return -1;
vfs = vfs_get_class (fname);
g_free (fname);
return vfs->flags;
}
static char *
@ -1232,9 +1234,8 @@ mc_def_getlocalcopy (const char *filename)
}
if (mc_stat (filename, &mystat) != -1)
{
chmod (tmp, mystat.st_mode);
}
return tmp;
fail:
@ -1249,7 +1250,7 @@ mc_def_getlocalcopy (const char *filename)
char *
mc_getlocalcopy (const char *pathname)
{
char *result;
char *result = NULL;
char *path;
path = vfs_canon_and_translate (pathname);
@ -1257,14 +1258,15 @@ mc_getlocalcopy (const char *pathname)
{
struct vfs_class *vfs = vfs_get_class (path);
result = vfs->getlocalcopy ? (*vfs->getlocalcopy) (vfs, path) : mc_def_getlocalcopy (path);
result = vfs->getlocalcopy != NULL ?
vfs->getlocalcopy (vfs, path) :
mc_def_getlocalcopy (path);
g_free (path);
if (!result)
if (result == NULL)
errno = ferrno (vfs);
return result;
}
else
return NULL;
return result;
}
static int
@ -1321,22 +1323,21 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
int
mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
{
int return_value = 0;
int return_value = -1;
char *path;
path = vfs_canon_and_translate (pathname);
if (path != NULL)
if (path == NULL)
{
struct vfs_class *vfs = vfs_get_class (path);
return_value = vfs->ungetlocalcopy ?
(*vfs->ungetlocalcopy) (vfs, path, local, has_changed) :
return_value = vfs->ungetlocalcopy != NULL ?
vfs->ungetlocalcopy (vfs, path, local, has_changed) :
mc_def_ungetlocalcopy (vfs, path, local, has_changed);
g_free (path);
return return_value;
}
else
return -1;
return return_value;
}