author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Wed, 03 Mar 2010 18:36:54 +0100 | |
changeset 52 | c9401e6a62cb |
parent 49 | 59b09b0aeb96 |
permissions | -rw-r--r-- |
13
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
2 |
* $Id: config.c 171 2008-08-10 18:20:39Z mbroeker $ |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
3 |
* $URL: http://localhost/svn/c/mcbot/trunk/src/compat.c $ |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
* |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
*/ |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <stdio.h> |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <stdlib.h> |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <string.h> |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
|
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
#include <compat.h> |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
|
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
char *compat_strdup (const char *s) |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
{ |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
char *buf; |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
|
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
buf = malloc (strlen (s) + 1); |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
if (buf != NULL) |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
strcpy (buf, s); |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
|
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
return buf; |
d3554afaa768
mcbot-0.94-5 Changelog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
} |
49
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
22 |
|
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
23 |
char *safe_strncpy (char *dest, const char *src, size_t size) |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
24 |
{ |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
25 |
size_t i; |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
26 |
|
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
27 |
for (i = 0; i < size - 1; i++) { |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
28 |
if (src[i] == '\0') |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
29 |
break; |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
30 |
dest[i] = src[i]; |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
31 |
} |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
32 |
|
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
33 |
dest[i] = '\0'; |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
34 |
|
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
35 |
return dest; |
59b09b0aeb96
safe_strncpy replaces the insecure strncpy function
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
13
diff
changeset
|
36 |
} |