delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/21/01:42:36

Date: Thu, 21 Aug 1997 17:42:57 +1100
From: Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz>
Subject: Re: [Q] wrapping functions with linker
In-reply-to: <5tg75j$sj3$1@newton.pacific.net.sg>
To: fesenko AT pacific DOT net DOT sg (Victor), djgpp AT delorie DOT com
Message-id: <199708210547.RAA21366@teleng1.tait.co.nz gatekeeper.tait.co.nz>
Organization: Tait Electronics Limited
MIME-version: 1.0
Comments: Authenticated sender is <billc AT blackmagic DOT tait DOT co DOT nz>

On 21 Aug 97 at 16:55, Victor wrote:
> #define mprintf(format,args...) {fi=fopen("malloc.log","a");
> fprintf(fi,format,## args); fclose(fi);}

That's your problem: fopen calls malloc which (for you) calls fopen 
which calls malloc... I got tipped off by esp in your stack dump 
being so low.

Try, instead (no guarantees, I'm not sure about opening for append, 
I've never done it):

#include <stdarg.h>
void mprintf(const char *fmt, ...)
{
	int fd=open ("malloc.log", O_TEXT|O_CREAT|O_APPEND, S_IWUSR)
	static char buff[1024]; /* dangerous if the output string is too
								long */	
	va_list args;
	va_start (args, fmt);
	vsprintf (buff, fmt, args);
	va_end (args);
	write (fd, buff, strlen (buff));
	close (fd);
}

HTH
Bill
--
Leave others their otherness.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019