Return to buf.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / tftpd / src |
1.1.2.1 misho 1: #include "global.h"
2: #include "buf.h"
3:
4:
5: int
6: initBuffer(int siz)
7: {
8: ETRACE();
9:
10: bf = rpack_create(NULL, 0);
11: if (!bf)
12: return -1;
13: if (rpack_attach(bf, siz) == -1) {
14: rpack_destroy(&bf);
15: return -1;
16: }
17:
18: return 0;
19: }
20:
21: void
22: endBuffer()
23: {
24: flushBuffer(cli.fd);
25: rpack_detach(bf);
26: rpack_destroy(&bf);
27: }
28:
29: int
30: flushBuffer(int fd)
31: {
32: int ret = 0;
33:
1.1.2.2 ! misho 34: if (!bf || !cli.addr.sa.sa_len || cli.opc != TFTP_OPC_WRQ)
1.1.2.1 misho 35: return 0;
36:
37: ret = write(fd, RPACK_BUF(bf), RPACK_OFF(bf));
38: if (ret == -1)
39: ESYSERR(0);
40: else
41: RPACK_REWIND(bf);
42:
43: EVERBOSE(3, "Flush buffer ret=%d", ret);
44: return ret;
45: }
46:
47: int
48: bfwrite(int fd, void *buf, int buflen)
49: {
50: void *m;
51:
52: if (!buf)
53: return -1;
54:
55: /* flush */
56: if (RPACK_REMAIN(bf) < buflen)
57: flushBuffer(fd);
58:
59: m = rpack_rdata(bf, buf, buflen);
60: if (!m)
61: return -1;
62:
63: e_free(m);
64: return buflen;
65: }