diff options
Diffstat (limited to 'std/io.zc')
| -rw-r--r-- | std/io.zc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/std/io.zc b/std/io.zc new file mode 100644 index 0000000..e7b6300 --- /dev/null +++ b/std/io.zc @@ -0,0 +1,43 @@ + +import "./core.zc" + +raw { + char* format(const char* fmt, ...) { + static char buffer[1024]; + va_list args; + va_start(args, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, args); + va_end(args); + return buffer; + } + + char* format_new(const char* fmt, ...) { + char* buffer = malloc(1024); + va_list args; + va_start(args, fmt); + vsnprintf(buffer, 1024, fmt, args); + va_end(args); + return buffer; + } +} + +raw { + char* readln() { + char* line = NULL; + size_t len = 0; + ssize_t read; + + read = getline(&line, &len, stdin); + + if (read != -1) { + // Remove newline if present + if (line[read - 1] == '\n') { + line[read - 1] = '\0'; + } + return line; + } + + if (line) free(line); + return NULL; + } +} |
