Esempio n. 1
0
int				ft_gnl(const int fd, char **line)
{
	static t_file	*myfile;
	t_file			*fptr;
	char			buf[BUFF_SIZE + 1];
	int				res;

	if (fd < 0 || !(line) || read(fd, buf, 0) < 0)
		return (-1);
	fptr = move_to_file(fd, &myfile);
	while ((res = read(fd, buf, BUFF_SIZE)))
	{
		buf[res] = '\0';
		fptr->str = ft_strfjoin(&fptr->str, buf);
		if (ft_strchr(buf, '\n'))
			break ;
	}
	if (res < BUFF_SIZE && !(ft_strlen(fptr->str)))
	{
		delete_current_file(&myfile, fptr, line);
		return (0);
	}
	buffer_update(fptr, line);
	return (1);
}
Esempio n. 2
0
size_t buffer_resize(Buffer *buffer, size_t new_size)
{
    // FIXME: If growing, zero area past the current size after completion.
    
    if (new_size != malloc_size(buffer->data)) {
        buffer->data = realloc(buffer->data, new_size);
        buffer_update(buffer);
    }
    
    return buffer->size;
}
Esempio n. 3
0
static VALUE
buffer_digest(int argc, VALUE *argv, VALUE self)
{
  VALUE str, value;

  if (0 < rb_scan_args(argc, argv, "01", &str)) {
    buffer_reset(self);
    buffer_update(self, str);
    value = rb_funcall(self, rb_intern("finish"), 0);
    buffer_reset(self);
  } else {
    value = rb_funcall(self, rb_intern("finish"), 0);
  }

  return value;
}
Esempio n. 4
0
int main()
{
    FILE *fd;
    FILE *fd_to;
    char buffer[4096];
    Buffer ctx;
    json_val_t *val;
    PtlHeader header;
    char dist[20];
    char *str;

    protocol_init(&header);
    protocol_set_key(&header, "user", "pwd");

    buffer_init(&ctx);
    if ((fd = fopen("test.json", "r")) == NULL) {
        printf("Can't open file\n");
        return 1;
    }

    while (1) {
        int read = fread(buffer, 1, 4096, fd);
        if (read <= 0)
            break;
        buffer_update(&ctx, buffer, read);
    } 

    if ((fd_to = fopen("test.dec", "w")) == NULL) {
        printf("Can't open file\n");
        return 1;
    }

    protocol_encrypt_string(&ctx, &header);
    fwrite(header.dist, 1, 20, fd_to);
    fwrite(ctx.buffer, 1, ctx.pos, fd_to);
    return 0;
}