Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdint-gcc.h>
- enum {
- BUFFER_SIZE = 4096
- };
- struct FileWriteState {
- int fd; // "файловый дескриптор", для вывода на стандартный поток вывода - 1
- unsigned char *buf; // указатель на буфер
- int bufsize; // размер буфера
- unsigned char buf_rec[4096];// здесь потребуется добавить поля для реализации буферизованной записи
- int count;
- };
- void flush(struct FileWriteState *out) {
- write(out->fd, out->buf_rec, BUFFER_SIZE);
- }
- void writechar(int c, struct FileWriteState *out) {
- unsigned char *p = out->buf;
- unsigned char *p_rec = out->buf_rec;
- for (int i = 0; i < c; ++i) {
- if (out->count == BUFFER_SIZE) {
- flush(out);
- }
- *p_rec = *p;
- ++p_rec;
- ++p;
- ++out->count;
- }
- }
- static unsigned char buffer[4096];
- struct FileWriteState defolt = {STDOUT_FILENO, buffer, BUFFER_SIZE};
- struct FileWriteState *stout = &defolt;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement