diff options
author | hunt <hunt> | 2006-08-21 17:03:12 +0000 |
---|---|---|
committer | hunt <hunt> | 2006-08-21 17:03:12 +0000 |
commit | b66cd46f5b5a5e7e9fd7fe841239f271f3e4420e (patch) | |
tree | 68829846301a4e7e000d1633b308faf6b065b800 /tapset/string.stp | |
parent | fc98aa95b304065ebbf8beb77699d7b686591259 (diff) | |
download | systemtap-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.
Diffstat (limited to 'tapset/string.stp')
-rw-r--r-- | tapset/string.stp | 27 |
1 files changed, 11 insertions, 16 deletions
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; |