Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
fb549cd5
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fb549cd5
编写于
2月 05, 2018
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util: bitmap: Fix function formatting and spacing
上级
eacc9312
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
83 addition
and
24 deletion
+83
-24
src/util/virbitmap.c
src/util/virbitmap.c
+83
-24
未找到文件。
src/util/virbitmap.c
浏览文件 @
fb549cd5
...
...
@@ -136,7 +136,8 @@ virBitmapNewEmpty(void)
*
* Free @bitmap previously allocated by virBitmapNew.
*/
void
virBitmapFree
(
virBitmapPtr
bitmap
)
void
virBitmapFree
(
virBitmapPtr
bitmap
)
{
if
(
bitmap
)
{
VIR_FREE
(
bitmap
->
map
);
...
...
@@ -145,7 +146,9 @@ void virBitmapFree(virBitmapPtr bitmap)
}
int
virBitmapCopy
(
virBitmapPtr
dst
,
virBitmapPtr
src
)
int
virBitmapCopy
(
virBitmapPtr
dst
,
virBitmapPtr
src
)
{
if
(
dst
->
nbits
!=
src
->
nbits
)
{
errno
=
EINVAL
;
...
...
@@ -167,7 +170,9 @@ int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src)
*
* Returns 0 on if bit is successfully set, -1 on error.
*/
int
virBitmapSetBit
(
virBitmapPtr
bitmap
,
size_t
b
)
int
virBitmapSetBit
(
virBitmapPtr
bitmap
,
size_t
b
)
{
if
(
bitmap
->
nbits
<=
b
)
return
-
1
;
...
...
@@ -176,6 +181,7 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
return
0
;
}
/**
* virBitmapExpand:
* @map: Pointer to bitmap
...
...
@@ -186,7 +192,9 @@ int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
*
* Returns 0 on success, -1 on error.
*/
static
int
virBitmapExpand
(
virBitmapPtr
map
,
size_t
b
)
static
int
virBitmapExpand
(
virBitmapPtr
map
,
size_t
b
)
{
size_t
new_len
=
VIR_DIV_UP
(
b
+
1
,
VIR_BITMAP_BITS_PER_UNIT
);
...
...
@@ -214,7 +222,9 @@ static int virBitmapExpand(virBitmapPtr map, size_t b)
*
* Returns 0 on if bit is successfully set, -1 on error.
*/
int
virBitmapSetBitExpand
(
virBitmapPtr
bitmap
,
size_t
b
)
int
virBitmapSetBitExpand
(
virBitmapPtr
bitmap
,
size_t
b
)
{
if
(
bitmap
->
nbits
<=
b
&&
virBitmapExpand
(
bitmap
,
b
)
<
0
)
return
-
1
;
...
...
@@ -233,7 +243,9 @@ int virBitmapSetBitExpand(virBitmapPtr bitmap, size_t b)
*
* Returns 0 on if bit is successfully clear, -1 on error.
*/
int
virBitmapClearBit
(
virBitmapPtr
bitmap
,
size_t
b
)
int
virBitmapClearBit
(
virBitmapPtr
bitmap
,
size_t
b
)
{
if
(
bitmap
->
nbits
<=
b
)
return
-
1
;
...
...
@@ -253,7 +265,9 @@ int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
*
* Returns 0 on if bit is successfully cleared, -1 on error.
*/
int
virBitmapClearBitExpand
(
virBitmapPtr
bitmap
,
size_t
b
)
int
virBitmapClearBitExpand
(
virBitmapPtr
bitmap
,
size_t
b
)
{
if
(
bitmap
->
nbits
<=
b
)
{
if
(
virBitmapExpand
(
bitmap
,
b
)
<
0
)
...
...
@@ -267,11 +281,13 @@ int virBitmapClearBitExpand(virBitmapPtr bitmap, size_t b)
/* Helper function. caller must ensure b < bitmap->nbits */
static
bool
virBitmapIsSet
(
virBitmapPtr
bitmap
,
size_t
b
)
static
bool
virBitmapIsSet
(
virBitmapPtr
bitmap
,
size_t
b
)
{
return
!!
(
bitmap
->
map
[
VIR_BITMAP_UNIT_OFFSET
(
b
)]
&
VIR_BITMAP_BIT
(
b
));
}
/**
* virBitmapIsBitSet:
* @bitmap: Pointer to bitmap
...
...
@@ -282,7 +298,9 @@ static bool virBitmapIsSet(virBitmapPtr bitmap, size_t b)
* If @b is in the range of @bitmap, returns the value of the bit.
* Otherwise false is returned.
*/
bool
virBitmapIsBitSet
(
virBitmapPtr
bitmap
,
size_t
b
)
bool
virBitmapIsBitSet
(
virBitmapPtr
bitmap
,
size_t
b
)
{
if
(
bitmap
->
nbits
<=
b
)
return
false
;
...
...
@@ -290,6 +308,7 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
return
virBitmapIsSet
(
bitmap
,
b
);
}
/**
* virBitmapGetBit:
* @bitmap: Pointer to bitmap
...
...
@@ -301,7 +320,10 @@ bool virBitmapIsBitSet(virBitmapPtr bitmap, size_t b)
* On success, @result will contain the setting of @b and 0 is
* returned. On failure, -1 is returned and @result is unchanged.
*/
int
virBitmapGetBit
(
virBitmapPtr
bitmap
,
size_t
b
,
bool
*
result
)
int
virBitmapGetBit
(
virBitmapPtr
bitmap
,
size_t
b
,
bool
*
result
)
{
if
(
bitmap
->
nbits
<=
b
)
return
-
1
;
...
...
@@ -310,6 +332,7 @@ int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
return
0
;
}
/**
* virBitmapToString:
* @bitmap: Pointer to bitmap
...
...
@@ -367,6 +390,7 @@ virBitmapToString(virBitmapPtr bitmap,
return
ret
;
}
/**
* virBitmapFormat:
* @bitmap: the bitmap
...
...
@@ -381,7 +405,8 @@ virBitmapToString(virBitmapPtr bitmap,
* Returns the string on success or NULL otherwise. Caller should call
* VIR_FREE to free the string.
*/
char
*
virBitmapFormat
(
virBitmapPtr
bitmap
)
char
*
virBitmapFormat
(
virBitmapPtr
bitmap
)
{
virBuffer
buf
=
VIR_BUFFER_INITIALIZER
;
bool
first
=
true
;
...
...
@@ -426,6 +451,7 @@ char *virBitmapFormat(virBitmapPtr bitmap)
return
virBufferContentAndReset
(
&
buf
);
}
/**
* virBitmapParseSeparator:
* @str: points to a string representing a human-readable bitmap
...
...
@@ -546,6 +572,7 @@ virBitmapParseSeparator(const char *str,
return
-
1
;
}
/**
* virBitmapParse:
* @str: points to a string representing a human-readable bitmap
...
...
@@ -569,6 +596,7 @@ virBitmapParse(const char *str,
return
virBitmapParseSeparator
(
str
,
'\0'
,
bitmap
,
bitmapSize
);
}
/**
* virBitmapParseUnlimited:
* @str: points to a string representing a human-readable bitmap
...
...
@@ -679,6 +707,7 @@ virBitmapParseUnlimited(const char *str)
return
NULL
;
}
/**
* virBitmapNewCopy:
* @src: the source bitmap.
...
...
@@ -688,7 +717,8 @@ virBitmapParseUnlimited(const char *str)
* returns the copied bitmap on success, or NULL otherwise. Caller
* should call virBitmapFree to free the returned bitmap.
*/
virBitmapPtr
virBitmapNewCopy
(
virBitmapPtr
src
)
virBitmapPtr
virBitmapNewCopy
(
virBitmapPtr
src
)
{
virBitmapPtr
dst
;
...
...
@@ -703,6 +733,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src)
return
dst
;
}
/**
* virBitmapNewData:
* @data: the data
...
...
@@ -714,7 +745,9 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src)
* Returns a pointer to the allocated bitmap or NULL if
* memory cannot be allocated.
*/
virBitmapPtr
virBitmapNewData
(
const
void
*
data
,
int
len
)
virBitmapPtr
virBitmapNewData
(
const
void
*
data
,
int
len
)
{
virBitmapPtr
bitmap
;
size_t
i
,
j
;
...
...
@@ -738,6 +771,7 @@ virBitmapPtr virBitmapNewData(const void *data, int len)
return
bitmap
;
}
/**
* virBitmapToData:
* @data: the data
...
...
@@ -749,7 +783,10 @@ virBitmapPtr virBitmapNewData(const void *data, int len)
*
* Returns 0 on success, -1 otherwise.
*/
int
virBitmapToData
(
virBitmapPtr
bitmap
,
unsigned
char
**
data
,
int
*
dataLen
)
int
virBitmapToData
(
virBitmapPtr
bitmap
,
unsigned
char
**
data
,
int
*
dataLen
)
{
ssize_t
len
;
...
...
@@ -768,6 +805,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
return
0
;
}
/**
* virBitmapToDataBuf:
* @bytes: pointer to memory to fill
...
...
@@ -777,7 +815,8 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
* Data consists of sequential bytes, with lower bytes containing
* lower bits.
*/
void
virBitmapToDataBuf
(
virBitmapPtr
bitmap
,
void
virBitmapToDataBuf
(
virBitmapPtr
bitmap
,
unsigned
char
*
bytes
,
size_t
len
)
{
...
...
@@ -797,6 +836,7 @@ void virBitmapToDataBuf(virBitmapPtr bitmap,
}
}
/**
* virBitmapEqual:
* @b1: bitmap 1
...
...
@@ -807,7 +847,9 @@ void virBitmapToDataBuf(virBitmapPtr bitmap,
* Returns true if two bitmaps have exactly the same set of bits set,
* otherwise false.
*/
bool
virBitmapEqual
(
virBitmapPtr
b1
,
virBitmapPtr
b2
)
bool
virBitmapEqual
(
virBitmapPtr
b1
,
virBitmapPtr
b2
)
{
virBitmapPtr
tmp
;
size_t
i
;
...
...
@@ -839,11 +881,14 @@ bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2)
return
true
;
}
size_t
virBitmapSize
(
virBitmapPtr
bitmap
)
size_t
virBitmapSize
(
virBitmapPtr
bitmap
)
{
return
bitmap
->
nbits
;
}
/**
* virBitmapSetAll:
* @bitmap: the bitmap
...
...
@@ -863,25 +908,29 @@ void virBitmapSetAll(virBitmapPtr bitmap)
-
1UL
>>
(
VIR_BITMAP_BITS_PER_UNIT
-
tail
);
}
/**
* virBitmapClearAll:
* @bitmap: the bitmap
*
* clear all bits in @bitmap.
*/
void
virBitmapClearAll
(
virBitmapPtr
bitmap
)
void
virBitmapClearAll
(
virBitmapPtr
bitmap
)
{
memset
(
bitmap
->
map
,
0
,
bitmap
->
map_len
*
(
VIR_BITMAP_BITS_PER_UNIT
/
CHAR_BIT
));
}
/**
* virBitmapIsAllSet:
* @bitmap: the bitmap to check
*
* check if all bits in @bitmap are set.
*/
bool
virBitmapIsAllSet
(
virBitmapPtr
bitmap
)
bool
virBitmapIsAllSet
(
virBitmapPtr
bitmap
)
{
size_t
i
;
int
unusedBits
;
...
...
@@ -906,13 +955,15 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap)
return
true
;
}
/**
* virBitmapIsAllClear:
* @bitmap: the bitmap to check
*
* check if all bits in @bitmap are clear
*/
bool
virBitmapIsAllClear
(
virBitmapPtr
bitmap
)
bool
virBitmapIsAllClear
(
virBitmapPtr
bitmap
)
{
size_t
i
;
...
...
@@ -923,6 +974,7 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap)
return
true
;
}
/**
* virBitmapNextSetBit:
* @bitmap: the bitmap
...
...
@@ -935,7 +987,8 @@ bool virBitmapIsAllClear(virBitmapPtr bitmap)
* Returns the position of the found bit, or -1 if no bit found.
*/
ssize_t
virBitmapNextSetBit
(
virBitmapPtr
bitmap
,
ssize_t
pos
)
virBitmapNextSetBit
(
virBitmapPtr
bitmap
,
ssize_t
pos
)
{
size_t
nl
;
size_t
nb
;
...
...
@@ -963,6 +1016,7 @@ virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos)
return
ffsl
(
bits
)
-
1
+
nl
*
VIR_BITMAP_BITS_PER_UNIT
;
}
/**
* virBitmapLastSetBit:
* @bitmap: the bitmap
...
...
@@ -1012,6 +1066,7 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
return
-
1
;
}
/**
* virBitmapNextClearBit:
* @bitmap: the bitmap
...
...
@@ -1024,7 +1079,8 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
* Returns the position of the found bit, or -1 if no bit found.
*/
ssize_t
virBitmapNextClearBit
(
virBitmapPtr
bitmap
,
ssize_t
pos
)
virBitmapNextClearBit
(
virBitmapPtr
bitmap
,
ssize_t
pos
)
{
size_t
nl
;
size_t
nb
;
...
...
@@ -1059,6 +1115,7 @@ virBitmapNextClearBit(virBitmapPtr bitmap, ssize_t pos)
return
ffsl
(
bits
)
-
1
+
nl
*
VIR_BITMAP_BITS_PER_UNIT
;
}
/* Return the number of bits currently set in the map. */
size_t
virBitmapCountBits
(
virBitmapPtr
bitmap
)
...
...
@@ -1134,6 +1191,7 @@ virBitmapDataFormat(const void *data,
return
ret
;
}
bool
virBitmapOverlaps
(
virBitmapPtr
b1
,
virBitmapPtr
b2
)
...
...
@@ -1154,6 +1212,7 @@ virBitmapOverlaps(virBitmapPtr b1,
return
false
;
}
/**
* virBitmapIntersect:
* @a: bitmap, modified to contain result
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录