summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-02-16 18:02:50 +0000
committerLuke Leighton <lkcl@samba.org>1999-02-16 18:02:50 +0000
commit78314c2e327ccd67e75dbc92be497ff2852b1817 (patch)
treef48dab8e76aa4d15912340579aa1c291a7963fa8 /source3/lib
parent2737f26ad64ee32d6ef7365dcce0a3eb881f99db (diff)
downloadsamba-78314c2e327ccd67e75dbc92be497ff2852b1817.tar.gz
samba-78314c2e327ccd67e75dbc92be497ff2852b1817.tar.bz2
samba-78314c2e327ccd67e75dbc92be497ff2852b1817.zip
bitmap to strings
(This used to be commit ba5919bcaefa792bae503c7ab19d4b7bbf9bb954)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_str.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index a55d4cd8dc..31dc9bfd62 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1089,3 +1089,73 @@ void split_at_last_component(char *path, char *front, char sep, char *back)
}
}
}
+
+/****************************************************************************
+convert a bit field to a string. if you want multiple bits to be detected
+set them first, e.g SV_TYPE_ALL to be "All" or "Full Control" for ACB_INFOs.
+
+strings are expected to contain their own separators, although the code
+below only assumes that separators are spaces.
+
+****************************************************************************/
+char *bit_field_to_str(uint32 type, struct field_info *bs)
+{
+ static fstring typestr;
+ int i = 0;
+
+ typestr[0] = 0;
+
+ if (type == 0 || bs == NULL)
+ {
+ return NULL;
+ }
+
+ while (bs[i].str != NULL && type != 0)
+ {
+ if (IS_BITS_SET_ALL(bs[i].bits, type))
+ {
+ fstrcat(typestr, bs[i].str);
+ type &= ~bs[i].bits;
+ }
+ i++;
+ }
+
+ i = strlen(typestr)-1;
+ if (i > 0 && typestr[i] == ' ')
+ {
+ typestr[i] = 0;
+ }
+
+ return typestr;
+}
+
+/****************************************************************************
+convert an enumeration to a string. first item is the default.
+****************************************************************************/
+char *enum_field_to_str(uint32 type, struct field_info *bs, BOOL first_default)
+{
+ int i = 0;
+
+ if (bs == NULL)
+ {
+ return NULL;
+ }
+
+ while (bs[i].str != NULL && type != 0)
+ {
+ if (bs[i].bits == type)
+ {
+ return bs[i].str;
+ }
+ i++;
+ }
+
+ /* oops - none found */
+
+ if (first_default)
+ {
+ return bs[0].str;
+ }
+
+ return NULL;
+}