[Frugalware-git] xbdmenu: mem.c

James Buren ryuo at frugalware.org
Thu Mar 12 18:47:10 CET 2009


Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=xbdmenu.git;a=commitdiff;h=c0cc567c929ea34f519bfe5bbc637c3be0d319f4

commit c0cc567c929ea34f519bfe5bbc637c3be0d319f4
Author: James Buren <ryuo at frugalware.org>
Date:   Thu Mar 12 12:51:32 2009 -0500

mem.c
* additional counter functions

diff --git a/mem.c b/mem.c
index 5b88b8b..30e8aa4 100644
--- a/mem.c
+++ b/mem.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include "mem.h"
#include "env.h"

@@ -40,6 +41,31 @@ extern void zfree(void *ptr)
}
}

+/* reference counting wrapper for fopen() */
+extern FILE *zfopen(const char *path,const char *mode)
+{
+	FILE *file = fopen(path,mode);
+	if(file==NULL)
+	{
+		printf("%s: '%s'\n",strerror(errno),path);
+		exit(EXIT_FAILURE);
+	}
+	++rc;
+	return(file);
+}
+
+/* reference counting wrapper for fclose() */
+extern void zfclose(FILE *ptr)
+{
+	if(ptr==NULL)
+		printf("Invalid pointer passed to zfclose().\n");
+	else
+	{
+		fclose(ptr);
+		--rc;
+	}
+}
+
/* cleanup global variables */
extern void cleanup(void)
{


More information about the Frugalware-git mailing list