All pastes #814881 Raw Edit

fdeleteline

public cpp v1 · immutable
·published 2007-12-13 16:42 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 = fopen("__temp__", io_write);	if (!fHnd2)	{		fclose(fHnd1);		return 0;	}	while (fread(fHnd1, temp))	{		if (strcmp(temp, line, .length = len))		{			fwrite(fHnd2, temp);		}	}	fclose(fHnd1);	fclose(fHnd2);	fremove(filename);	fHnd1 = fopen(filename, io_write);	if (!fHnd1) return 0;	fHnd2 = fopen("__temp__", io_read);	if (!fHnd2)	{		fclose(fHnd1);		return 0;	}	while (fread(fHnd2, temp))	{		fwrite(fHnd1, temp);	}	fclose(fHnd1);	fclose(fHnd2);	fremove("__temp__");	return 1;}