merged volatile memory barriers
[cacao.git] / src / toolbox / util.c
index d74f704f0d3daa22b19c8e8eb4ed1abc59879c99..fc5a1c4b3696038f631ab257d1740abe72688c1b 100644 (file)
@@ -1,9 +1,7 @@
 /* src/toolbox/util.c - contains some utility functions
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
-
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Christian Thalinger
-
-   Changes:
-
-   $Id: util.c 2979 2005-07-11 09:59:37Z twisti $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 
+#include "config.h"
+
+#include <assert.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <unistd.h>
 
-#include "types.h"
-#include "mm/memory.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
+#include "vm/types.h"
 
+#include "mm/memory.hpp"
+#include "vm/vm.hpp"
 
-/* getcwd **********************************************************************
 
-   XXX
+/* get_variable_message_length *************************************************
+
+   This function simluates the print of a variable message and
+   determines so the message length;
 
 *******************************************************************************/
 
-char *_Jv_getcwd(void)
+int get_variable_message_length(const char *fmt, va_list ap)
 {
-       char *buf;
-       s4    size;
+       int n;
 
-       size = 1024;
+       n = vsnprintf(NULL, 0, fmt, ap);
 
-       buf = MNEW(char, size);
+#if defined(__IRIX__)
+       /* We know that IRIX returns -1 if the buffer is NULL */
 
-       while (buf) {
-               if (getcwd(buf, size) != NULL)
-                       return buf;
+       if (n == -1) {
+               char *p, *np;
+               s4    size;
 
-               MFREE(buf, char, size);
+               size = 100;                     /* start with 100-bytes               */
 
-               /* too small buffer or a more serious problem */
+               p = MNEW(char, size);
 
-               if (errno != ERANGE)
-                       throw_cacao_exception_exit(string_java_lang_InternalError,
-                                                                          strerror(errno));
+               while (1) {
+                       /* Try to print in the allocated space. */
 
-               /* double the buffer size */
+                       n = vsnprintf(p, size, fmt, ap);
 
-               size *= 2;
+                       /* If that worked, return the length. */
+                       if (n > -1 && n < size)
+                               return n;
 
-               buf = MNEW(char, size);
-       }
-
-       return NULL;
-}
+                       /* Else try again with more space. */
+                       size *= 2;  /* twice the old size */
 
+                       if ((np = MREALLOC(p, char, size, size)) == NULL) {
+                               assert(0);
+                       } else {
+                               p = np;
+                       }
+               }
+       }
+#endif
 
-/* get_variable_message_length *************************************************
-
-   This function simluates the print of a variable message and
-   determines so the message length;
-
-*******************************************************************************/
-
-int get_variable_message_length(const char *fmt, va_list ap)
-{
-       int len;
-
-       len = vsnprintf(NULL, 0, fmt, ap);
-
-       return len;
+       return n;
 }