diff options
| author | tedu <> | 2010-05-18 22:24:55 +0000 |
|---|---|---|
| committer | tedu <> | 2010-05-18 22:24:55 +0000 |
| commit | 84e56ad2cf3f4b33089396bba6483888d54d99a3 (patch) | |
| tree | a6c0f4a1cf1cb7596fb9279f0a7ff14d13a1317e /src/lib/libc/string/strnlen.c | |
| parent | 5a36fcc1c46490330487900d818ea64d85ac1f1a (diff) | |
| download | openbsd-84e56ad2cf3f4b33089396bba6483888d54d99a3.tar.gz openbsd-84e56ad2cf3f4b33089396bba6483888d54d99a3.tar.bz2 openbsd-84e56ad2cf3f4b33089396bba6483888d54d99a3.zip | |
add posix_madvise, posix_memalign, strndup, and strnlen. mostly from
brad and millert, with hints from guenther, jmc, and otto I think.
ok previous.
Diffstat (limited to 'src/lib/libc/string/strnlen.c')
| -rw-r--r-- | src/lib/libc/string/strnlen.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/libc/string/strnlen.c b/src/lib/libc/string/strnlen.c new file mode 100644 index 0000000000..5c99994744 --- /dev/null +++ b/src/lib/libc/string/strnlen.c | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* $OpenBSD: strnlen.c,v 1.1 2010/05/18 22:24:55 tedu Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <sys/types.h> | ||
| 20 | |||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | size_t | ||
| 24 | strnlen(const char *str, size_t maxlen) | ||
| 25 | { | ||
| 26 | const char *cp, *ep; | ||
| 27 | size_t len; | ||
| 28 | |||
| 29 | ep = str + maxlen; | ||
| 30 | for (cp = str; cp < ep && *cp != '\0'; cp++) | ||
| 31 | ; | ||
| 32 | |||
| 33 | return (size_t)(cp - str); | ||
| 34 | } | ||
