Группа :: Система/Серверы
Пакет: ftpproxy
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: ftpproxy-1.2.3-alt-use_locale.patch
Скачать
Скачать
Fixed lower/upper case functions to use locale.
https://github.com/mpapierski/ftpproxy/commit/f606f57b47b3f286ea1ba5b50728d6f3cb9a313d
Author: Michaе┌ Papierski <michal@papierski.net>
Date: Sat Aug 23 13:38:44 2014 +0200
Previous version hardcoded some letters from alphabet and added its
own (most probably German special characters). This is better
because locale is used for the conversion.
--- src/lib.c
+++ src/lib.c
@@ -59,122 +59,33 @@ void *reallocate(void *p, size_t size)
return (p);
}
-
-
-static unsigned int lower[256], upper[256];
-
-static int _init_upper()
-{
- unsigned int c;
-
- DEBUG( fprintf (stderr, "init upper[]\n"); )
- for (c = 0; c < 256; c++)
- upper[c] = c;
-
- DEBUG( fprintf (stderr, "init uppercase letters\n"); )
- for (c = 'a'; c < 'z'+1; c++)
- upper[c] = 'A' + (c - 'a');
-
- DEBUG( fprintf (stderr, "init umlaute\n"); )
- upper[c = (unsigned char) 'Д'] = 'д';
- upper[c = (unsigned char) 'Ж'] = 'ж';
- upper[c = (unsigned char) 'Э'] = 'э';
-
- DEBUG( fprintf (stderr, "init upper[] complete\n"); )
- return (0);
-}
-
-static int _init_lower()
-{
- unsigned int c;
-
- DEBUG( fprintf (stderr, "init lower[]\n"); )
- for (c = 0; c < 256; c++)
- lower[c] = c;
-
- DEBUG( fprintf (stderr, "init uppercase letters\n"); )
- for (c = 'A'; c < 'Z'+1; c++)
- lower[c] = 'a' + (c - 'A');
-
- DEBUG( fprintf (stderr, "init umlaute\n"); )
- lower[c = (unsigned char) 'д'] = 'Д';
- lower[c = (unsigned char) 'ж'] = 'Ж';
- lower[c = (unsigned char) 'э'] = 'Э';
-
- DEBUG( fprintf (stderr, "init upper[] complete\n"); )
- return (0);
-}
-
-
-unsigned int uppercase(unsigned int c)
-{
- if (upper['0'] == 0)
- _init_upper();
-
- return (upper[c]);
-}
-
-int isuppercase(unsigned int c)
-{
- if (upper['0'] == 0)
- _init_upper();
-
- return (upper[c] == c);
-}
-
-unsigned int lowercase(unsigned int c)
-{
- if (lower['0'] == 0)
- _init_lower();
-
- return (lower[c]);
-}
-
-int islowercase(unsigned int c)
-{
- if (lower['0'] == 0)
- _init_lower();
-
- return (lower[c] == c);
-}
-
char *strlwr(char *string)
{
- unsigned int c;
- unsigned char *p;
+ int c;
- if (lower['0'] == 0)
- _init_lower();
-
- p = string;
- while ((c = *p) != 0) {
- *p++ = lower[c];
+ while ((c = *string) != 0) {
+ *string++ = tolower(c);
}
return (string);
-}
+}
char *strupr(char *string)
{
- unsigned int c;
- unsigned char *p;
+ int c;
- if (upper['0'] == 0)
- _init_upper();
-
- p = string;
- while ((c = *p) != 0) {
- *p++ = upper[c];
+ while ((c = *string) != 0) {
+ *string++ = toupper(c);
}
return (string);
-}
+}
char *skip_ws(char *string)
{
- unsigned int c;
+ int c;
- while ((c = *string) == ' ' || c == '\t')
+ while (isspace(c = *string))
string++;
return (string);
@@ -185,6 +95,7 @@ char *noctrl(char *buffer)
int len, i;
unsigned char *p;
+ // TODO: Use iscntrl here. iscntrl(32) returns 0 so figure out why space is converted to null byte too.
if ((p = buffer) == NULL)
return (NULL);
--- src/lib.h
+++ src/lib.h
@@ -32,10 +32,6 @@ extern int verbose;
void *allocate(size_t size);
void *reallocate(void *p, size_t size);
-unsigned int uppercase(unsigned int c);
-int isuppercase(unsigned int c);
-unsigned int lowercase(unsigned int c);
-int islowercase(unsigned int c);
char *strlwr(char *string);
char *strupr(char *string);
char *skip_ws(char *string);