mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-16 03:19:54 +08:00
1f232abc89
compiler warnings found this way. * libc/stdio/freopen.c (_freopen_r): Fix bug setting _flags. * libc/include/stdio.h (_rename): Define when building newlib. * libc/include/sys/signal.h (_kill): Ditto. * libc/include/sys/stat.h (_mkdir): Ditto. * libc/include/sys/time.h (_gettimeofday): Ditto. * libc/include/sys/times.h (_times): Ditto. * libc/include/sys/wait.h (_wait): Ditto. * libc/locale/lmessages.c (empty): Don't define for Cygwin. * libc/locale/lmonetary.c (cnv): Ditto. * libc/locale/nl_langinfo.c (nl_langinfo): Ditto for variable s. * libc/posix/collate.c: Throughout cast to avoid compiler warning. * libc/posix/engine.c (matcher): Initialize dp to avoid compiler warning. * libc/posix/glob.c: Disable on Cygwin. Explain why. * libc/posix/regcomp.c: Fix "uninitialized" compiler warnings. (dissect): Deliberately silence gcc compiler warning. Add comment to explain why. * libc/posix/wordexp.c (wordexp): Remove num_bytes variable since result is never used. * libc/posix/popen.c (popen): Ditto for variable last. * libc/reent/mkdirr.c: Include sys/stat.h. * libc/reent/renamer.c: Include stdio.h. * libc/search/hash.c: Throughout use underscored variants of the stat function family. (init_hash): Add missing definition for the __USE_INTERNAL_STAT64 case. * libc/search/hash_bigkey.c (__big_insert): Add parenthesis to avoid compiler warning. * libc/search/hash_page.c (overflow_page): Initalize freep to NULL to avoid compiler warning. * libc/stdio/asiprintf.c (_asiprintf_r): Cast unsigned char * to char * to avoid compiler warning. (asiprintf): Ditto. * libc/stdio/asprintf.c (_asprintf_r): Ditto. (asprintf): Ditto. * libc/stdio/vasiprintf.c (_vasiprintf_r): Ditto. * libc/stdio/vasprintf.c (_vasprintf_r): Ditto. * libc/stdio/mktemp.c (_gettemp): Cast to unsigned char in call to isdigit to avoid compiler warning. * libc/stdio/vfprintf.c (_VFPRINTF_R): Initialize variables used for grouping to avoid compiler warning. Only define and set nseps and nrepeats if they are really used. * libc/stdio/vfwprintf.c (_VFWPRINTF_R): Ditto. Only define state if it is really used. * libc/stdio/vfscanf.c (u_char): Revert to be defined as unsigned char. (__SVFSCANF_R): Cast fmt in call to __mbtowc. * libc/stdlib/mbtowc_r.c (JIS_state_table): Disable when building Cygwin. (JIS_action_table): Ditto. * libc/stdlib/wctomb_r.c (__utf8_wctomb): Add parenthesis to avoid compiler warning. * libc/string/strcasestr.c: Deliberately silence gcc compiler warning. Add comment to explain why. * libc/time/strptime.c (strptime): Cast to unsigned char in calls to isspace to avoid compiler warning. * libm/math/e_atan2.c (__ieee754_atan2): Add parenthesis to avoid compiler warning. * libm/math/e_exp.c (__ieee754_exp): Initialize k to 0 to avoid compiler warning. Drop setting it to 0 later. * libm/math/ef_exp.c (__ieee754_expf): Ditto. * libm/math/e_pow.c (__ieee754_pow): Add braces to avoid compiler warning. * libm/math/ef_pow.c (__ieee754_powf): Ditto. * libm/math/er_lgamma.c (__ieee754_lgamma_r): Initialize nadj to 0 to avoid compiler warning. * libm/math/erf_lgamma.c (__ieee754_lgammaf_r): Ditto. * libm/math/e_rem_pio2.c (__ieee754_rem_pio2): Ditto for variable z. * libm/common/sf_round.c (roundf): Remove signbit variable since result is never used.
216 lines
5.8 KiB
C
216 lines
5.8 KiB
C
/*-
|
|
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
|
|
* at Electronni Visti IA, Kiev, Ukraine.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
#include <rune.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <sysexits.h>
|
|
#include "un-namespace.h"
|
|
|
|
#include "collate.h"
|
|
|
|
extern char *_PathLocale;
|
|
int __collate_load_error = 1;
|
|
int __collate_substitute_nontrivial;
|
|
char __collate_version[STR_LEN];
|
|
u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
|
|
struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
|
|
struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE];
|
|
|
|
#define FREAD(a, b, c, d) \
|
|
do { \
|
|
if (fread(a, b, c, d) != c) { \
|
|
fclose(d); \
|
|
return -1; \
|
|
} \
|
|
} while(0)
|
|
|
|
void __collate_err(int ex, const char *f);
|
|
|
|
int
|
|
__collate_load_tables(encoding)
|
|
char *encoding;
|
|
{
|
|
char buf[PATH_MAX];
|
|
FILE *fp;
|
|
int i, save_load_error;
|
|
|
|
save_load_error = __collate_load_error;
|
|
__collate_load_error = 1;
|
|
if (!encoding) {
|
|
__collate_load_error = save_load_error;
|
|
return -1;
|
|
}
|
|
if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
|
|
return 0;
|
|
if (!_PathLocale) {
|
|
__collate_load_error = save_load_error;
|
|
return -1;
|
|
}
|
|
/* Range checking not needed, encoding has fixed size */
|
|
(void) strcpy(buf, _PathLocale);
|
|
(void) strcat(buf, "/");
|
|
(void) strcat(buf, encoding);
|
|
(void) strcat(buf, "/LC_COLLATE");
|
|
if ((fp = fopen(buf, "r")) == NULL) {
|
|
__collate_load_error = save_load_error;
|
|
return -1;
|
|
}
|
|
FREAD(__collate_version, sizeof(__collate_version), 1, fp);
|
|
if (strcmp(__collate_version, COLLATE_VERSION) != 0) {
|
|
fclose(fp);
|
|
return -1;
|
|
}
|
|
FREAD(__collate_substitute_table, sizeof(__collate_substitute_table),
|
|
1, fp);
|
|
FREAD(__collate_char_pri_table, sizeof(__collate_char_pri_table), 1,
|
|
fp);
|
|
FREAD(__collate_chain_pri_table, sizeof(__collate_chain_pri_table), 1,
|
|
fp);
|
|
fclose(fp);
|
|
__collate_load_error = 0;
|
|
|
|
__collate_substitute_nontrivial = 0;
|
|
for (i = 0; i < UCHAR_MAX + 1; i++) {
|
|
if (__collate_substitute_table[i][0] != i ||
|
|
__collate_substitute_table[i][1] != 0) {
|
|
__collate_substitute_nontrivial = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
u_char *
|
|
__collate_substitute(s)
|
|
const u_char *s;
|
|
{
|
|
int dest_len, len, nlen;
|
|
int delta = strlen((const char *) s);
|
|
u_char *dest_str = NULL;
|
|
|
|
if(s == NULL || *s == '\0')
|
|
return __collate_strdup((u_char *) "");
|
|
delta += delta / 8;
|
|
dest_str = (u_char *) malloc(dest_len = delta);
|
|
if(dest_str == NULL)
|
|
__collate_err(EX_OSERR, __FUNCTION__);
|
|
len = 0;
|
|
while(*s) {
|
|
nlen = len + strlen((const char *)
|
|
__collate_substitute_table[*s]);
|
|
if (dest_len <= nlen) {
|
|
dest_str = reallocf(dest_str, dest_len = nlen + delta);
|
|
if(dest_str == NULL)
|
|
__collate_err(EX_OSERR, __FUNCTION__);
|
|
}
|
|
strcpy((char *) dest_str + len,
|
|
(const char *) __collate_substitute_table[*s++]);
|
|
len = nlen;
|
|
}
|
|
return dest_str;
|
|
}
|
|
|
|
void
|
|
__collate_lookup(t, len, prim, sec)
|
|
const u_char *t;
|
|
int *len, *prim, *sec;
|
|
{
|
|
struct __collate_st_chain_pri *p2;
|
|
|
|
*len = 1;
|
|
*prim = *sec = 0;
|
|
for(p2 = __collate_chain_pri_table; p2->str[0]; p2++) {
|
|
if(strncmp((const char *) t, (const char *) p2->str,
|
|
strlen((const char *) p2->str)) == 0) {
|
|
*len = strlen((const char *) p2->str);
|
|
*prim = p2->prim;
|
|
*sec = p2->sec;
|
|
return;
|
|
}
|
|
}
|
|
*prim = __collate_char_pri_table[*t].prim;
|
|
*sec = __collate_char_pri_table[*t].sec;
|
|
}
|
|
|
|
u_char *
|
|
__collate_strdup(s)
|
|
u_char *s;
|
|
{
|
|
u_char *t = (u_char *) strdup((const char *) s);
|
|
|
|
if (t == NULL)
|
|
__collate_err(EX_OSERR, __FUNCTION__);
|
|
return t;
|
|
}
|
|
|
|
void
|
|
__collate_err(int ex, const char *f)
|
|
{
|
|
const char *s;
|
|
int serrno = errno;
|
|
int dummy;
|
|
|
|
/* Be careful to change write counts if you change the strings */
|
|
write(STDERR_FILENO, "collate_error: ", 15);
|
|
write(STDERR_FILENO, f, strlen(f));
|
|
write(STDERR_FILENO, ": ", 2);
|
|
s = _strerror_r(_REENT, serrno, 1, &dummy);
|
|
write(STDERR_FILENO, s, strlen(s));
|
|
write(STDERR_FILENO, "\n", 1);
|
|
exit(ex);
|
|
}
|
|
|
|
#ifdef COLLATE_DEBUG
|
|
void
|
|
__collate_print_tables()
|
|
{
|
|
int i;
|
|
struct __collate_st_chain_pri *p2;
|
|
|
|
printf("Substitute table:\n");
|
|
for (i = 0; i < UCHAR_MAX + 1; i++)
|
|
if (i != *__collate_substitute_table[i])
|
|
printf("\t'%c' --> \"%s\"\n", i,
|
|
__collate_substitute_table[i]);
|
|
printf("Chain priority table:\n");
|
|
for (p2 = __collate_chain_pri_table; p2->str[0]; p2++)
|
|
printf("\t\"%s\" : %d %d\n\n", p2->str, p2->prim, p2->sec);
|
|
printf("Char priority table:\n");
|
|
for (i = 0; i < UCHAR_MAX + 1; i++)
|
|
printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim,
|
|
__collate_char_pri_table[i].sec);
|
|
}
|
|
#endif
|