Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
b93982cc
Commit
b93982cc
authored
3 months ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
Add/use BITFIELD macros for defining/using multi-bit bit-fields
parent
f9ad15e8
No related branches found
No related tags found
No related merge requests found
Pipeline
#7417
passed
3 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/smblib/smbdefs.h
+10
-12
10 additions, 12 deletions
src/smblib/smbdefs.h
src/smblib/smblib.c
+17
-10
17 additions, 10 deletions
src/smblib/smblib.c
src/xpdev/gen_defs.h
+6
-0
6 additions, 0 deletions
src/xpdev/gen_defs.h
with
33 additions
and
22 deletions
src/smblib/smbdefs.h
+
10
−
12
View file @
b93982cc
...
...
@@ -368,18 +368,16 @@ typedef struct { /* Time with time-zone */
}
when_t
;
// We encode Month/Day/Hour/Min/Sec into 26 bits:
#define SMB_DATE_MK_MASK(width, shift) (((1 << (width)) - 1) << shift)
#define SMB_DATE_MON_SHIFT 22
#define SMB_DATE_MON_MASK SMB_DATE_MK_MASK(4, SMB_DATE_MON_SHIFT)
#define SMB_DATE_DAY_SHIFT 17
#define SMB_DATE_DAY_MASK SMB_DATE_MK_MASK(5, SMB_DATE_DAY_SHIFT)
#define SMB_DATE_HR_SHIFT 12
#define SMB_DATE_HR_MASK SMB_DATE_MK_MASK(5, SMB_DATE_HR_SHIFT)
#define SMB_DATE_MIN_SHIFT 6
#define SMB_DATE_MIN_MASK SMB_DATE_MK_MASK(6, SMB_DATE_MIN_SHIFT)
#define SMB_DATE_SEC_SHIFT 0
#define SMB_DATE_SEC_MASK SMB_DATE_MK_MASK(6, SMB_DATE_SEC_SHIFT)
#define SMB_DATE_MASK (SMB_DATE_MON_MASK | SMB_DATE_DAY_MASK | SMB_DATE_HR_MASK | SMB_DATE_MIN_MASK | SMB_DATE_SEC_MASK)
#define SMB_DATE_MON_BITWIDTH 4
#define SMB_DATE_MON_BITPOS 22
#define SMB_DATE_DAY_BITWIDTH 5
#define SMB_DATE_DAY_BITPOS 17
#define SMB_DATE_HR_BITWIDTH 5
#define SMB_DATE_HR_BITPOS 12
#define SMB_DATE_MIN_BITWIDTH 6
#define SMB_DATE_MIN_BITPOS 6
#define SMB_DATE_SEC_BITWIDTH 6
#define SMB_DATE_SEC_BITPOS 0
typedef
uint16_t
smb_msg_attr_t
;
...
...
This diff is collapsed.
Click to expand it.
src/smblib/smblib.c
+
17
−
10
View file @
b93982cc
...
...
@@ -2118,6 +2118,13 @@ int smb_tzutc(int16_t zone)
return
(
tz
);
}
#define SMB_DATE_MASK (\
BITFIELD_MASK(SMB_DATE_MON_BITWIDTH, SMB_DATE_MON_BITPOS) | \
BITFIELD_MASK(SMB_DATE_DAY_BITWIDTH, SMB_DATE_DAY_BITPOS) | \
BITFIELD_MASK(SMB_DATE_HR_BITWIDTH, SMB_DATE_HR_BITPOS) | \
BITFIELD_MASK(SMB_DATE_MIN_BITWIDTH, SMB_DATE_MIN_BITPOS) | \
BITFIELD_MASK(SMB_DATE_SEC_BITWIDTH, SMB_DATE_SEC_BITPOS))
/****************************************************************************/
/* Decode the 2 possible encoding of when_t (when_written) */
/****************************************************************************/
...
...
@@ -2129,11 +2136,11 @@ time_t smb_time(when_t when)
return
when
.
time
;
tm
.
tm_year
=
when
.
year
;
tm
.
tm_mon
=
(
when
.
time
&
SMB_DATE_MON_
MASK
)
>>
SMB_DATE_MON_
SHIFT
;
tm
.
tm_mday
=
(
when
.
time
&
SMB_DATE_DAY_
MASK
)
>>
SMB_DATE_DAY_
SHIFT
;
tm
.
tm_hour
=
(
when
.
time
&
SMB_DATE_HR_
MASK
)
>>
SMB_DATE_HR_
SHIFT
;
tm
.
tm_min
=
(
when
.
time
&
SMB_DATE_MIN_
MASK
)
>>
SMB_DATE_MIN_
SHIFT
;
tm
.
tm_sec
=
(
when
.
time
&
SMB_DATE_SEC_
MASK
)
>>
SMB_DATE_SEC_
SHIFT
;
tm
.
tm_mon
=
BITFIELD_DECODE
(
when
.
time
,
SMB_DATE_MON_
BITWIDTH
,
SMB_DATE_MON_
BITPOS
)
;
tm
.
tm_mday
=
BITFIELD_DECODE
(
when
.
time
,
SMB_DATE_DAY_
BITWIDTH
,
SMB_DATE_DAY_
BITPOS
)
;
tm
.
tm_hour
=
BITFIELD_DECODE
(
when
.
time
,
SMB_DATE_HR_
BITWIDTH
,
SMB_DATE_HR_
BITPOS
)
;
tm
.
tm_min
=
BITFIELD_DECODE
(
when
.
time
,
SMB_DATE_MIN_
BITWIDTH
,
SMB_DATE_MIN_
BITPOS
)
;
tm
.
tm_sec
=
BITFIELD_DECODE
(
when
.
time
,
SMB_DATE_SEC_
BITWIDTH
,
SMB_DATE_SEC_
BITPOS
)
;
return
sane_mktime
(
&
tm
);
}
...
...
@@ -2148,11 +2155,11 @@ when_t smb_when(time_t t, int16_t zone)
localtime_r
(
&
t
,
&
tm
);
when
.
year
=
1900
+
tm
.
tm_year
;
when
.
time
=
(
tm
.
tm_mon
+
1
)
<<
SMB_DATE_MON_
SHIFT
;
when
.
time
|=
tm
.
tm_mday
<<
SMB_DATE_DAY_
SHIFT
;
when
.
time
|=
tm
.
tm_hour
<<
SMB_DATE_HR_
SHIFT
;
when
.
time
|=
tm
.
tm_min
<<
SMB_DATE_MIN_
SHIFT
;
when
.
time
|=
tm
.
tm_sec
<<
SMB_DATE_SEC_
SHIFT
;
when
.
time
=
BITFIELD_ENCODE
(
tm
.
tm_mon
+
1
,
SMB_DATE_MON_BITWIDTH
,
SMB_DATE_MON_
BITPOS
)
;
when
.
time
|=
BITFIELD_ENCODE
(
tm
.
tm_mday
,
SMB_DATE_DAY_BITWIDTH
,
SMB_DATE_DAY_
BITPOS
)
;
when
.
time
|=
BITFIELD_ENCODE
(
tm
.
tm_hour
,
SMB_DATE_HR_
BITWIDTH
,
SMB_DATE_HR_BITPOS
)
;
when
.
time
|=
BITFIELD_ENCODE
(
tm
.
tm_min
,
SMB_DATE_MIN_BITWIDTH
,
SMB_DATE_MIN_
BITPOS
)
;
when
.
time
|=
BITFIELD_ENCODE
(
tm
.
tm_sec
,
SMB_DATE_SEC_BITWIDTH
,
SMB_DATE_SEC_
BITPOS
)
;
when
.
zone
=
zone
;
return
when
;
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/gen_defs.h
+
6
−
0
View file @
b93982cc
...
...
@@ -402,6 +402,12 @@ typedef struct {
/* Handy Integer Macros */
/************************/
/* Multi-bit bit-fields with "defined behavior" */
#define BITFIELD_MAX(width) ((1 << (width)) - 1)
#define BITFIELD_MASK(width, pos) (BITFIELD_MAX(width) << (pos))
#define BITFIELD_ENCODE(val, width, pos) (((val) & BITFIELD_MAX(width)) << (pos))
#define BITFIELD_DECODE(val, width, pos) (((val) & BITFIELD_MASK(width, pos)) >> (pos))
/* Data Block Length Alignment Macro (returns required padding length for proper alignment) */
#define PAD_LENGTH_FOR_ALIGNMENT(len,blk) (((len)%(blk))==0 ? 0 : (blk)-((len)%(blk)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment