aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-02-11 18:08:55 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-02-11 18:08:55 +0100
commit6e40a34fef4b4b140442cc34408b2442043eba21 (patch)
treeacae1f3828a067e66683bb349054d9c7e7cf8842 /core
parent05cf1511dfcde10717894bab2004150ad43cca3f (diff)
chagne system structure and fix env
Diffstat (limited to 'core')
-rw-r--r--core/env.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/core/env.c b/core/env.c
index e96be59..0d014a8 100644
--- a/core/env.c
+++ b/core/env.c
@@ -2,13 +2,14 @@
#include "../lib/sys/sizes.h"
#include "../lib/sys/execve.h"
#include "../lib/env/env.h"
+#include "../lib/sys/types.h"
+#include "../lib/cstr/cstr.h"
-#define BUFSIZ 1024
char buf[BUFSIZ] = "";
-
void add_to_env(char *line, u64 linenumber)
{
+ char *begin = line;
char *key;
char *value;
@@ -17,7 +18,7 @@ void add_to_env(char *line, u64 linenumber)
while (*line != '=' && *line) ++line;
if (!*line) {
- wff(STDERR_FD, "error: %i no valid environment line\n", linenumber);
+ wff(STDERR_FD, "error: '%s' %i no valid environment line\n", begin, linenumber);
return;
}
@@ -46,7 +47,7 @@ int main(int argc, const char **argv)
}
u64 fd = STDIN_FD;
- u64 size;
+ i64 size;
char *p;
u64 linenumber = 1;
const char **execargv = argv + 1;
@@ -65,13 +66,10 @@ int main(int argc, const char **argv)
}
}
- while ((size = read(fd, buf, BUFSIZ - 1))) {
- p = buf;
-
- while (p < buf + BUFSIZ && *p != '\n') ++p;
- *(++p) = 0;
-
- add_to_env(buf, linenumber++);
+ while ((size = get_next_line_from_fd(fd, buf)) >= 0) {
+ if (cstr_length(buf)) {
+ add_to_env(buf, linenumber++);
+ }
}
execve(execargv[0], execargv, getenvp());