summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2005-10-15 09:32:04 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:44:46 -0500
commita8504e1061d248a54be93716ead545b2f066f2cf (patch)
treeba86920b85b821260b81b75a2718639dbccb62e7 /source4/scripting
parent5f6a3213e254a9ef178fc756b72badd5823811b2 (diff)
downloadsamba-a8504e1061d248a54be93716ead545b2f066f2cf.tar.gz
samba-a8504e1061d248a54be93716ead545b2f066f2cf.tar.bz2
samba-a8504e1061d248a54be93716ead545b2f066f2cf.zip
r11085: as ejs doesn't support '&' '|' bitwise AND and OR,
we need some helper functions for this metze (This used to be commit e27e36909d367748fc653ddc0fd1c699b77780e9)
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/ejs/smbcalls_sys.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c
index 340671cf0b..5f6a756f8f 100644
--- a/source4/scripting/ejs/smbcalls_sys.c
+++ b/source4/scripting/ejs/smbcalls_sys.c
@@ -257,6 +257,51 @@ static int ejs_sys_lstat(MprVarHandle eid, int argc, char **argv)
return 0;
}
+/*
+ bitwise AND
+ usage:
+ var z = sys.bitAND(x, 0x70);
+*/
+static int ejs_sys_bitAND(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ int x, y, z;
+
+ if (argc != 2 ||
+ !mprVarIsNumber(argv[0]->type) ||
+ !mprVarIsNumber(argv[1]->type)) {
+ ejsSetErrorMsg(eid, "bitand invalid arguments");
+ return -1;
+ }
+ x = mprToInt(argv[0]);
+ y = mprToInt(argv[1]);
+ z = x & y;
+
+ mpr_Return(eid, mprCreateIntegerVar(z));
+ return 0;
+}
+
+/*
+ bitwise OR
+ usage:
+ var z = sys.bitOR(x, 0x70);
+*/
+static int ejs_sys_bitOR(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ int x, y, z;
+
+ if (argc != 2 ||
+ !mprVarIsNumber(argv[0]->type) ||
+ !mprVarIsNumber(argv[1]->type)) {
+ ejsSetErrorMsg(eid, "bitand invalid arguments");
+ return -1;
+ }
+ x = mprToInt(argv[0]);
+ y = mprToInt(argv[1]);
+ z = x | y;
+
+ mpr_Return(eid, mprCreateIntegerVar(z));
+ return 0;
+}
/*
initialise sys ejs subsystem
@@ -276,6 +321,8 @@ static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv)
mprSetStringCFunction(obj, "file_save", ejs_sys_file_save);
mprSetStringCFunction(obj, "stat", ejs_sys_stat);
mprSetStringCFunction(obj, "lstat", ejs_sys_lstat);
+ mprSetCFunction(obj, "bitAND", ejs_sys_bitAND);
+ mprSetCFunction(obj, "bitOR", ejs_sys_bitOR);
return 0;
}