summaryrefslogtreecommitdiff
path: root/edit-null.c
blob: ea6c5db7a92f8b860b0b7f2e606491086a9432c2 (plain)
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
#include "rc.h"

#include <errno.h>

#include <sys/types.h>

#include "edit.h"

bool editing = 0;

void *edit_init(int fd) {
	/* this function deliberately left blank */
	return NULL;
}

char *edit_alloc(void *cookie, int *count) {
	char *buf;
	int size, used;
	ssize_t r;

	used = 0;
	size = 1;
	buf = ealloc(size + 1); /* leave room for terminating \0 */
	do {
		if (used >= size) { /* >= leaves room for terminating \0 */
			size = size * 2;
			buf = erealloc(buf, size);
		}
		do {
			r = rc_read(0, buf + used, size - used);
			sigchk();
			if (r == -1)
				switch (errno) {
				case EAGAIN:
					if (!makeblocking(0))
						panic("not O_NONBLOCK");
					errno = EINTR;
					break;
				case EIO:
					if (makesamepgrp(0))
						errno = EINTR;
					else
						errno = EIO;
					break;
				}
		} while (r < 0 && errno == EINTR);

		if (r == 0)
			return NULL;

		used += r;
		buf[used] = '\0';
	} while (strchr(buf, '\n') == NULL);

	*count = used;
	if (used)
		return buf;
	else
		return NULL;
}

void edit_prompt(void *cookie, char *prompt) {
	fprint(2, "%s", prompt);
}

void edit_free(void *buffer) {
	efree(buffer);
}

void edit_end(void *cookie) {
	/* this function deliberately left blank */
}