summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tapset/string.stp12
-rw-r--r--testsuite/systemtap.printf/char1.exp2
-rw-r--r--testsuite/systemtap.printf/char1.stp1
3 files changed, 14 insertions, 1 deletions
diff --git a/tapset/string.stp b/tapset/string.stp
index 2f43aecc..35ee9fa2 100644
--- a/tapset/string.stp
+++ b/tapset/string.stp
@@ -25,6 +25,18 @@ function substr:string(str:string,start:long, length:long) %{ /* pure */
strlcpy(THIS->__retvalue, THIS->str + THIS->start, length);
%}
+/** @addtogroup library
+* @code function stringat:string(str:string, pos:long) @endcode
+* @param str string
+* @param pos the given position. 0 = start of the string
+* @return Returns the char in given position of string.
+*/
+function stringat:long(str:string, pos:long) %{ /* pure */
+ if (THIS->pos >= 0 && THIS->pos < strlen(THIS->str))
+ THIS->__retvalue = THIS->str[THIS->pos];
+ else
+ THIS->__retvalue = 0;
+%}
/** @addtogroup library
* @code isinstr:long(s1:string,s2:string) @endcode
diff --git a/testsuite/systemtap.printf/char1.exp b/testsuite/systemtap.printf/char1.exp
index 35aa479f..f9343c0e 100644
--- a/testsuite/systemtap.printf/char1.exp
+++ b/testsuite/systemtap.printf/char1.exp
@@ -1,3 +1,3 @@
set test "char1"
-set ::result_string {stap}
+set ::result_string {stapok}
stap_run2 $srcdir/$subdir/$test.stp
diff --git a/testsuite/systemtap.printf/char1.stp b/testsuite/systemtap.printf/char1.stp
index 207d1bc5..564c416b 100644
--- a/testsuite/systemtap.printf/char1.stp
+++ b/testsuite/systemtap.printf/char1.stp
@@ -3,6 +3,7 @@ probe begin
printf("%c", 115)
printf("%c", 116)
printf("%c%c", 97, 112)
+ printf("%c%c", stringat("ok", 0), stringat("ok", 1))
print("\n")
exit()
}