Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
6222c3f4
Unverified
Commit
6222c3f4
authored
Oct 18, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: add lxc_find_next_power2()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
e3db0162
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
utils.c
src/lxc/utils.c
+18
-0
utils.h
src/lxc/utils.h
+10
-0
No files found.
src/lxc/utils.c
View file @
6222c3f4
...
@@ -2457,3 +2457,21 @@ int parse_byte_size_string(const char *s, int64_t *converted)
...
@@ -2457,3 +2457,21 @@ int parse_byte_size_string(const char *s, int64_t *converted)
*
converted
=
overflow
;
*
converted
=
overflow
;
return
0
;
return
0
;
}
}
uint64_t
lxc_find_next_power2
(
uint64_t
n
)
{
/* 0 is not valid input. We return 0 to the caller since 0 is not a
* valid power of two.
*/
if
(
n
==
0
)
return
0
;
if
(
!
(
n
&
(
n
-
1
)))
return
n
;
while
(
n
&
(
n
-
1
))
n
=
n
&
(
n
-
1
);
n
=
n
<<
1
;
return
n
;
}
src/lxc/utils.h
View file @
6222c3f4
...
@@ -472,4 +472,14 @@ extern bool lxc_nic_exists(char *nic);
...
@@ -472,4 +472,14 @@ extern bool lxc_nic_exists(char *nic);
extern
int
lxc_make_tmpfile
(
char
*
template
,
bool
rm
);
extern
int
lxc_make_tmpfile
(
char
*
template
,
bool
rm
);
extern
uint64_t
lxc_getpagesize
(
void
);
extern
uint64_t
lxc_getpagesize
(
void
);
/* If n is not a power of 2 this function will return the next power of 2
* greater than that number. Note that this function always returns the *next*
* power of 2 *greater* that number not the *nearest*. For example, passing 1025
* as argument this function will return 2048 although the closest power of 2
* would be 1024.
* If the caller passes in 0 they will receive 0 in return since this is invalid
* input and 0 is not a power of 2.
*/
extern
uint64_t
lxc_find_next_power2
(
uint64_t
n
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment