Compare commits
3 Commits
prerelease
...
prerelease
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d3e79b731 | ||
|
|
b3ee64d294 | ||
|
|
e6ec0fa38a |
@@ -19,6 +19,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
char *get_current_directory() {
|
||||
char *buffer = NULL;
|
||||
|
||||
34
src/shell.c
34
src/shell.c
@@ -23,6 +23,7 @@
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
FILE *fmemopen(void *buf, size_t size, const char *mode) {
|
||||
if (strchr(mode, 'r') == NULL) {
|
||||
return NULL;
|
||||
@@ -41,6 +42,39 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
typedef long ssize_t;
|
||||
|
||||
ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
if (!lineptr || !n || !stream) return -1;
|
||||
|
||||
size_t pos = 0;
|
||||
int c;
|
||||
|
||||
if (*lineptr == NULL || *n == 0) {
|
||||
*n = 128;
|
||||
*lineptr = malloc(*n);
|
||||
if (!*lineptr) return -1;
|
||||
}
|
||||
|
||||
while ((c = fgetc(stream)) != EOF) {
|
||||
if (pos + 1 >= *n) {
|
||||
*n *= 2;
|
||||
char *tmp = realloc(*lineptr, *n);
|
||||
if (!tmp) return -1;
|
||||
*lineptr = tmp;
|
||||
}
|
||||
(*lineptr)[pos++] = c;
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
if (pos == 0 && c == EOF)
|
||||
return -1;
|
||||
|
||||
(*lineptr)[pos] = '\0';
|
||||
return (ssize_t)pos;
|
||||
}
|
||||
#else
|
||||
#include "../external/linenoise/linenoise.h"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user