Exemple #1
0
/* grow -- buffer grow function for str() */
static void str_grow(Format *f, size_t more) {
	Buffer *buf = expandbuffer(f->u.p, more);
	f->u.p		= buf;
	f->buf		= buf->str + (f->buf - f->bufbegin);
	f->bufbegin	= buf->str;
	f->bufend	= buf->str + buf->len;
}
Exemple #2
0
int WriteSectionA(const char *filename, const char *section, const CONFENTRY *entrydef, const int size, const int CharType, int maxbufsize)
{
	int ret;
	int len;
	int nsize=0;
	int remaining=maxbufsize;

	unsigned char **buffer;
	unsigned char **newbuf;
	
	*buffer = (unsigned char*) malloc(maxbufsize);
	if (*buffer==NULL)
		return -1;

	*newbuf = (unsigned char*) malloc(maxbufsize);
	if (*newbuf==NULL)
	{
		free(*buffer);
		return -1;
	}


	if((ret=LoadConfigFileA(filename, buffer, maxbufsize))==0)
	{
		/*
			Convert the buffer from ASCII to UTF-16/32 or vice versa
		*/
		if (TestBuffer(*buffer)==ASCII && CharType!=ASCII)
			expandbuffer((char*)*buffer, ret, (wchar_t*) newbuf);
		else
			shrinkbuffer((wchar_t*)*buffer, ret/sizeof(wchar_t),(char*)newbuf);

		if (CharType==ASCII)
		{
			char* result1, *result2;
			char* begin, *buf, *nbuf;
			buf = (char*) *buffer;
			nbuf = (char*) *newbuf;

			result1 = FindSectionA(buf, section, &begin);
			if (result1!=NULL)
				result2 = FindSectionEndA(result1);
			else
			{
				free(*buffer);
				free(*newbuf);
				return -1;
			}

			/* Copy everything in front of the section */
			len = begin - result1;
			if (remaining-len > 16)
				strncpy(nbuf, buf, len);
			
			remaining -= len;
			
			/* Fill buffer */
			nsize = PrepareConfigBufferA(entrydef, size, result1, remaining);
			if (nsize>2)
				nsize += len;

			/* Copy the rest of the file */
			if (result2!=NULL)
			{
				strncpy(nbuf, result2, remaining);
			}
			else
			{
				/* Write End of File */
				strcpy(nbuf,"\\\\END OF FILE//");
				nsize+=16;
			}
			SaveConfigFileA(filename, nbuf, nsize);
		}
		else
		{

		}

	}

	free(*buffer);
	free(*newbuf);
	return ret;
}