|
@@ -7,11 +7,52 @@
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <sys/syscall.h>
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
-
|
|
+#ifdef __NR_getcwd
|
|
-#ifndef __NR_getcwd
|
|
+#define __NR___getcwd __NR_getcwd
|
|
|
|
+static inline _syscall2(int, __getcwd, char *, buf, unsigned long, size);
|
|
|
|
|
|
|
|
+char *getcwd(char *buf, int size)
|
|
|
|
+{
|
|
|
|
+ int olderrno, ret;
|
|
|
|
+ char *allocbuf;
|
|
|
|
+
|
|
|
|
+ if (size == 0) {
|
|
|
|
+ __set_errno(EINVAL);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ if (size < 3) {
|
|
|
|
+ __set_errno(ERANGE);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ allocbuf=NULL;
|
|
|
|
+ olderrno = errno;
|
|
|
|
+ if (buf == NULL) {
|
|
|
|
+ buf = allocbuf = malloc (size);
|
|
|
|
+ if (buf == NULL)
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ ret = __getcwd(buf, size);
|
|
|
|
+ if (ret < 0) {
|
|
|
|
+ if (allocbuf) {
|
|
|
|
+ free(allocbuf);
|
|
|
|
+ }
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ __set_errno(olderrno);
|
|
|
|
+ return buf;
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * directory tree till we hit the root. Now we _could_
|
|
|
|
+ * use /proc/self/cwd if /proc is mounted... That approach
|
|
|
|
+ * is left an an exercise for the reader... */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
static char *search_dir(dev_t this_dev, ino_t this_ino, char *path_buf, int path_size)
|
|
static char *search_dir(dev_t this_dev, ino_t this_ino, char *path_buf, int path_size)
|
|
{
|
|
{
|