[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: file-retriever



Hi,

On Wed, Dec 11, 2002 at 01:01:39AM +0100, David Weinehall wrote:
> Here is an implementation of file-retriever in C, since its TODO file
> expressed an interest in having one.

Oops, I did this also but forgot to send, patch attached.

What amount of error checking code should be done?
Can we use GNU extension functions as most src is using _GNU_SOURCE anyway?
Is any interest in rewriting all other retrievers in C?

regards,
guillem
diff -Naur file/debian/control file-patched/debian/control
--- file/debian/control	2002-05-09 12:39:15.000000000 +0200
+++ file-patched/debian/control	2002-12-11 05:02:46.000000000 +0100
@@ -6,7 +6,7 @@
 Standards-Version: 3.5.2.0
 
 Package: file-retriever
-Architecture: all
+Architecture: any
 Depends: ${shlibs:Depends}
 Provides: retriever
 Description: File retriever
diff -Naur file/debian/rules file-patched/debian/rules
--- file/debian/rules	2000-12-13 05:59:59.000000000 +0100
+++ file-patched/debian/rules	2002-12-11 05:01:07.000000000 +0100
@@ -10,19 +10,21 @@
 
 PACKAGE=$(shell dh_listpackages)
 VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
-ARCH=all
+ARCH=$(shell dpkg --print-architecture)
 FILENAME=$(PACKAGE)_$(VERSION)_$(ARCH).udeb
 PRIORITY=$(shell grep ^Priority: debian/control | cut -d ' ' -f 2)
 
 build: build-stamp
 build-stamp:
 	dh_testdir
+	$(MAKE) small
 	touch build-stamp
 
 clean:
 	dh_testdir
 	dh_testroot
 	rm -f build-stamp
+	$(MAKE) clean
 	dh_clean
 
 install: build
@@ -33,14 +35,14 @@
 	install file-retriever \
 		debian/file-retriever/usr/lib/debian-installer/retriever/file-retriever
 
-# Build architecture-dependent files here.
-binary-arch: build install
+# Build architecture-independent files here.
+binary-indep: build install
 # We have nothing to do by default.
 
-# Build architecture-independent files here.
+# Build architecture-dependent files here.
 #
 # Note that this builds a .udeb, which is not policy compliant or anything.
-binary-indep: build install
+binary-arch: build install
 	dh_testdir
 	dh_testroot
 	dh_installdebconf
diff -Naur file/file-retriever file-patched/file-retriever
--- file/file-retriever	2002-12-11 05:21:17.000000000 +0100
+++ file-patched/file-retriever	1970-01-01 01:00:00.000000000 +0100
@@ -1,2 +0,0 @@
-#!/bin/sh -e
-ln -sf `pwd`/debs/$1 $2
diff -Naur file/file-retriever.c file-patched/file-retriever.c
--- file/file-retriever.c	1970-01-01 01:00:00.000000000 +0100
+++ file-patched/file-retriever.c	2002-12-02 06:40:00.000000000 +0100
@@ -0,0 +1,52 @@
+/*
+ * file-retriever
+ *
+ * Copyright (C) 2002 Guillem Jover <guillem.jover@menta.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+	if (argc < 2)
+		return 1;
+
+	if (strcmp(argv[1], "retrieve") == 0) {
+		char *oldpath, *newpath, *pwd;
+
+		if (argc < 4)
+			return 1;
+
+		pwd = get_current_dir_name();
+		if (pwd == NULL)
+			return errno;
+
+		asprintf(&oldpath, "%s/debs/%s", pwd, argv[2]);
+		newpath = argv[3];
+		unlink(newpath);
+		symlink(oldpath, newpath);
+	} else {
+		return 1;
+	}
+
+	return 0;
+}
+
diff -Naur file/Makefile file-patched/Makefile
--- file/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ file-patched/Makefile	2002-12-11 04:57:52.000000000 +0100
@@ -0,0 +1,25 @@
+# Makefile based on net-retriever's
+
+ARCH=$(shell dpkg --print-architecture)
+CFLAGS=-Wall -g -D_GNU_SOURCE -DARCH=\"$(ARCH)\"
+OBJS=$(subst .c,.o,$(wildcard *.c))
+BIN=file-retriever
+LIBS=
+
+ifdef DEBUG
+CFLAGS:=$(CFLAGS) -DDODEBUG
+endif
+
+all: $(BIN)
+
+$(BIN): $(OBJS)
+	$(CC) -o $(BIN) $(OBJS) $(LIBS)
+
+# Size optimized and stripped binary target.
+small: CFLAGS:=-Os $(CFLAGS) -DSMALL
+small: clean $(BIN)
+	strip --remove-section=.comment --remove-section=.note $(BIN)
+	ls -l $(BIN)
+
+clean:
+	-rm -f $(BIN) $(OBJS) *~

Reply to: