Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
47605e1d
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47605e1d
编写于
6月 24, 2008
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added helpers for dealing with enumerations
上级
313f1a7c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
0 deletion
+55
-0
ChangeLog
ChangeLog
+5
-0
src/util.c
src/util.c
+22
-0
src/util.h
src/util.h
+28
-0
未找到文件。
ChangeLog
浏览文件 @
47605e1d
Tue Jun 24 15:59:33 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/util.h, src/util.c: Added helpers for managing enumerations
and conversion to/from string vs integer format
Tue Jun 24 15:29:33 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/storage_backend.h, src/storage_backend.c: Fix const-ness
...
...
src/util.c
浏览文件 @
47605e1d
...
...
@@ -764,6 +764,28 @@ virParseMacAddr(const char* str, unsigned char *addr)
return
-
1
;
}
int
virEnumFromString
(
const
char
*
const
*
types
,
unsigned
int
ntypes
,
const
char
*
type
)
{
unsigned
int
i
;
for
(
i
=
0
;
i
<
ntypes
;
i
++
)
if
(
STREQ
(
types
[
i
],
type
))
return
i
;
return
-
1
;
}
const
char
*
virEnumToString
(
const
char
*
const
*
types
,
unsigned
int
ntypes
,
int
type
)
{
if
(
type
<
0
||
type
>=
ntypes
)
return
NULL
;
return
types
[
type
];
}
/* Translates a device name of the form (regex) "[fhv]d[a-z]+" into
* the corresponding index (e.g. sda => 1, hdz => 26, vdaa => 27)
* @param name The name of the device
...
...
src/util.h
浏览文件 @
47605e1d
...
...
@@ -25,6 +25,7 @@
#define __VIR_UTIL_H__
#include "util-lib.h"
#include "verify.h"
int
virExec
(
virConnectPtr
conn
,
char
**
argv
,
int
*
retpid
,
int
infd
,
int
*
outfd
,
int
*
errfd
);
...
...
@@ -88,4 +89,31 @@ int virParseMacAddr(const char* str, unsigned char *addr);
int
virDiskNameToIndex
(
const
char
*
str
);
int
virEnumFromString
(
const
char
*
const
*
types
,
unsigned
int
ntypes
,
const
char
*
type
);
const
char
*
virEnumToString
(
const
char
*
const
*
types
,
unsigned
int
ntypes
,
int
type
);
#define VIR_ENUM_IMPL(name, lastVal, ...) \
static const char const *name ## TypeList[] = { __VA_ARGS__ }; \
verify(ARRAY_CARDINALITY(name ## TypeList) == lastVal); \
const char *name ## TypeToString(int type) { \
return virEnumToString(name ## TypeList, \
ARRAY_CARDINALITY(name ## TypeList), \
type); \
} \
int name ## TypeFromString(const char *type) { \
return virEnumFromString(name ## TypeList, \
ARRAY_CARDINALITY(name ## TypeList), \
type); \
}
#define VIR_ENUM_DECL(name) \
const char *name ## TypeToString(int type); \
int name ## TypeFromString(const char*type);
#endif
/* __VIR_UTIL_H__ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录