From ee867dbeb2a5cb8ee6f796b812d0edf95e170344 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 13 Aug 2004 21:22:59 +0000 Subject: [PATCH] Implement class template for automatic casting uint64_t to stat packet fields git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1523 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/findlib/attribs.c | 43 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index aad35e1d08..ea8f09e1aa 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -150,60 +150,69 @@ void encode_stat(char *buf, FF_PKT *ff_pkt, int data_stream) } +/* Do casting according to unknown type to keep compiler happy */ +class castit { +public: + template void plug(T &st, uint64_t val) + { st = (T)val; } +}; + /* Decode a stat packet from base64 characters */ int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI) { char *p = buf; int64_t val; + castit plugger; + p += from_base64(&val, p); - statp->st_dev = val; - p++; /* skip space */ + plugger.plug(statp->st_dev, val); + p++; p += from_base64(&val, p); - statp->st_ino = val; + plugger.plug(statp->st_ino, val); p++; p += from_base64(&val, p); - statp->st_mode = val; + plugger.plug(statp->st_mode, val); p++; p += from_base64(&val, p); - statp->st_nlink = val; + plugger.plug(statp->st_nlink, val); p++; p += from_base64(&val, p); - statp->st_uid = val; + plugger.plug(statp->st_uid, val); p++; p += from_base64(&val, p); - statp->st_gid = val; + plugger.plug(statp->st_gid, val); p++; p += from_base64(&val, p); - statp->st_rdev = val; + plugger.plug(statp->st_rdev, val); p++; p += from_base64(&val, p); - statp->st_size = val; + plugger.plug(statp->st_size, val); p++; #ifndef HAVE_MINGW p += from_base64(&val, p); - statp->st_blksize = val; + plugger.plug(statp->st_blksize, val); p++; p += from_base64(&val, p); - statp->st_blocks = val; + plugger.plug(statp->st_blocks, val); p++; #else p += from_base64(&val, p); -// statp->st_blksize = val; +// plugger.plug(statp->st_blksize, val); p++; p += from_base64(&val, p); -// statp->st_blocks = val; +// plugger.plug(statp->st_blocks, val); p++; #endif p += from_base64(&val, p); - statp->st_atime = val; + plugger.plug(statp->st_atime, val); p++; p += from_base64(&val, p); - statp->st_mtime = val; + plugger.plug(statp->st_mtime, val); p++; p += from_base64(&val, p); - statp->st_ctime = val; + plugger.plug(statp->st_ctime, val); /* Optional FileIndex of hard linked file data */ if (*p == ' ' || (*p != 0 && *(p+1) == ' ')) { @@ -220,7 +229,7 @@ int decode_stat(char *buf, struct stat *statp, int32_t *LinkFI) p++; p += from_base64(&val, p); #ifdef HAVE_CHFLAGS - statp->st_flags = (uint32_t)val; + plugger.plug(statp->st_flags, val); } else { statp->st_flags = 0; #endif -- 2.39.5