Skip to content

Commit f0fcf99

Browse files
committed
Linux: now str*_s functions return error codes according MSDN
1 parent 9eca63e commit f0fcf99

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Common/PlatformLinux.inl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ inline void _splitpath(const char* path, // Path Input
8484
char* ext // Extension : Output
8585
)
8686
{
87+
if(!path)
88+
return EINVAL;
89+
8790
const char *p, *end;
8891

8992
if(drive)
@@ -279,11 +282,15 @@ typedef dirent DirEntryType;
279282
// error code numbers from original MS strcpy_s return value
280283
inline int strcpy_s(char *dest, size_t num, const char *source)
281284
{
282-
if(!num)
283-
return EINVAL;
284285
if(!dest)
285286
return EINVAL;
286287

288+
if(0 == num)
289+
{
290+
dest[0] = '\0';
291+
return ERANGE;
292+
}
293+
287294
if(!source)
288295
{
289296
dest[0] = '\0';
@@ -305,16 +312,20 @@ inline int strcpy_s(char (&dest)[num], const char *source) { return strcpy_s(des
305312

306313
inline int strncpy_s(char * dest, size_t dst_size, const char * source, size_t num)
307314
{
308-
if(!num)
309-
{
310-
if(dest && dst_size)
311-
*dest = 0;
315+
if (!dest || (0 == dst_size))
316+
return EINVAL;
312317

318+
if(0 == num)
319+
{
320+
dest[0] = '\0';
313321
return 0;
314322
}
315323

316-
if (!dest || !source || (0 == dst_size))
324+
if (!source)
325+
{
326+
dest[0] = '\0';
317327
return EINVAL;
328+
}
318329

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

342353
inline int strcat_s(char * dest, size_t num, const char * source)
343354
{
344-
if(!dest || (0 == num))
355+
if(!dest)
345356
return EINVAL;
346357

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

370381
inline int strncat_s(char * dest, size_t num, const char * source, size_t count)
371382
{
372-
if (!dest || (0 == num))
383+
if (!dest || !source)
373384
return EINVAL;
374385

375-
if (!source)
376-
{
377-
dest[0] = '\0';
378-
return EINVAL;
379-
}
380-
381386
size_t i, j;
382387
for(i = 0; i < num; i++)
383388
{
@@ -394,7 +399,6 @@ inline int strncat_s(char * dest, size_t num, const char * source, size_t count)
394399
}
395400
}
396401

397-
dest[0] = '\0';
398402
return ERANGE;
399403
}
400404

0 commit comments

Comments
 (0)