[Frugalware-darcs] setup: added util.c: new function: get_version()

VMiklos vmiklos at frugalware.org
Fri Mar 31 00:48:33 CEST 2006


[added util.c: new function: get_version()
VMiklos <vmiklos at frugalware.org>**20051102210308] {
addfile ./src/util.c
hunk ./src/util.c 1
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "setup.h"
+#include "util.h"
+
+#define VERSIONFILE "/etc/frugalware-release"
+
+char *get_version(void)
+{
+	FILE *fp;
+	char *version;
+	MALLOC(version, 128);
+
+	if ((fp = fopen(VERSIONFILE, "r")) == NULL)
+	{
+		perror(_("Could not open file for reading"));
+		return(NULL);
+	}
+	fgets(version, 127, fp);
+	version[strlen(version)-1]='\0';
+	fclose(fp);
+	return(version);
+}
addfile ./src/util.h
hunk ./src/util.h 1
+#define MALLOC(p, b) { if((b) > 0) \
+	{ p = malloc(b); if (!(p)) \
+	{ fprintf(stderr, "malloc failure: could not allocate %d bytes\n", b); \
+	exit(1); }} else p = NULL; }
+#define FREE(p) { if (p) { free(p); (p) = NULL; }}
+
+char *get_version(void);
}


More information about the Frugalware-darcs mailing list