2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
10 #include "native_client/src/shared/platform/nacl_error.h"
12 int NaClGetLastErrorString(char* buffer, size_t length) {
13 #if defined(__native_client__) || (NACL_LINUX && !NACL_ANDROID)
16 * Note some Linux distributions and newlib provide only the GNU version of
19 if (buffer == NULL || length == 0) {
23 message = strerror_r(errno, buffer, length);
24 if (message != buffer) {
25 size_t message_bytes = strlen(message) + 1;
26 if (message_bytes < length) {
27 length = message_bytes;
29 memmove(buffer, message, length);
30 buffer[length - 1] = '\0';
34 return strerror_r(errno, buffer, length);