]>
sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/miscfuncs.cc
1 /* miscfuncs.cc: misc funcs that don't belong anywhere else
3 Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #include <sys/errno.h>
22 const char case_folded_lower
[] NO_COPY
= {
23 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
24 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
25 32, '!', '"', '#', '$', '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
26 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
27 '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
28 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', 92, ']', '^', '_',
29 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
30 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 127,
31 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
32 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
33 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
34 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
35 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
36 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
37 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
38 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
41 const char case_folded_upper
[] NO_COPY
= {
42 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
43 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
44 32, '!', '"', '#', '$', '%', '&', 39, '(', ')', '*', '+', ',', '-', '.', '/',
45 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
46 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
47 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', 92, ']', '^', '_',
48 '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
49 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127,
50 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
51 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
52 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
53 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
54 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
55 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
56 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
57 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
60 #define ch_case_eq(ch1, ch2) (cyg_tolower(ch1) == cyg_tolower(ch2))
62 /* Return TRUE if two strings match up to length n */
63 extern "C" int __stdcall
64 strncasematch (const char *s1
, const char *s2
, size_t n
)
72 if (!ch_case_eq (*s1
, *s2
))
76 return !n
|| *s2
== '\0';
79 /* Return TRUE if two strings match */
80 extern "C" int __stdcall
81 strcasematch (const char *s1
, const char *s2
)
88 if (!ch_case_eq (*s1
, *s2
))
95 extern "C" char * __stdcall
96 strcasestr (const char *searchee
, const char *lookfor
)
102 return (char *) searchee
;
111 return (char *) searchee
;
113 if (!ch_case_eq (lookfor
[i
], searchee
[i
]))
124 check_null_str (const char *name
)
126 if (name
&& !IsBadStringPtr (name
, MAX_PATH
))
133 check_null_empty_str (const char *name
)
135 if (name
&& !IsBadStringPtr (name
, MAX_PATH
))
136 return !*name
? ENOENT
: 0;
142 check_null_empty_str_errno (const char *name
)
145 if ((__err
= check_null_empty_str (name
)))
151 check_null_str_errno (const char *name
)
154 if ((__err
= check_null_str (name
)))
160 __check_null_invalid_struct (void *s
, unsigned sz
)
162 if (s
&& !IsBadWritePtr (s
, sz
))
169 __check_null_invalid_struct_errno (void *s
, unsigned sz
)
172 if ((err
= __check_null_invalid_struct (s
, sz
)))
178 __check_invalid_read_ptr_errno (const void *s
, unsigned sz
)
180 if (s
&& !IsBadReadPtr (s
, sz
))
182 return set_errno (EFAULT
);
186 check_iovec_for_read (const struct iovec
*iov
, int iovcnt
)
188 if (iovcnt
<= 0 || iovcnt
> IOV_MAX
)
194 if (__check_invalid_read_ptr_errno (iov
, iovcnt
* sizeof (*iov
)))
201 if (iov
->iov_len
> SSIZE_MAX
|| (tot
+= iov
->iov_len
) > SSIZE_MAX
)
208 && __check_null_invalid_struct_errno (iov
->iov_base
, iov
->iov_len
))
215 assert (tot
<= SSIZE_MAX
);
217 return (ssize_t
) tot
;
221 check_iovec_for_write (const struct iovec
*iov
, int iovcnt
)
223 if (iovcnt
<= 0 || iovcnt
> IOV_MAX
)
229 if (__check_invalid_read_ptr_errno (iov
, iovcnt
* sizeof (*iov
)))
236 if (iov
->iov_len
> SSIZE_MAX
|| (tot
+= iov
->iov_len
) > SSIZE_MAX
)
243 && __check_invalid_read_ptr_errno (iov
->iov_base
, iov
->iov_len
))
250 assert (tot
<= SSIZE_MAX
);
252 return (ssize_t
) tot
;
258 return current_codepage
== ansi_cp
? GetACP() : GetOEMCP();
262 sys_wcstombs (char *tgt
, const WCHAR
*src
, int len
)
264 return WideCharToMultiByte (get_cp (), 0, src
, -1, tgt
, len
, NULL
, NULL
);
268 sys_mbstowcs (WCHAR
*tgt
, const char *src
, int len
)
270 return MultiByteToWideChar (get_cp (), 0, src
, -1, tgt
, len
);
This page took 0.052093 seconds and 5 git commands to generate.