All pastes #814860 Raw Edit

fdeleteline

public cpp v1 · immutable
·published 2007-12-13 16:31 UTC
rendered paste body
stock fdeleteline(filename[], line[]){		if (!fexist(filename)) return 0;	new		temp[256],		File:fHnd1 = fopen(filename, io_read),		len = strlen(line);	if (!fHnd1) return 0;	new		File:fHnd2 = ftemp();	if (!fHnd2)	{		fclose(fHnd1);		return 0;	}	while (fread(fHnd1, temp))	{		if (strcmp(temp, line, .length = len))		{			fwrite(fHnd2, temp);		}	}	fclose(fHnd1);	fremove(filename);	fHnd1 = fopen(filename, io_write);	if (fHnd1)	{		while (fread(fHnd2, temp))		{			fwrite(fHnd1, temp);		}		fclose(fHnd1);		fclose(fHnd2);		return 1;	}	fclose(fHnd2);	return 0;}