Skip to content

Commit

Permalink
Linux: now str*_s functions return error codes according MSDN
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed Nov 9, 2018
1 parent 9eca63e commit f0fcf99
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Common/PlatformLinux.inl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ inline void _splitpath(const char* path, // Path Input
char* ext // Extension : Output
)
{
if(!path)
return EINVAL;

This comment has been minimized.

Copy link
@Zegeri

Zegeri Nov 14, 2018

Contributor

Returns EINVAL in a function that returns void.

This comment has been minimized.

Copy link
@eagleivg

eagleivg Nov 14, 2018

Author Contributor

Oops, my bad. Need set errno in EINVAL


const char *p, *end;

if(drive)
Expand Down Expand Up @@ -279,11 +282,15 @@ typedef dirent DirEntryType;
// error code numbers from original MS strcpy_s return value
inline int strcpy_s(char *dest, size_t num, const char *source)
{
if(!num)
return EINVAL;
if(!dest)
return EINVAL;

if(0 == num)
{
dest[0] = '\0';
return ERANGE;
}

if(!source)
{
dest[0] = '\0';
Expand All @@ -305,16 +312,20 @@ inline int strcpy_s(char (&dest)[num], const char *source) { return strcpy_s(des

inline int strncpy_s(char * dest, size_t dst_size, const char * source, size_t num)
{
if(!num)
{
if(dest && dst_size)
*dest = 0;
if (!dest || (0 == dst_size))
return EINVAL;

if(0 == num)
{
dest[0] = '\0';
return 0;
}

if (!dest || !source || (0 == dst_size))
if (!source)
{
dest[0] = '\0';
return EINVAL;
}

size_t i, end;
if(num < dst_size)
Expand All @@ -341,7 +352,7 @@ inline int strncpy_s(char (&dest)[dst_sz], const char * source, size_t num) { re

inline int strcat_s(char * dest, size_t num, const char * source)
{
if(!dest || (0 == num))
if(!dest)
return EINVAL;

if(!source)
Expand Down Expand Up @@ -369,15 +380,9 @@ inline int strcat_s(char * dest, size_t num, const char * source)

inline int strncat_s(char * dest, size_t num, const char * source, size_t count)
{
if (!dest || (0 == num))
if (!dest || !source)
return EINVAL;

if (!source)
{
dest[0] = '\0';
return EINVAL;
}

size_t i, j;
for(i = 0; i < num; i++)
{
Expand All @@ -394,7 +399,6 @@ inline int strncat_s(char * dest, size_t num, const char * source, size_t count)
}
}

dest[0] = '\0';
return ERANGE;
}

Expand Down

0 comments on commit f0fcf99

Please sign in to comment.