[Cbe-oss-dev] [PATCH 3/3] libspe2: add getcwd assist call

Patrick Mansfield patmans at us.ibm.com
Tue Jun 5 02:28:31 EST 2007


Add an assist call for:

	char *getcwd(char *buf, size_t size)

Signed-off-by: Patrick Mansfield <patmans at us.ibm.com>

Index: libspe2/spebase/default_posix1_handler.c
===================================================================
--- libspe2.orig/spebase/default_posix1_handler.c
+++ libspe2/spebase/default_posix1_handler.c
@@ -130,6 +130,7 @@ enum {
 	SPE_POSIX1_CHOWN,
 	SPE_POSIX1_FCHOWN,
 	SPE_POSIX1_LCHOWN,
+	SPE_POSIX1_GETCWD,
 	SPE_POSIX1_LAST_OPCODE,
 };
 #define SPE_POSIX1_NR_OPCODES	\
@@ -1458,6 +1459,44 @@ int default_posix1_handler_lchown(char *
     return 0;
 }
 
+/**
+ * default_posix1_handler_getcwd
+ * @ls: base pointer to local store area.
+ * @opdata: POSIX.1 call opcode & data.
+ *
+ * Implement:
+ *     char *getcwd(char *buf, size_t size)
+ */
+int default_posix1_handler_getcwd(char *ls, unsigned long opdata)
+{
+    DECL_2_ARGS();
+    DECL_RET();
+    char *buf;
+    size_t size;
+    char *res;
+    int rc;
+
+    DEBUG_PRINTF("%s\n", __func__);
+    if (arg1->slot[0] == 0) {
+        /*
+         * Do not support a NULL buf, since any allocations need to take
+         * place on the SPU.
+         */
+        PUT_LS_RC(0, 0, 0, EINVAL);
+        return 0;
+    }
+    buf = GET_LS_PTR(arg0->slot[0]);
+    size = arg1->slot[0];
+    res = getcwd(buf, size);
+    if (res == buf) {
+        rc = arg0->slot[0];
+    } else {
+        rc = 0;
+    }
+    PUT_LS_RC(rc, 0, 0, errno);
+    return 0;
+}
+
 int (*default_posix1_funcs[SPE_POSIX1_NR_OPCODES]) (char *, unsigned long) = {
 	[SPE_POSIX1_UNUSED]		= NULL,
 	[SPE_POSIX1_ADJTIMEX]		= default_posix1_handler_adjtimex,
@@ -1502,6 +1541,7 @@ int (*default_posix1_funcs[SPE_POSIX1_NR
 	[SPE_POSIX1_CHOWN]		= default_posix1_handler_chown,
 	[SPE_POSIX1_FCHOWN]		= default_posix1_handler_fchown,
 	[SPE_POSIX1_LCHOWN]		= default_posix1_handler_lchown,
+	[SPE_POSIX1_GETCWD]             = default_posix1_handler_getcwd,
 };
 
 /**
Index: libspe2/spebase/default_posix1_handler.h
===================================================================
--- libspe2.orig/spebase/default_posix1_handler.h
+++ libspe2/spebase/default_posix1_handler.h
@@ -65,5 +65,6 @@ extern int default_posix1_handler_fchmod
 extern int default_posix1_handler_chown(char *ls, unsigned long args);
 extern int default_posix1_handler_fchown(char *ls, unsigned long args);
 extern int default_posix1_handler_lchown(char *ls, unsigned long args);
+extern int default_posix1_handler_getcwd(char *ls, unsigned long args);
 
 #endif /* __DEFAULT_POSIX1_HANDLER_H__ */



More information about the cbe-oss-dev mailing list