summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/setenv.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 23:14:53 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 23:14:53 +0100
commit169daa11155988a210fac949297381743f3cb400 (patch)
tree602ef5df5ae9ea075ab3d5dac3c8ad60da1ea2cc /lib/libc/stdlib/setenv.c
parent4e2112e165fdd94dee58378e3ea32892f3710cd7 (diff)
feat: clang-tidy fixes
Diffstat (limited to 'lib/libc/stdlib/setenv.c')
-rw-r--r--lib/libc/stdlib/setenv.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/libc/stdlib/setenv.c b/lib/libc/stdlib/setenv.c
index 1464fc1b..004a29bd 100644
--- a/lib/libc/stdlib/setenv.c
+++ b/lib/libc/stdlib/setenv.c
@@ -1,7 +1,9 @@
-#include <libc.h>
-#include <atomic.h>
-#include <stdlib.h>
-#include <string.h>
+#include "stddef.h" // for NULL
+
+#include <atomic.h> // for LIBC_LOCK, LIBC_UNLOCK
+#include <libc.h> // for (anonymous), libc, (anonymous struct)::(anonymous)
+#include <stdlib.h> // for malloc, realloc, setenv
+#include <string.h> // for strlen, size_t, memcpy, strcpy, strchr, strncmp
extern char **environ;
@@ -20,7 +22,7 @@ int setenv(const char *var, const char *value, int overwrite)
malloc(var_len + 1 + value_len + 1);
if (!new_env)
return -1;
- memcpy(new_env, var, var_len);
+ strcpy(new_env, var);
new_env[var_len] = '=';
memcpy(new_env + var_len + 1, value,
value_len + 1);
@@ -34,7 +36,8 @@ int setenv(const char *var, const char *value, int overwrite)
while (environ[env_count])
env_count++;
- char **new_envp = realloc(environ, (env_count + 2) * sizeof(char *));
+ char **new_envp = (char **)realloc((void *)environ,
+ (env_count + 2) * sizeof(char *));
if (!new_envp)
return -1;
@@ -43,7 +46,7 @@ int setenv(const char *var, const char *value, int overwrite)
if (!new_var)
return -1;
- memcpy(new_var, var, var_len);
+ strcpy(new_var, var);
new_var[var_len] = '=';
memcpy(new_var + var_len + 1, value, value_len + 1);