-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing95.c
123 lines (107 loc) · 2.42 KB
/
missing95.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
popen and pclose are not part of win 95 and nt,
but it appears that _popen and _pclose "work".
if this won't load, use the return NULL statements.
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int pclose(FILE *f)
{
return _pclose(f); /* return NULL; */
}
size_t strlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return s - src - 1; /* count does not include NUL */
}
size_t strlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return dlen + strlen(s);
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return dlen + (s - src); /* count does not include NUL */
}
/**
* Maloc that causes process exit in case of ENOMEM
*/
void *xmalloc(size_t size)
{
void *p = calloc(size, 1);
if (p == 0) {
perror("malloc");
exit(1);
}
return p;
}
void *xcalloc(size_t number, size_t size)
{
void *p = calloc(number, size);
if (p == 0) {
perror("calloc");
exit(1);
}
return p;
}
void xfree(void *m)
{
if (m != 0)
free(m);
}
char *xucsdup(const wchar_t *wcs)
{
char *mbs;
int cch = WideCharToMultiByte(CP_UTF8, 0, wcs, -1, 0, 0, 0, 0);
if (cch == 0)
return NULL;
mbs = (char *)xmalloc(cch);
WideCharToMultiByte(CP_UTF8, 0, wcs, -1, mbs, cch, 0, 0);
return mbs;
}
FILE *ufopen(const char *f, const wchar_t *m)
{
wchar_t wf[8192];
if (MultiByteToWideChar(CP_UTF8, 0, f, -1, wf, 8192) == 0)
return NULL;
return _wfopen(wf, m);
}
FILE *upopen(const char *f, const wchar_t *m)
{
wchar_t wf[8192];
if (MultiByteToWideChar(CP_UTF8, 0, f, -1, wf, 8192) == 0)
return NULL;
return _wpopen(wf, m);
}