mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Add strndup.h header so we can use this useful function
It's missing on Windows... we had this helper in liquivision.c but since I used the function in git-access.c I figured I should just turn it into a little helper. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5bbcc7f16d
commit
e84d8624bb
4 changed files with 25 additions and 19 deletions
21
strndup.h
Normal file
21
strndup.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef STRNDUP_H
|
||||
#define STRNDUP_H
|
||||
#if __WIN32__
|
||||
static char *strndup (const char *s, size_t n)
|
||||
{
|
||||
char *cpy;
|
||||
size_t len = strlen(s);
|
||||
if (n < len)
|
||||
len = n;
|
||||
if ((cpy = malloc(len + 1)) !=
|
||||
NULL) {
|
||||
cpy[len] =
|
||||
'\0';
|
||||
memcpy(cpy,
|
||||
s,
|
||||
len);
|
||||
}
|
||||
return cpy;
|
||||
}
|
||||
#endif
|
||||
#endif /* STRNDUP_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue