summaryrefslogtreecommitdiff
path: root/debian/patches/ajoin.patch
blob: dcda59bd00b37347f52513ab0140639b3c040435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 00f493fb731f677e037baecded7b8fa066739ad6 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Tue, 3 Feb 2015 11:50:36 +0100
Subject: [PATCH hurd] XXX libdiskfs: avoid frequent asprintf in dir_lookup

---
 libdiskfs/dir-lookup.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/libdiskfs/dir-lookup.c b/libdiskfs/dir-lookup.c
index f3364cd..c1f7a68 100644
--- a/libdiskfs/dir-lookup.c
+++ b/libdiskfs/dir-lookup.c
@@ -26,6 +26,25 @@
 #include "priv.h"
 #include "fs_S.h"
 
+/* Join paths A and B.  The result is allocated using malloc.  */
+static inline char *
+ajoin (const char *a, const char *b)
+{
+  char *result;
+  size_t sa, sb;
+  sa = strlen (a);
+  sb = strlen (b);
+  result = malloc (sa + sb + 2);
+  if (result)
+    {
+      memcpy (result, a, sa);
+      result[sa] = '/';
+      memcpy (result + sa + 1, b, sb);
+      result[sa + sb + 1] = 0;
+    }
+  return result;
+}
+
 /* Implement dir_lookup as described in <hurd/fs.defs>. */
 kern_return_t
 diskfs_S_dir_lookup (struct protid *dircred,
@@ -331,7 +350,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 		      /* dircred is the root directory.  */
 		      complete_path = translator_path;
 		  else
-		      asprintf (&complete_path, "%s/%s", dircred->po->path, translator_path);
+		      complete_path = ajoin (dircred->po->path, translator_path);
 
 		  error = fshelp_set_active_translator (&newpi->pi,
 							complete_path,
@@ -535,10 +554,7 @@ diskfs_S_dir_lookup (struct protid *dircred,
 	  relpath = NULL; /* Do not free relpath.  */
 	}
       else
-	{
-	  newpi->po->path = NULL;
-	  asprintf (&newpi->po->path, "%s/%s", dircred->po->path, relpath);
-	}
+	newpi->po->path = ajoin (dircred->po->path, relpath);
 
       if (! newpi->po->path)
 	error = errno;
-- 
2.1.4