aboutsummaryrefslogtreecommitdiff
path: root/lib/io/io.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-02-08 13:19:56 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-02-08 13:19:56 +0100
commitd7229970f8910aa756d299f8bdceee7f4d1fbfbc (patch)
treea95ff2e6bd50578d34d6449c9fde173acc0ef59c /lib/io/io.c
parente947b1459f93f11ad91f3e920676fe1b828281e7 (diff)
add env and make smash be able to parse files with comments
Diffstat (limited to 'lib/io/io.c')
-rw-r--r--lib/io/io.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/io/io.c b/lib/io/io.c
index e8384f3..7dee314 100644
--- a/lib/io/io.c
+++ b/lib/io/io.c
@@ -20,36 +20,48 @@ void rstd(char *buf, unsigned long count)
read(STDIN_FD, buf, count);
}
+
+void wf(unsigned int fd, char *buf)
+{
+ write(fd, buf, cstr_length(buf));
+}
+
void wstdf__(const char *buf, const void **args)
{
+ wff__(STDOUT_FD, buf, args);
+}
+
+
+void wff__(unsigned int fd, const char *buf, const void **args)
+{
const char *start = buf;
char stoi_buf[32] = "";
int i;
for (; *buf; ++buf) {
if (*buf == '%') {
if (buf - start > 0)
- __wstdn(start, buf - start);
+ write(fd, start, buf - start);
++buf;
switch (*buf) {
case '%': __wstdn("%", 1); break;
case 's':
- __wstdn(((const char **)args)[0], cstr_length(((const char**)args)[0]));
+ write(fd, ((const char **)args)[0], cstr_length(((const char**)args)[0]));
++args;
break;
case 'i':
for (i = 0; i < 32; ++i)
stoi_buf[i] = 0;
i64_to_cstr(((u64 *)args)[0], stoi_buf, 32);
- __wstdn(stoi_buf, cstr_length(stoi_buf));
+ write(fd, stoi_buf, cstr_length(stoi_buf));
++args;
break;
case 'u':
for (i = 0; i < 32; ++i)
stoi_buf[i] = 0;
u64_to_cstr(((u64 *)args)[0], stoi_buf, 32);
- __wstdn(stoi_buf, cstr_length(stoi_buf));
+ write(fd, stoi_buf, cstr_length(stoi_buf));
++args;
break;
case 'S':
@@ -71,7 +83,7 @@ void wstdf__(const char *buf, const void **args)
}
if (buf - start > 0)
- __wstdn(start, buf - start);
+ write(fd, start, buf - start);
}
#ifdef IO_LIB_UNIT_TEST