2008-10-11 07:35:26 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2015-12-07 20:53:23 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2019-05-15 04:27:37 -07:00
|
|
|
#include "evil_private.h"
|
2008-10-11 07:35:26 -07:00
|
|
|
|
|
|
|
|
2008-10-19 12:06:19 -07:00
|
|
|
/*
|
2019-05-03 05:09:07 -07:00
|
|
|
* string related functions
|
2008-10-19 12:06:19 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API char *strcasestr(const char *haystack, const char *needle)
|
2012-04-20 00:51:58 -07:00
|
|
|
{
|
|
|
|
size_t length_needle;
|
|
|
|
size_t length_haystack;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!haystack || !needle)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
length_needle = strlen(needle);
|
2015-01-29 12:17:00 -08:00
|
|
|
length_haystack = strlen(haystack);
|
|
|
|
if (length_haystack < length_needle) return NULL;
|
|
|
|
length_haystack = length_haystack - length_needle + 1;
|
2012-04-20 00:51:58 -07:00
|
|
|
|
|
|
|
for (i = 0; i < length_haystack; i++)
|
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
for (j = 0; j < length_needle; j++)
|
|
|
|
{
|
|
|
|
unsigned char c1;
|
|
|
|
unsigned char c2;
|
|
|
|
|
|
|
|
c1 = haystack[i+j];
|
|
|
|
c2 = needle[j];
|
|
|
|
if (toupper(c1) != toupper(c2))
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
return (char *) haystack + i;
|
|
|
|
next:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-24 20:26:20 -07:00
|
|
|
|
evil: Rename EAPI macro to EVIL_API in Evil library
Summary:
Patch from a series of patches to rename EAPI symbols to specific
library DSOs.
EAPI was designed to be able to pass
```__attribute__ ((visibility ("default")))``` for symbols with
GCC, which would mean that even if -fvisibility=hidden was used
when compiling the library, the needed symbols would get exported.
MSVC __almost__ works like GCC (or mingw) in which you can
declare everything as export and it will just work (slower, but
it will work). But there's a caveat: global variables will not
work the same way for MSVC, but works for mingw and GCC.
For global variables (as opposed to functions), MSVC requires
correct DSO visibility for MSVC: instead of declaring a symbol as
export for everything, you need to declare it as import when
importing from another DSO and export when defining it locally.
With current EAPI definitions, we get the following example
working in mingw and MSVC (observe it doesn't define any global
variables as exported symbols).
```
Example 1:
dll1:
```
EAPI void foo(void);
EAPI void bar()
{
foo();
}
```
dll2:
```
EAPI void foo()
{
printf ("foo\n");
}
```
This works fine with API defined as __declspec(dllexport) in both
cases and for gcc defining as
```__atttribute__((visibility("default")))```
However, the following:
Example 2:
dll1:
```
EAPI extern int foo;
EAPI void foobar(void);
EAPI void bar()
{
foo = 5;
foobar();
}
```
dll2:
```
EAPI int foo = 0;
EAPI void foobar()
{
printf ("foo %d\n", foo);
}
```
This will work on mingw but will not work for MSVC. And that's why
EAPI is the only solution that worked for MSVC.
Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev>
Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
Reviewers: raster, vtorri, jptiz, lucas, woohyun
Reviewed By: vtorri, jptiz
Subscribers: ProhtMeyhet, cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D12182
2020-11-12 08:47:38 -08:00
|
|
|
EVIL_API char *
|
2013-06-24 20:26:20 -07:00
|
|
|
strsep (char **stringp, const char *delim)
|
|
|
|
{
|
|
|
|
char *begin, *end;
|
|
|
|
|
|
|
|
begin = *stringp;
|
|
|
|
if (begin == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* A frequent case is when the delimiter string contains only one
|
|
|
|
character. Here we don't need to call the expensive `strpbrk'
|
|
|
|
function and instead work using `strchr'. */
|
|
|
|
if (delim[0] == '\0' || delim[1] == '\0')
|
|
|
|
{
|
|
|
|
char ch = delim[0];
|
|
|
|
|
|
|
|
if (ch == '\0')
|
|
|
|
end = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*begin == ch)
|
|
|
|
end = begin;
|
|
|
|
else if (*begin == '\0')
|
|
|
|
end = NULL;
|
|
|
|
else
|
|
|
|
end = strchr (begin + 1, ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Find the end of the token. */
|
|
|
|
end = strpbrk (begin, delim);
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
{
|
|
|
|
/* Terminate the token and set *STRINGP past NUL character. */
|
|
|
|
*end++ = '\0';
|
|
|
|
*stringp = end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* No more delimiters; this is the last token. */
|
|
|
|
*stringp = NULL;
|
|
|
|
|
|
|
|
return begin;
|
|
|
|
}
|