aboutsummaryrefslogtreecommitdiff
path: root/core/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/env.c')
-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());