summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2006-08-21 17:03:12 +0000
committerhunt <hunt>2006-08-21 17:03:12 +0000
commitb66cd46f5b5a5e7e9fd7fe841239f271f3e4420e (patch)
tree68829846301a4e7e000d1633b308faf6b065b800
parentfc98aa95b304065ebbf8beb77699d7b686591259 (diff)
downloadsystemtap-steved-b66cd46f5b5a5e7e9fd7fe841239f271f3e4420e.tar.gz
systemtap-steved-b66cd46f5b5a5e7e9fd7fe841239f271f3e4420e.tar.xz
systemtap-steved-b66cd46f5b5a5e7e9fd7fe841239f271f3e4420e.zip
2006-08-21 Martin Hunt <hunt@redhat.com>
* string.stp (substr): Rewrite. Make the 3rd parameter be the length.
-rw-r--r--tapset/ChangeLog5
-rw-r--r--tapset/string.stp27
2 files changed, 16 insertions, 16 deletions
diff --git a/tapset/ChangeLog b/tapset/ChangeLog
index 60c08290..0ed7b291 100644
--- a/tapset/ChangeLog
+++ b/tapset/ChangeLog
@@ -1,3 +1,8 @@
+2006-08-21 Martin Hunt <hunt@redhat.com>
+
+ * string.stp (substr): Rewrite. Make the 3rd parameter
+ be the length.
+
2006-08-17 Josh Stone <joshua.i.stone@intel.com>
* signal.stp: Changes on behalf of Manoj S Pattabhiraman:
diff --git a/tapset/string.stp b/tapset/string.stp
index 28f8e2dc..f1666afa 100644
--- a/tapset/string.stp
+++ b/tapset/string.stp
@@ -9,27 +9,22 @@
* @return Returns the length of the string.
*/
function strlen:long(s:string) %{ /* pure */
- THIS->__retvalue=strlen(THIS->s);
+ THIS->__retvalue = strlen(THIS->s);
%}
/** @addtogroup library
-* @code function substr:string(str:string,start:long,stop:long) @endcode
+* @code function substr:string(str:string,start:long,length:long) @endcode
* @param str string
+* @param start Starting position. 0 = start of the string
+* @param length Length of string to return.
* @return Returns the length of the string.
*/
-function substr:string(str:string,start:long,stop:long) %{ /* pure */
- int len=strlen(THIS->str);
- if(THIS->start<0 || THIS->stop<0 ||
- THIS->start>len || THIS->stop>len ||
- THIS->start>=THIS->stop)
- {
+function substr:string(str:string,start:long, length:long) %{ /* pure */
+ int length = THIS->length + 1 > MAXSTRINGLEN ? MAXSTRINGLEN : THIS->length + 1;
+ if (THIS->start < 0 || length < 1) {
return;
- }
- else {
- char *s=THIS->str;
- strncpy(THIS->__retvalue,s+THIS->start,THIS->stop);
- THIS->__retvalue[THIS->stop]='\0';
- }
+ } else
+ strlcpy(THIS->__retvalue, THIS->str + THIS->start, length);
%}
@@ -37,10 +32,10 @@ function substr:string(str:string,start:long,stop:long) %{ /* pure */
* @code isinstr:long(s1:string,s2:string) @endcode
* @param s1 string
* @param s2 string
-* @return Returns 1 if s2 is in s1.
+* @return Returns 1 if s2 is in s1. Otherwise 0.
*/
function isinstr:long(s1:string,s2:string) %{ /* pure */
- if(strstr(THIS->s1,THIS->s2)!=NULL)
+ if (strstr(THIS->s1,THIS->s2) != NULL)
THIS->__retvalue = 1;
else
THIS->__retvalue = 0;