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

Need advice if changes to file_5.04-6 enabling build on GNU/Hurd are OK?



Hi list,

I've managed to make the package file_5.04-6 to build on Hurd overcoming
the MAXPATHLEN problems. Three .c files and one .h file was changed: Can
somebody take a look to check if the the patch attached below is correct
(before I create send a bug report to the package managers). Sorry for
some blanks and tabs changes.

Thanks,
Svante Signell

# Fixing MAXPATHLEN problems enabling build for GNU/Hurd
# Svante Signell <svante.signell@telia.com>  Tue, 8 Feb 2011 23:17:13 +0100
#
--- file-5.04.orig/src/magic.c
+++ file-5.04/src/magic.c
@@ -85,22 +85,36 @@
 get_default_magic(void)
 {
 	static const char hmagic[] = "/.magic";
+#ifdef __GLIBC__
+	static char * default_magic;
+	char * hmagicpath;
+#else
 	static char default_magic[2 * MAXPATHLEN + 2];
-	char *home;
 	char hmagicpath[MAXPATHLEN + 1];
+#endif
+
+	char *home;
 
 	if ((home = getenv("HOME")) == NULL)
 		return MAGIC;
 
+#ifdef __GLIBC__
+	(void)asprintf(&hmagicpath, "%s%s", home, hmagic);
+	if (access(hmagicpath, R_OK) == -1)
+		return MAGIC;
+	(void)asprintf(&default_magic, "%s:%s",
+	    hmagicpath, MAGIC);
+	return default_magic;
+	free (hmagicpath);
+	free (default_magic);
+#else
 	(void)snprintf(hmagicpath, sizeof(hmagicpath), "%s%s", home, hmagic);
-
 	if (access(hmagicpath, R_OK) == -1)
 		return MAGIC;
-
 	(void)snprintf(default_magic, sizeof(default_magic), "%s:%s",
 	    hmagicpath, MAGIC);
-
 	return default_magic;
+#endif
 }
 
 public const char *
--- file-5.04.orig/src/apprentice.c
+++ file-5.04/src/apprentice.c
@@ -72,10 +72,6 @@
 #define MAP_FILE 0
 #endif
 
-#ifndef MAXPATHLEN
-#define MAXPATHLEN	1024
-#endif
-
 struct magic_entry {
 	struct magic *mp;	
 	uint32_t cont_count;
@@ -708,7 +704,12 @@
 	struct magic_entry *marray;
 	uint32_t marraycount, i, mentrycount = 0, starttest;
 	size_t slen, files = 0, maxfiles = 0;
-	char subfn[MAXPATHLEN], **filearr = NULL, *mfn;
+#ifdef __GLIBC__
+	char * subfn;
+#else
+	char subfn[MAXPATHLEN];
+#endif
+	char **filearr = NULL, *mfn;
 	struct stat st;
 	DIR *dir;
 	struct dirent *d;
@@ -735,8 +736,13 @@
 			goto out;
 		}
 		while ((d = readdir(dir)) != NULL) {
-			(void)snprintf(subfn, sizeof(subfn), "%s/%s",
-			    fn, d->d_name);
+#ifdef __GLIBC__
+		  (void)asprintf (&subfn, "%s/%s",
+				  fn, d->d_name);
+#else
+		  (void)snprintf (subfn, sizeof(subfn), "%s/%s",
+				  fn, d->d_name);
+#endif
 			if (stat(subfn, &st) == -1 || !S_ISREG(st.st_mode))
 				continue;
 			if ((mfn = strdup(subfn)) == NULL) {
@@ -757,6 +763,9 @@
 			}
 			filearr[files++] = mfn;
 		}
+#ifdef __GLIBC__
+		free (subfn);
+#endif
 		closedir(dir);
 		qsort(filearr, files, sizeof(*filearr), cmpstrp);
 		for (i = 0; i < files; i++) {
--- file-5.04.orig/src/file.h
+++ file-5.04/src/file.h
@@ -51,7 +51,13 @@
 #endif
 #include <regex.h>
 #include <sys/types.h>
+
+#ifdef __GNU__
+#include <features.h>
+#else
 #include <sys/param.h>
+#endif
+
 /* Do this here and now, because struct stat gets re-defined on solaris */
 #include <sys/stat.h>
 #include <stdarg.h>
--- file-5.04.orig/src/file.c
+++ file-5.04/src/file.c
@@ -85,10 +85,6 @@
     "       %s -C [-m magicfiles]\n" \
     "       %s [--help]\n"
 
-#ifndef MAXPATHLEN
-#define	MAXPATHLEN	1024
-#endif
-
 private int 		/* Global command-line options 		*/
 	bflag = 0,	/* brief output format	 		*/
 	nopad = 0,	/* Don't pad output			*/
@@ -358,7 +354,13 @@
 private int
 unwrap(struct magic_set *ms, const char *fn)
 {
-	char buf[MAXPATHLEN];
+#ifdef __GLIBC__
+  static char * buf;
+  size_t dummy = 0;
+#else
+  char buf[MAXPATHLEN];
+#endif
+
 	FILE *f;
 	int wid = 0, cwid;
 	int e = 0;
@@ -372,8 +374,11 @@
 			    progname, fn, strerror(errno));
 			return 1;
 		}
-
+#ifdef __GLIBC__
+		while (getline(&buf, &dummy, f) != -1) {
+#else
 		while (fgets(buf, sizeof(buf), f) != NULL) {
+#endif
 			buf[strcspn(buf, "\n")] = '\0';
 			cwid = file_mbswidth(buf);
 			if (cwid > wid)
@@ -381,9 +386,13 @@
 		}
 
 		rewind(f);
-	}
+	 }
 
+#ifdef __GLIBC__
+	while (getline(&buf, &dummy, f) != -1) {
+#else
 	while (fgets(buf, sizeof(buf), f) != NULL) {
+#endif
 		buf[strcspn(buf, "\n")] = '\0';
 		e |= process(ms, buf, wid);
 		if(nobuffer)
@@ -391,5 +400,8 @@
 	}
 
 	(void)fclose(f);
+#ifdef __GLIBC__
+	free(buf);
+#endif
 	return e;
 }

Reply to: