예제 #1
0
/* agstrdup_html:
 * For various purposes, including deparsing, we have to recognize
 * strings coming from <...> rather than "...". To do this, we set
 * the top bit of the refcnt field. Since the use of html strings
 * is localized, we allow the application to make the distinction.
 */
char *agstrdup_html(char *s)
{
    refstr_t *key, *r;

    if (StringDict == NULL)
	initialize_strings();
    if (s == NULL)
	return s;

    key = (refstr_t *) (s - offsetof(refstr_t, s[0]));
    r = (refstr_t *) dtsearch(StringDict, key);
    if (r)
	r->refcnt++;
    else {
	r = (refstr_t *) malloc(sizeof(refstr_t) + strlen(s));
	r->refcnt = 1 | HTML_BIT;
	strcpy(r->s, s);
	dtinsert(StringDict, r);
    }
    return r->s;
}
예제 #2
0
파일: test.c 프로젝트: madthanu/alc-strace
int main() {
	pthread_t thread[2];
	char thread_id[2][10];
	int i, ret, pid;

	system("rm -f /tmp/mmap*");
	initialize_strings();

	pid = fork();
	assert(pid != -1);

	for(i = 0; i < 2; i++) {
		sprintf(thread_id[i], "%d.%d", pid, i);
		ret = pthread_create(&thread[i], NULL, thread_main, (char *)thread_id[i]);
		assert(ret == 0);
	}

	for(i = 0; i < 2; i++) {
		ret = pthread_join(thread[i], NULL);
		assert(ret == 0);
	}

	printf("done.\n");
}