⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringbuf.c

📁 mpeg 2 source code for video compression
💻 C
字号:
/*	stringbuf: mimicking a bit of C++ to more safely handle strings	copyright 2006 by the mpg123 project - free software under the terms of the LGPL 2.1	see COPYING and AUTHORS files in distribution or http://mpg123.de	initially written by Thomas Orgis*/#include "config.h"#include "debug.h"#include "stringbuf.h"#include <stdlib.h>void init_stringbuf(struct stringbuf* sb){	sb->p = NULL;	sb->size = 0;	sb->fill = 0;}void free_stringbuf(struct stringbuf* sb){	if(sb->p != NULL)	{		free(sb->p);		init_stringbuf(sb);	}}int resize_stringbuf(struct stringbuf* sb, size_t new){	if(sb->size != new)	{		char* t = (char*) realloc(sb->p, new*sizeof(char));		if(t != NULL)		{			sb->p = t;			sb->size = new;			return 1;		}		else return 0;	}	else return 1; /* success */}int copy_stringbuf(struct stringbuf* from, struct stringbuf* to){	if(resize_stringbuf(to, from->fill))	{		memcpy(to->p, from->p, to->size);		to->fill = to->size;		return 1;	}	else return 0;}int add_to_stringbuf(struct stringbuf* sb, char* stuff){	size_t addl = strlen(stuff)+1;	debug1("adding %s", stuff);	if(sb->fill)	{		if(sb->size >= sb->fill-1+addl || resize_stringbuf(sb, sb->fill-1+addl))		{			memcpy(sb->p+sb->fill-1, stuff, addl);			sb->fill += addl-1;		}		else return 0;	}	else	{		if(resize_stringbuf(sb, addl))		{			memcpy(sb->p, stuff, addl);			sb->fill = addl;		}		else return 0;	}	return 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -