Sha256: 69cffa24daeb3f893f252a06ce5cfc7a88565a68ad1c38769b5d63b9dd9a3bc5

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

#ifndef KSTRING_H
#define KSTRING_H

#include <stdlib.h>
#include <string.h>

#ifndef kroundup32
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#endif

#ifndef KSTRING_T
#define KSTRING_T kstring_t
typedef struct __kstring_t {
	size_t l, m;
	char *s;
} kstring_t;
#endif

static inline int kputs(const char *p, kstring_t *s)
{
	int l = strlen(p);
	if (s->l + l + 1 >= s->m) {
		s->m = s->l + l + 2;
		kroundup32(s->m);
		s->s = (char*)realloc(s->s, s->m);
	}
	strcpy(s->s + s->l, p);
	s->l += l;
	return l;
}

static inline int kputc(int c, kstring_t *s)
{
	if (s->l + 1 >= s->m) {
		s->m = s->l + 2;
		kroundup32(s->m);
		s->s = (char*)realloc(s->s, s->m);
	}
	s->s[s->l++] = c;
	s->s[s->l] = 0;
	return c;
}

int ksprintf(kstring_t *s, const char *fmt, ...);

#endif

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bio-bwa-0.2.2 ext/kstring.h
bio-bwa-0.2.1 ext/kstring.h
bio-bwa-0.2.0 ext/kstring.h