-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompat.cpp
More file actions
90 lines (68 loc) · 1.83 KB
/
Copy pathcompat.cpp
File metadata and controls
90 lines (68 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Text Justify utility, Copyright (c) 2020 Yuriy Yakimenko
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/
#include "compat.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <wchar.h>
#ifndef _MSC_VER // MS compatibility adapters for "secure" functions.
void strerror_s(char *buffer, size_t bufLen, int err)
{
char *r = strerror_r (err, buffer, bufLen);
assert (r);
}
int fopen_s(FILE **fp, const char *name, const char *mode)
{
int ret = 0;
assert (fp);
*fp = fopen (name, mode);
if (!*fp)
ret = errno;
return ret;
}
int wcscat_s (wchar_t * dest, size_t dest_len, const wchar_t * src)
{
if (!src || !dest)
return EINVAL;
if (wcslen (src) >= dest_len)
return ERANGE;
wcscat (dest, src);
return 0;
}
int wcscpy_s( wchar_t * dest, size_t dest_len, const wchar_t * src)
{
if (!src || !dest)
return EINVAL;
if (wcslen (src) >= dest_len)
return ERANGE;
wcscpy (dest, src);
return 0;
}
int tmpnam_s(char* temp_name, size_t sizeInChars)
{
char buffer [PATH_MAX] ;
if (NULL == tmpnam(buffer))
return -1;
/* if (strlen (mktemp (buffer)) == 0)
return errno; */
if (strlen (buffer) >= sizeInChars)
{
return ERANGE;
}
if (temp_name == NULL)
{
return EINVAL;
}
strcpy (temp_name, buffer);
return 0;
}
#endif // _MSC_VER