Fix strerror_r(3) range error case.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-09-25 15:30:27 +02:00
parent 0b1af77ca0
commit 0b085cbcf1
1 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library.
@ -30,7 +30,8 @@ extern "C" int strerror_r(int errnum, char* dest, size_t dest_len)
const char* msg = sortix_strerror(errnum);
if ( !msg )
return -1;
if ( strlcpy(dest, msg, dest_len) != strlen(msg) )
errno = ERANGE;
if ( dest_len < strlen(msg) + 1 )
return errno = ERANGE;
strcpy(dest, msg);
return 0;
}