Repository: Konstantin8105/c4go
Pull request #280 (2019-02-24 17:49:43)

CSTD: string.h: strrchr

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=h1) Report
> Merging [#280](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/982f5b9b08c78cca7eac03115fdc5da29dd38eb8?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `90.9%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/280/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   86.88%   86.89%   +<.01%     
==========================================
  Files         180      180              
  Lines        9829     9840      +11     
==========================================
+ Hits         8540     8550      +10     
- Misses        890      891       +1     
  Partials      399      399
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [program/definition\_function.go](https://codecov.io/gh/Konstantin8105/c4go/pull/280/diff?src=pr&el=tree#diff-cHJvZ3JhbS9kZWZpbml0aW9uX2Z1bmN0aW9uLmdv) | `89.53% <ø> (ø)` | :arrow_up: |
| [noarch/string.go](https://codecov.io/gh/Konstantin8105/c4go/pull/280/diff?src=pr&el=tree#diff-bm9hcmNoL3N0cmluZy5nbw==) | `92.59% <90.9%> (-0.27%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=footer). Last update [982f5b9...37d4a26](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=h1) Report
> Merging [#280](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/982f5b9b08c78cca7eac03115fdc5da29dd38eb8?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `90.9%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/280/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #280      +/-   ##
==========================================
+ Coverage   86.88%   86.89%   +<.01%     
==========================================
  Files         180      180              
  Lines        9829     9840      +11     
==========================================
+ Hits         8540     8550      +10     
- Misses        890      891       +1     
  Partials      399      399
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [program/definition\_function.go](https://codecov.io/gh/Konstantin8105/c4go/pull/280/diff?src=pr&el=tree#diff-cHJvZ3JhbS9kZWZpbml0aW9uX2Z1bmN0aW9uLmdv) | `89.53% <ø> (ø)` | :arrow_up: |
| [noarch/string.go](https://codecov.io/gh/Konstantin8105/c4go/pull/280/diff?src=pr&el=tree#diff-bm9hcmNoL3N0cmluZy5nbw==) | `92.59% <90.9%> (-0.27%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=footer). Last update [982f5b9...37d4a26](https://codecov.io/gh/Konstantin8105/c4go/pull/280?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 1e8f0b0..32b5604 100644
--- a/README.md
+++ b/README.md
@@ -133,7 +133,7 @@ func main() {
             stddef.h	       2/6	        33.3%
              stdio.h	     33/46	        71.7%
             stdlib.h	     33/47	        70.2%
-            string.h	     13/24	        54.2%
+            string.h	     14/24	        58.3%
               time.h	      7/15	        46.7%
              wchar.h	      3/68	        4.41%
             wctype.h	      0/22	           0%
diff --git a/noarch/string.go b/noarch/string.go
index c185ded..b7b084f 100644
--- a/noarch/string.go
+++ b/noarch/string.go
@@ -174,3 +174,20 @@ func Memcpy(dest, source []byte, num uint) []byte {
 	}
 	return nil
 }
+
+func Strrchr(source []byte, c int) []byte {
+	ch := byte(c)
+	pos := len(source)
+	for i := range source {
+		if source[i] == '\x00' {
+			pos = i
+			break
+		}
+	}
+	for i := pos; i >= 0; i-- {
+		if source[i] == ch {
+			return source[i:]
+		}
+	}
+	return source
+}
diff --git a/program/definition_function.go b/program/definition_function.go
index bc5cee8..dbc6136 100644
--- a/program/definition_function.go
+++ b/program/definition_function.go
@@ -261,6 +261,7 @@ var builtInFunctionDefinitions = map[string][]string{
 		"char * memmove(char *, char *, unsigned int) -> noarch.Memmove",
 		"int memcmp(const char *, const char *, unsigned int) -> noarch.Memcmp",
 		"void * memcpy(void *, const void *, size_t) -> noarch.Memcpy",
+		"const char * strrchr( const char *, int) -> noarch.Strrchr",
 	},
 	"stdlib.h": {
 		// stdlib.h


Test patch:
diff --git a/tests/string.c b/tests/string.c
index 2bfe012..c5d8048 100644
--- a/tests/string.c
+++ b/tests/string.c
@@ -3,7 +3,7 @@
 
 int main()
 {
-    plan(40);
+    plan(41);
 
     diag("TODO: __builtin_object_size");
     // https://github.com/Konstantin8105/c4go/issues/359
@@ -169,6 +169,14 @@ int main()
 		memcpy ( name, myname, strlen(myname)+1 );
 		is_streq(name, myname);
 	}
+	{
+		diag("strrchr");
+		char str[] = "This is a sample string";
+		char failData[] = "faildata";
+		char * pch = &failData;
+		pch=strrchr(str,'s');
+		is_eq(pch-str+1,18);
+	}
 
     done_testing();
 }