Example #1
0
void* malloc(size_t size) {
	mythread* thread = getById(pthread_self());
	if (size >= N) {
		mybucket* b = bfind(thread->big_list, size);
		if (b == 0) {
			b = bfind(glob_list, size);
			if (b == 0) {
				b = bcreate(size);
				return b->mem;
			}
			pthread_mutex_lock(&glob_mutex);
			bdelete(&glob_list, &glob_list_end, b);
			glob_size--;
			pthread_mutex_unlock(&glob_mutex);
			return b->mem;
		}
		pthread_mutex_lock(&thread->thread_mutex);
		bdelete(&thread->big_list, &thread->big_list_end, b);
		thread->bigsize--;
		pthread_mutex_unlock(&thread->thread_mutex);
		return b->mem;
	} else {
		mybucket* b = bfind(thread->small_list, size);
		if (b == 0) {
			b = bcreate(size);
			return b->mem;
		}
		pthread_mutex_lock(&thread->thread_mutex);
		bdelete(&thread->small_list, &thread->small_list_end, b);
		thread->smallsize--;
		pthread_mutex_unlock(&thread->thread_mutex);
		return b->mem;
	}
}
Example #2
0
STRING* new_string(int increments)
{
	STRING *s = mallocx(sizeof(STRING));
	bcreate(s, 1, increments);
	badd(s, "\0", 1);
	return s;
}
Example #3
0
void Zread_file(void)
{
	struct buff *tbuff;
	struct mark *tmark;
	int rc = 1;

	if (get_findfile("Read File: "))
		return;

	if ((tbuff = bcreate())) {
		putpaw("Reading %s", lastpart(Fname));
		rc = breadfile(tbuff, Fname, NULL);
		if (rc == 0) {
			btoend(tbuff);
			if ((tmark = bcremark(tbuff))) {
				btostart(tbuff);
				bcopyrgn(tmark, Bbuff);
				bdelmark(tmark);
			} else
				error("Out of memory");
		}
		bdelbuff(tbuff);
	}

	if (rc)
		error("Unable to read %s", Fname);
}
Example #4
0
FILE *fopendyn(void) {
	/* create file */
	FILE *f;
	if(!(f = bcreate(-1,O_WRONLY,NULL,0,DYN_BUFFER_SIZE,true))) {
		free(f);
		return NULL;
	}
	benqueue(f);
	return f;
}
Example #5
0
/* If there is a config.z file, read it! */
void readvfile(const char *fname)
{
	struct buff *buff = bcreate();

	if (!buff || breadfile(buff, fname, NULL)) {
		terror("Unable to read config file\n");
		exit(1);
	}

	while (bstrline(buff, PawStr, PAWSTRLEN))
		setavar(PawStr, false);

	bdelbuff(buff);
}
Example #6
0
create_rgb_files()
{
int i;
for (i=0; i<3; i++)
	{
	if (!bcreate(rgb_names[i], rgb_files+i))
		{
		cant_create(rgb_names[i]);
		close_rgb_files();
		return(0);
		}
	}
return(1);
}
Example #7
0
FILE *fopen(const char *filename,const char *mode) {
	uint flags = parsemode(mode);
	if((flags & O_ACCMODE) == 0)
		return NULL;

	/* open */
	int fd = open(filename,flags,FILE_DEF_MODE);
	if(fd < 0)
		return NULL;

	/* create file */
	FILE *f = NULL;
	if(!(f = bcreate(fd,flags,NULL,IN_BUFFER_SIZE,OUT_BUFFER_SIZE,false))) {
		close(fd);
		free(f);
		return NULL;
	}
	benqueue(f);
	return f;
}