summaryrefslogtreecommitdiff
path: root/libc/debian/patches/libc-add-get_current_dir_name.patch
blob: db52ebe24f7bfbc6d0a7e58a40cf7937906d7d2b (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Description: add get_current_dir_name() - the GNU extension
 We cannot add it to getcwd.c, because libc_pic.a goes to ld.so.1
 and it gets some functions multiple defined (e. g. malloc, read)
Index: b/usr/src/head/unistd.h
===================================================================
--- a/usr/src/head/unistd.h
+++ b/usr/src/head/unistd.h
@@ -335,6 +335,9 @@ extern int fsync(int);
 extern int ftruncate(int, off_t);
 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
 extern char *getcwd(char *, size_t);
+#if defined(_GNU_SOURCE) || defined(__EXTENSIONS__)
+char *get_current_dir_name(void);
+#endif
 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
 	defined(__EXTENSIONS__)
 extern int getdtablesize(void);
Index: b/usr/src/lib/libc/port/mapfile-vers
===================================================================
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -280,6 +280,7 @@ SYMBOL_VERSION DYSON_1 {
         fts_open;
         fts_read;
         fts_set;
+        get_current_dir_name;
         getgrouplist;
         gnu_strerror_r;
         mempcpy;
Index: b/usr/src/lib/libc/port/gen/get_current_dir_name.c
===================================================================
--- /dev/null
+++ b/usr/src/lib/libc/port/gen/get_current_dir_name.c
@@ -0,0 +1,39 @@
+
+/*
+Written by Igor Pashev <pashev.igor@gmail.com>
+
+The author has placed this work in the Public Domain,
+thereby relinquishing all copyrights. Everyone is free
+to use, modify, republish, sell or give away this work
+without prior consent from anybody.
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+char *
+get_current_dir_name (void)
+{
+  char *pwd, *cwd;
+  struct stat64 st1, st2;
+
+  pwd = getenv ("PWD");
+  if (pwd && !stat64 (".", &st1)
+      && !stat64 (pwd, &st2)
+      && (st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino))
+    return strdup (pwd);
+
+  cwd = getcwd (NULL, PATH_MAX);
+  if (cwd)
+    {
+      pwd = strdup (cwd);
+      free (cwd);
+      return pwd;
+    }
+
+  return NULL;
+}
Index: b/usr/src/lib/libc/i386/Makefile.com
===================================================================
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -428,6 +428,7 @@ PORTGEN=			\
 	fts.o			\
 	ftw.o			\
 	gcvt.o			\
+	get_current_dir_name.o		\
 	getauxv.o		\
 	getcwd.o		\
 	getdate_err.o		\
Index: b/usr/src/lib/libc/amd64/Makefile
===================================================================
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -396,6 +396,7 @@ PORTGEN=			\
 	fts.o			\
 	ftw.o			\
 	gcvt.o			\
+	get_current_dir_name.o		\
 	getauxv.o		\
 	getcwd.o		\
 	getdate_err.o		\