diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-24 00:28:15 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-24 01:25:53 +0000 |
| commit | f2544d094ba88e1cfbb7993ad67444852cfd5efd (patch) | |
| tree | 252172594a1284e59e88c73c22f0201508809022 /util/nvmutil/lib/string.c | |
| parent | afcd535816b45fd7b0e0d07c1a8580f6f462f5e4 (diff) | |
util/mkhtemp: new utility (hardened mktemp)
part of the same code library as nvmutil.
as part of this, i renamed util/nvmutil
to util/libreboot-utils/ because it is
now a multi-utility codebase.
this is more efficient, since i also wish
to use mkhtemp (function) in nvmutil.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil/lib/string.c')
| -rw-r--r-- | util/nvmutil/lib/string.c | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/util/nvmutil/lib/string.c b/util/nvmutil/lib/string.c deleted file mode 100644 index ca58fb1c..00000000 --- a/util/nvmutil/lib/string.c +++ /dev/null @@ -1,114 +0,0 @@ -/* SPDX-License-Identifier: MIT - * Copyright (c) 2026 Leah Rowe <leah@libreboot.org> - * - * String functions - */ - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <stddef.h> -#include <string.h> -#include <unistd.h> - -#include "../include/common.h" - -/* scmp() - strict string comparison - * - * strict string comparison - * similar to strncmp, but null and - * unterminated inputs do not produce - * a return value; on error, errno is - * set and -1 is returned. - * - * the real return value is stored in - * the 4th argument by pointer. - * - * the value at rval pointer is set, - * only upon success. callers should - * check the return value accordingly. - */ - -int -scmp(const char *a, - const char *b, - size_t maxlen, - int *rval) -{ - size_t ch; - unsigned char ac; - unsigned char bc; - - if (a == NULL || - b == NULL || - rval == NULL) { - - errno = EFAULT; - return -1; - } - - for (ch = 0; ch < maxlen; ch++) { - - ac = (unsigned char)a[ch]; - bc = (unsigned char)b[ch]; - - if (ac != bc) { - *rval = ac - bc; - return 0; - } - - if (ac == '\0') { - *rval = 0; - return 0; - } - } - - /* block unterminated strings */ - errno = EFAULT; - return -1; -} - -/* slen() - strict strict length - * - * strict string length calculation - * similar to strnlen, but null and - * unterminated inputs do not produce - * a return value; on error, errno is - * set and -1 is returned. - * - * the real return value is stored in - * the 3rd argument by pointer. - * - * the value at rval pointer is set, - * only upon success. callers should - * check the return value accordingly. - */ - -int -slen(const char *s, - size_t maxlen, - size_t *rval) -{ - size_t ch; - - if (s == NULL || - rval == NULL) { - - errno = EFAULT; - return -1; - } - - for (ch = 0; - ch < maxlen && s[ch] != '\0'; - ch++); - - if (ch == maxlen) { - /* unterminated */ - errno = EFAULT; - return -1; - } - - *rval = ch; - return 0; -} |
