src/java.base/unix/native/libjava/jni_util_md.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -21,10 +21,11 @@
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+#include <errno.h>
#include <string.h>
#include "jni.h"
#include "jni_util.h"
#include "dlfcn.h"
@@ -49,5 +50,19 @@
strcat(jniEntryName, "_");
strcat(jniEntryName, cname);
}
}
+size_t
+getLastErrorString(char *buf, size_t len)
+{
+ if (errno == 0 || len < 1) return 0;
+
+ const char *err = strerror(errno);
+ size_t n = strlen(err);
+ if (n >= len)
+ n = len - 1;
+
+ strncpy(buf, err, n);
+ buf[n] = '\0';
+ return n;
+}