* src/toolbox/util.c (_Jv_getcwd): Moved convenience function to os wrapper.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 15 Oct 2009 16:33:49 +0000 (18:33 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Thu, 15 Oct 2009 16:33:49 +0000 (18:33 +0200)
* src/toolbox/util.h: Likewise.
* src/vm/os.cpp: Likewise.
* src/vm/os.hpp (os::getcwd): Added system function wrapper.
* src/vm/properties.cpp (Properties::Properties): Adapted to above change.
* src/vm/suck.cpp (SuckClasspath::add): Likewise.

src/toolbox/util.c
src/toolbox/util.h
src/vm/os.cpp
src/vm/os.hpp
src/vm/properties.cpp
src/vm/suck.cpp

index 4adb970f5f00d0c0ffa97d1a37f8d8a6a13eedb0..fc5a1c4b3696038f631ab257d1740abe72688c1b 100644 (file)
 #include "vm/vm.hpp"
 
 
-/* _Jv_getcwd ******************************************************************
-
-   Return the current working directory.
-
-   RETURN VALUE:
-       pointer to a char array allocated by MNEW, or
-          NULL if memory could not be allocated.
-
-*******************************************************************************/
-
-char *_Jv_getcwd(void)
-{
-       char *buf;
-       s4    size;
-
-       size = 1024;
-
-       buf = MNEW(char, size);
-
-       while (buf) {
-               if (getcwd(buf, size) != NULL)
-                       return buf;
-
-               MFREE(buf, char, size);
-
-               /* too small buffer or a more serious problem */
-
-               if (errno != ERANGE)
-                       vm_abort("getcwd failed: %s", strerror(errno));
-
-               /* double the buffer size */
-
-               size *= 2;
-
-               buf = MNEW(char, size);
-       }
-
-       return NULL;
-}
-
-
 /* get_variable_message_length *************************************************
 
    This function simluates the print of a variable message and
index 659ab0eb967aaa913edacc8eb5544aad606fc82a..fd1143b6549351a9f49b49f650e58eb0495e3d34 100644 (file)
@@ -39,7 +39,6 @@
 extern "C" {
 #endif
 
-char *_Jv_getcwd(void);
 int   get_variable_message_length(const char *fmt, va_list ap);
 
 #ifdef __cplusplus
index dcfc08e8f3b20f817b9879c2cd32b82143b0ab3c..486bf67cb844d66ca2e062183f9a994324365708 100644 (file)
@@ -58,6 +58,8 @@
 /* this should work on BSD */
 /* #include <sys/sysctl.h> */
 
+#include "mm/memory.hpp"
+
 #include "vm/vm.hpp"
 
 
@@ -141,6 +143,40 @@ void os::abort_errno(const char* text, ...)
 }
 
 
+/**
+ * Return the current working directory.
+ *
+ * @return Pointer to a char array allocated by MNEW, or
+ *         NULL if memory could not be allocated.
+ */
+char* os::getcwd(void)
+{
+       int32_t size = 1024;
+
+       char* buf = MNEW(char, size);
+
+       while (buf != NULL) {
+               if (getcwd(buf, size) != NULL)
+                       return buf;
+
+               MFREE(buf, char, size);
+
+               /* too small buffer or a more serious problem */
+
+               if (errno != ERANGE)
+                       abort_errno("os::getcwd: getcwd failed");
+
+               /* double the buffer size */
+
+               size *= 2;
+
+               buf = MNEW(char, size);
+       }
+
+       return NULL;
+}
+
+
 /**
  * Maps anonymous memory, even on systems not defining
  * MAP_ANON(YMOUS).
index 2344b536a448ba030061cb0a2dac2087e2850208..c882a6d0fd4795a3d90ab441b1f593a13b25e921 100644 (file)
@@ -137,6 +137,7 @@ public:
        static inline int     fprintf(FILE* stream, const char* format, ...);
        static inline size_t  fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
        static inline void    free(void* ptr);
+       static inline char*   getcwd(char* buf, size_t size);
        static inline char*   getenv(const char* name);
        static inline int     gethostname(char* name, size_t len);
        static inline int     getloadavg(double loadavg[], int nelem);
@@ -170,6 +171,7 @@ public:
        static void  abort(const char* text, ...);
        static void  abort_errnum(int errnum, const char* text, ...);
        static void  abort_errno(const char* text, ...);
+       static char* getcwd(void);
        static void* mmap_anonymous(void *addr, size_t len, int prot, int flags);
        static void  print_backtrace();
        static int   processors_online();
@@ -379,6 +381,15 @@ inline static int system_ftruncate(int fd, off_t length)
 #endif
 }
 
+inline char* os::getcwd(char* buf, size_t size)
+{
+#if defined(HAVE_GETCWD)
+       return ::getcwd(buf, size);
+#else
+# error getcwd not available
+#endif
+}
+
 inline char* os::getenv(const char* name)
 {
 #if defined(HAVE_GETENV)
index e2f3858388d5e1cb33a64280c60d52102efe0ce4..c605efd658881a172dc66e796c3f6f4f59678887 100644 (file)
@@ -38,8 +38,6 @@
 
 #include "native/llni.h"
 
-#include "toolbox/util.h"
-
 #include "vm/class.hpp"
 #include "vm/global.h"
 #include "vm/method.hpp"
@@ -339,7 +337,7 @@ Properties::Properties()
 
        /* Get properties from system. */
 
-       char* cwd      = _Jv_getcwd();
+       char* cwd      = os::getcwd();
 
        char* env_user = os::getenv("USER");
        char* env_home = os::getenv("HOME");
index ecf0a70c3ee5ed2927469e430692661fe3d54b0e..ef43e92ff114f11e17c22fb075bc3a0bcaf2a335 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "toolbox/list.hpp"
 #include "toolbox/logging.hpp"
-#include "toolbox/util.h"
 
 #include "vm/exceptions.hpp"
 #include "vm/loader.hpp"
@@ -115,7 +114,7 @@ void SuckClasspath::add(char *classpath)
                        cwdlen = 0;
 
                        if (*start != '/') {                      /* XXX fix me for win32 */
-                               cwd = _Jv_getcwd();
+                               cwd = os::getcwd();
                                cwdlen = strlen(cwd) + strlen("/");
                        }