summaryrefslogtreecommitdiff
path: root/libc/debian/patches/libc-add-get_current_dir_name.patch
blob: fad82dbda6300ae4fc0351fb4df7ea660aa16ad4 (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	2014-03-02 23:23:33.560744425 +0400
+++ b/usr/src/head/unistd.h	2014-03-02 23:24:19.242793108 +0400
@@ -336,6 +336,9 @@
 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	2014-03-02 23:24:11.652848232 +0400
+++ b/usr/src/lib/libc/port/mapfile-vers	2014-03-02 23:24:19.248906611 +0400
@@ -138,6 +138,7 @@
         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	1970-01-01 00:00:00.000000000 +0000
+++ b/usr/src/lib/libc/port/gen/get_current_dir_name.c	2014-03-02 23:24:19.251471523 +0400
@@ -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	2014-03-02 23:24:11.646472983 +0400
+++ b/usr/src/lib/libc/i386/Makefile.com	2014-03-02 23:24:19.254038108 +0400
@@ -415,6 +415,7 @@
 	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	2014-03-02 23:24:11.648948976 +0400
+++ b/usr/src/lib/libc/amd64/Makefile	2014-03-02 23:24:19.256268158 +0400
@@ -385,6 +385,7 @@
 	fts.o			\
 	ftw.o			\
 	gcvt.o			\
+	get_current_dir_name.o		\
 	getauxv.o		\
 	getcwd.o		\
 	getdate_err.o		\