void stack_print(stack *st) { int i; for (i = st->top; i >= 0; i--) { buffer_putlong(buffer_1, st->st[i]); buffer_puts(buffer_1, " "); } buffer_putnlflush(buffer_1); }
int main() { stralloc sa; int res; stralloc_init(&sa); res=buffer_get_token_sa_pred(buffer_0,&sa,ishttp); buffer_puts(buffer_1,"buffer_get_token_sa_pred returned "); buffer_putlong(buffer_1,res); buffer_putsflush(buffer_1,".\n\n"); buffer_putsa(buffer_1,&sa); buffer_flush(buffer_1); return 0; }
void buffer_putdata(struct buffer *b, struct data_item* d) { int len; len = d->key_len + d->value_len; if(b->NUL + len + 21 >= b->buflen)//21 is the other member of data_item:int int int int64 char = 21 _buffer_extendby(b, 1024); buffer_putint(b,len); buffer_putint(b,d->key_len); buffer_putint(b,d->value_len); buffer_putc(b,d->type); buffer_putlong(b,d->version); buffer_putnstr(b,d->key,d->key_len); buffer_putnstr(b,d->value,d->value_len); }
void *_write_mmap(struct silopit *silopit, struct skipnode *x, size_t count, int need_new) { int i, j, c_clone; int fd; int sizes; int result; char file[FILE_PATH_SIZE]; struct skipnode *last; struct footer footer; struct stats stats; int fsize = sizeof(struct footer); memset(&footer, 0, fsize); _prepare_stats(x, count, &stats); sizes = stats.mmap_size; struct inner_block { char key[stats.max_len]; char offset[8]; }; struct inner_block *blks; memset(file, 0, FILE_PATH_SIZE); snprintf(file, FILE_PATH_SIZE, "%s/%s", silopit->basedir, silopit->name); fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd == -1) __PANIC("error creating silopit file"); if (lseek(fd, sizes - 1, SEEK_SET) == -1) __PANIC("error lseek silopit"); result = write(fd, "", 1); if (result == -1) __PANIC("error writing empty"); blks = mmap(0, sizes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (blks == MAP_FAILED) { __PANIC("error mapping block when write on process"); } last = x; c_clone = count; for (i = 0, j = 0; i < c_clone; i++) { if (x->opt == ADD) { buffer_putstr(silopit->buf, x->key); buffer_putc(silopit->buf, 0); buffer_putlong(silopit->buf, x->val); j++; } else count--; last = x; x = x->forward[0]; } char *strings = buffer_detach(silopit->buf); memcpy(blks, strings, sizes); #ifdef MSYNC if (msync(blks, sizes, MS_SYNC) == -1) { __ERROR("Error Msync"); } #endif if (munmap(blks, sizes) == -1) { __ERROR("Un-mmapping the file"); } footer.count = to_be32(count); footer.crc = to_be32(F_CRC); footer.size = to_be32(sizes); footer.max_len = to_be32(stats.max_len); memcpy(footer.key, last->key, strlen(last->key)); result = write(fd, &footer, fsize); if (result == -1) __PANIC("writing the footer"); struct meta_node mn; mn.count = count; memset(mn.end, 0, SILOKATANA_MAX_KEY_SIZE); memcpy(mn.end, last->key, SILOKATANA_MAX_KEY_SIZE); memset(mn.index_name, 0, FILE_NAME_SIZE); memcpy(mn.index_name, silopit->name, FILE_NAME_SIZE); if (need_new) meta_set(silopit->meta, &mn); else meta_set_byname(silopit->meta, &mn); close(fd); return x; }