* 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.
#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
extern "C" {
#endif
-char *_Jv_getcwd(void);
int get_variable_message_length(const char *fmt, va_list ap);
#ifdef __cplusplus
/* this should work on BSD */
/* #include <sys/sysctl.h> */
+#include "mm/memory.hpp"
+
#include "vm/vm.hpp"
}
+/**
+ * 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).
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);
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();
#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)
#include "native/llni.h"
-#include "toolbox/util.h"
-
#include "vm/class.hpp"
#include "vm/global.h"
#include "vm/method.hpp"
/* Get properties from system. */
- char* cwd = _Jv_getcwd();
+ char* cwd = os::getcwd();
char* env_user = os::getenv("USER");
char* env_home = os::getenv("HOME");
#include "toolbox/list.hpp"
#include "toolbox/logging.hpp"
-#include "toolbox/util.h"
#include "vm/exceptions.hpp"
#include "vm/loader.hpp"
cwdlen = 0;
if (*start != '/') { /* XXX fix me for win32 */
- cwd = _Jv_getcwd();
+ cwd = os::getcwd();
cwdlen = strlen(cwd) + strlen("/");
}