Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
a369d134
Commit
a369d134
authored
8 years ago
by
Kostyantyn Vorobyov
Browse files
Options
Downloads
Patches
Plain Diff
[RTL] Support functions in E-ACSL string library
parent
428f4208
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/e-acsl/share/e-acsl/e_acsl_string.h
+58
-0
58 additions, 0 deletions
src/plugins/e-acsl/share/e-acsl/e_acsl_string.h
with
58 additions
and
0 deletions
src/plugins/e-acsl/share/e-acsl/e_acsl_string.h
+
58
−
0
View file @
a369d134
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
* of string.h functions use GLIBC-based implementations.
* of string.h functions use GLIBC-based implementations.
***************************************************************************/
***************************************************************************/
#include
"e_acsl_malloc.h"
#ifndef E_ACSL_STD_STRING
#ifndef E_ACSL_STD_STRING
#define E_ACSL_STD_STRING
#define E_ACSL_STD_STRING
# if defined(__GNUC__) && defined(E_ACSL_BUILTINS)
# if defined(__GNUC__) && defined(E_ACSL_BUILTINS)
...
@@ -60,4 +62,60 @@
...
@@ -60,4 +62,60 @@
# include "glibc/strcmp.c"
# include "glibc/strcmp.c"
# include "glibc/strncmp.c"
# include "glibc/strncmp.c"
# endif
# endif
/* \brief Local version of `strcat` */
static
char
*
nstrcat
(
char
*
dest
,
const
char
*
src
)
{
memcpy
(
dest
+
strlen
(
dest
),
src
,
strlen
(
src
)
+
1
);
return
dest
;
}
/* \brief Local version of `strdup` */
static
char
*
nstrdup
(
const
char
*
s
)
{
if
(
s
)
{
size_t
len
=
strlen
(
s
)
+
1
;
void
*
n
=
native_malloc
(
len
);
return
(
n
==
NULL
)
?
NULL
:
(
char
*
)
memcpy
(
n
,
s
,
len
);
}
return
NULL
;
}
/* \brief Append `src` to `dest` by re-allocating `dest`.
*
* `sappend` assumes that `dest` is either NULL (in which case it is
* allocated on the heap) or a heap-allocated C string that can be passed
* as an input to realloc. If `delim` and `dest` are not NULLs them string
* `delim` is appended to `dest` before `src`
*
* \return Result of concatenation of `dest` and `src` */
static
char
*
sappend
(
char
*
dest
,
const
char
*
src
,
const
char
*
delim
)
{
if
(
!
dest
&&
src
)
dest
=
nstrdup
(
src
);
else
if
(
src
&&
dest
)
{
size_t
ldelim
=
delim
?
strlen
(
delim
)
:
0
;
size_t
len
=
strlen
(
src
)
+
strlen
(
dest
)
+
1
;
if
(
ldelim
)
len
+=
ldelim
;
dest
=
native_realloc
(
dest
,
len
);
if
(
ldelim
)
dest
=
nstrcat
(
dest
,
delim
);
dest
=
nstrcat
(
dest
,
src
);
}
return
dest
;
}
/** \brief Return 0 if string `str` end with string `pat` and a non-zero value
* otherwise. The function assumes that both, `str` and `path` are valid,
* NUL-terminated C strings. If any of the input strings are NULLs, a non-zero
* value is returned. */
static
int
endswith
(
char
*
str
,
char
*
pat
)
{
if
(
str
&&
pat
)
{
size_t
slen
=
strlen
(
str
);
size_t
plen
=
strlen
(
pat
);
if
(
slen
>=
plen
)
{
str
+=
slen
-
plen
;
return
strncmp
(
str
,
pat
,
plen
);
}
}
return
1
;
}
#endif
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment