Adjust initializers of union in erofs-utils to ensure compatibility
with various compilers. The original C99 designated initializer style
was not supported in other compilers (e.g., C++11), leading to build
failures. Additionally, change the codebase to minimize potential
conflicts with headers from other projects.
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240624063217.170251-1-hongzhen@linux.alibaba.com
[ Gao Xiang: minor commit message update. ]
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
#define ST_MTIM_NSEC(stbuf) 0
#endif
-#define likely(x) __builtin_expect(!!(x), 1)
-#define unlikely(x) __builtin_expect(!!(x), 0)
+#define __erofs_likely(x) __builtin_expect(!!(x), 1)
+#define __erofs_unlikely(x) __builtin_expect(!!(x), 0)
#ifdef __cplusplus
}
static inline struct erofs_inode *erofs_parent_inode(struct erofs_inode *inode)
{
- return (void *)((unsigned long)inode->i_parent & ~1UL);
+ return (struct erofs_inode *)((unsigned long)inode->i_parent & ~1UL);
}
#define IS_ROOT(x) ((x) == erofs_parent_inode(x))
struct z_erofs_map_header h;
__le64 v;
} fmh __maybe_unused = {
- .h.h_clusterbits = 1 << Z_EROFS_FRAGMENT_INODE_BIT,
+ .h = {
+ .h_clusterbits = 1 <<Z_EROFS_FRAGMENT_INODE_BIT,
+ },
};
BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
struct erofs_compress_cfg *lc = &tls->ccfg[alg_id];
int ret;
- if (likely(lc->enable))
+ if (__erofs_likely(lc->enable))
return 0;
ret = erofs_compressor_init(sbi, &lc->handle, alg_name,
erofs_dbg("Assign nid %llu to file %s (mode %05o)",
inode->nid, inode->i_srcpath, inode->i_mode);
}
- if (unlikely(IS_ROOT(inode)) && inode->nid > 0xffff)
+ if (__erofs_unlikely(IS_ROOT(inode)) && inode->nid > 0xffff)
return sbi->root_nid;
return inode->nid;
}
int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf)
{
- if (unlikely(cfg.c_dry_run)) {
+ if (__erofs_unlikely(cfg.c_dry_run)) {
buf->st_size = 0;
buf->st_mode = S_IFREG | 0777;
return 0;
{
ssize_t ret, written = 0;
- if (unlikely(cfg.c_dry_run))
+ if (__erofs_unlikely(cfg.c_dry_run))
return 0;
if (vf->ops)
{
int ret;
- if (unlikely(cfg.c_dry_run))
+ if (__erofs_unlikely(cfg.c_dry_run))
return 0;
if (vf->ops)
static const char zero[EROFS_MAX_BLOCK_SIZE] = {0};
ssize_t ret;
- if (unlikely(cfg.c_dry_run))
+ if (__erofs_unlikely(cfg.c_dry_run))
return 0;
if (vf->ops)
int ret;
struct stat st;
- if (unlikely(cfg.c_dry_run))
+ if (__erofs_unlikely(cfg.c_dry_run))
return 0;
if (vf->ops)
{
ssize_t ret, read = 0;
- if (unlikely(cfg.c_dry_run))
+ if (__erofs_unlikely(cfg.c_dry_run))
return 0;
if (vf->ops)
*
* [1] https://github.com/tukaani-project/xz/blob/v5.4.0/src/liblzma/lz/lz_encoder_mf.c#L94
*/
- if (unlikely(mf->base > ((typeof(mf->base))-1) >> 1)) {
+ if (__erofs_unlikely(mf->base > ((typeof(mf->base))-1) >> 1)) {
mf->base = kHistorySize32 + 1;
memset(mf->hash, 0, 0x10000 * sizeof(mf->hash[0]));
}
if (ret < ios->bufsize - rabytes)
ios->feof = true;
}
- if (unlikely(ios->dumpfd >= 0))
+ if (__erofs_unlikely(ios->dumpfd >= 0))
if (write(ios->dumpfd, ios->buffer + rabytes, ret) < ret)
erofs_err("failed to dump %d bytes of the raw stream: %s",
ret, erofs_strerror(-errno));
if (ios->feof)
return sz;
- if (ios->sz && likely(ios->dumpfd < 0)) {
+ if (ios->sz && __erofs_likely(ios->dumpfd < 0)) {
s64 cur = erofs_io_lseek(&ios->vf, sz, SEEK_CUR);
if (cur > ios->sz)