-
Notifications
You must be signed in to change notification settings - Fork 1
/
osint_posix.c
102 lines (88 loc) · 1.75 KB
/
osint_posix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include "db_vm.h"
void VM_sysinit(int argc, char *argv[])
{
#ifdef LINE_EDIT
setvbuf(stdin, NULL, _IONBF, 0);
#endif
}
char *VM_getline(char *buf, int size)
{
#ifdef LINE_EDIT
int i = 0;
while (i < size - 1) {
int ch = VM_getchar();
if (ch == '\n') {
buf[i++] = '\n';
#ifdef ECHO_INPUT
VM_putchar('\n');
#endif
break;
}
else if (ch == '\b' || ch == 0x7f) {
if (i > 0) {
#ifdef ECHO_INPUT
VM_putchar('\b');
#endif
VM_putchar(' ');
VM_putchar('\b');
fflush(stdout);
--i;
}
}
else {
buf[i++] = ch;
#ifdef ECHO_INPUT
VM_putchar(ch);
fflush(stdout);
#endif
}
}
buf[i] = '\0';
#else
fgets(buf, size, stdin);
#endif
return buf;
}
void VM_vprintf(const char *fmt, va_list ap)
{
char buf[80], *p = buf;
vsprintf(buf, fmt, ap);
while (*p != '\0')
VM_putchar(*p++);
}
void VM_flush(void)
{
fflush(stdout);
}
int VM_getchar(void)
{
return getchar();
}
void VM_putchar(int ch)
{
putchar(ch);
}
#ifdef LOAD_SAVE
int VM_opendir(const char *path, VMDIR *dir)
{
if (!(dir->dirp = opendir(path)))
return -1;
return 0;
}
int VM_readdir(VMDIR *dir, VMDIRENT *entry)
{
struct dirent *ansi_entry;
if (!(ansi_entry = readdir(dir->dirp)))
return -1;
strcpy(entry->name, ansi_entry->d_name);
return 0;
}
void VM_closedir(VMDIR *dir)
{
closedir(dir->dirp);
}
#endif