]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: sis - Use container_of() instead of casts
authorJosef 'Jeff' Sipek <jeff.sipek@open-xchange.com>
Tue, 21 Jul 2020 17:18:41 +0000 (13:18 -0400)
committerjeff.sipek <jeff.sipek@open-xchange.com>
Tue, 4 Aug 2020 22:11:58 +0000 (22:11 +0000)
Being more explicit not only makes the code more explict, it makes it safer.

src/lib-fs/fs-sis.c

index 0a6ee82ff7e5655795ec5b98948a0c4a7526d8a0..b3176a7603e5b26b5d36ef5701ec37ff847e08c7 100644 (file)
@@ -27,6 +27,9 @@ struct sis_fs_file {
        bool opened;
 };
 
+#define SIS_FS(ptr)    container_of((ptr), struct sis_fs, fs)
+#define SIS_FILE(ptr)  container_of((ptr), struct sis_fs_file, file)
+
 static struct fs *fs_sis_alloc(void)
 {
        struct sis_fs *fs;
@@ -69,7 +72,7 @@ fs_sis_init(struct fs *_fs, const char *args, const struct fs_settings *set,
 
 static void fs_sis_free(struct fs *_fs)
 {
-       struct sis_fs *fs = (struct sis_fs *)_fs;
+       struct sis_fs *fs = SIS_FS(_fs);
 
        fs_deinit(&_fs->parent);
        i_free(fs);
@@ -85,8 +88,8 @@ static void
 fs_sis_file_init(struct fs_file *_file, const char *path,
                 enum fs_open_mode mode, enum fs_open_flags flags)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
-       struct sis_fs *fs = (struct sis_fs *)_file->fs;
+       struct sis_fs_file *file = SIS_FILE(_file);
+       struct sis_fs *fs = SIS_FS(_file->fs);
        const char *dir, *hash;
 
        file->file.path = i_strdup(path);
@@ -120,7 +123,7 @@ fs_sis_file_init(struct fs_file *_file, const char *path,
 
 static void fs_sis_file_deinit(struct fs_file *_file)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
+       struct sis_fs_file *file = SIS_FILE(_file);
 
        fs_file_deinit(&file->hash_file);
        fs_file_free(_file);
@@ -132,7 +135,7 @@ static void fs_sis_file_deinit(struct fs_file *_file)
 
 static void fs_sis_file_close(struct fs_file *_file)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
+       struct sis_fs_file *file = SIS_FILE(_file);
 
        i_stream_unref(&file->hash_input);
        fs_file_close(file->hash_file);
@@ -244,7 +247,7 @@ static void fs_sis_replace_hash_file(struct sis_fs_file *file)
 
 static int fs_sis_write(struct fs_file *_file, const void *data, size_t size)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
+       struct sis_fs_file *file = SIS_FILE(_file);
 
        if (_file->parent == NULL)
                return -1;
@@ -267,7 +270,7 @@ static int fs_sis_write(struct fs_file *_file, const void *data, size_t size)
 
 static void fs_sis_write_stream(struct fs_file *_file)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
+       struct sis_fs_file *file = SIS_FILE(_file);
 
        i_assert(_file->output == NULL);
 
@@ -290,7 +293,7 @@ static void fs_sis_write_stream(struct fs_file *_file)
 
 static int fs_sis_write_stream_finish(struct fs_file *_file, bool success)
 {
-       struct sis_fs_file *file = (struct sis_fs_file *)_file;
+       struct sis_fs_file *file = SIS_FILE(_file);
 
        if (!success) {
                if (_file->parent != NULL)