summaryrefslogtreecommitdiff
path: root/libgammu/misc
diff options
context:
space:
mode:
Diffstat (limited to 'libgammu/misc')
-rw-r--r--libgammu/misc/coding/coding.c74
-rw-r--r--libgammu/misc/coding/coding.h20
-rw-r--r--libgammu/misc/misc.c16
-rw-r--r--libgammu/misc/misc.h6
4 files changed, 60 insertions, 56 deletions
diff --git a/libgammu/misc/coding/coding.c b/libgammu/misc/coding/coding.c
index e1b3a25..28f9f2e 100644
--- a/libgammu/misc/coding/coding.c
+++ b/libgammu/misc/coding/coding.c
@@ -279,9 +279,9 @@ char *DecodeUnicodeConsole(const unsigned char *src)
}
/* Encode string to Unicode. Len is number of input chars */
-void DecodeISO88591 (unsigned char *dest, const char *src, int len)
+void DecodeISO88591 (unsigned char *dest, const char *src, size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < len; i++) {
/* Hack for Euro sign */
@@ -298,9 +298,9 @@ void DecodeISO88591 (unsigned char *dest, const char *src, int len)
}
/* Encode string to Unicode. Len is number of input chars */
-void EncodeUnicode (unsigned char *dest, const char *src, int len)
+void EncodeUnicode (unsigned char *dest, const char *src, size_t len)
{
- int i_len = 0, o_len;
+ size_t i_len = 0, o_len;
wchar_t wc;
for (o_len = 0; i_len < len; o_len++) {
@@ -325,9 +325,10 @@ int DecodeWithBCDAlphabet(unsigned char value)
return 10*(value & 0x0f)+(value >> 4);
}
-void DecodeBCD (unsigned char *dest, const unsigned char *src, int len)
+void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current=0,digit;
+ size_t i,current=0;
+ int digit;
for (i = 0; i < len; i++) {
digit=src[i] & 0x0f;
@@ -338,9 +339,9 @@ void DecodeBCD (unsigned char *dest, const unsigned char *src, int len)
dest[current]=0;
}
-void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, gboolean fill)
+void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill)
{
- int i,current=0;
+ size_t i,current=0;
for (i = 0; i < len; i++) {
if (i & 0x01) {
@@ -407,9 +408,10 @@ void EncodeHexUnicode (char *dest, const unsigned char *src, size_t len)
EncodeHexBin(dest, src, len * 2);
}
-gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, int len)
+gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current=0, low, high;
+ size_t i,current=0;
+ int low, high;
for (i = 0; i < len/2 ; i++) {
low = DecodeWithHexBinAlphabet(src[i*2+1]);
@@ -828,7 +830,8 @@ static unsigned char ConvertTable[] =
void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
{
- size_t i,current=0,j,z;
+ size_t i,current=0;
+ int j,z;
char ret;
gboolean FoundSpecial,FoundNormal;
@@ -947,7 +950,7 @@ void FindDefaultAlphabetLen(const unsigned char *src, size_t *srclen, size_t *sm
#define ByteMask ((1 << Bits) - 1)
-int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
+int GSM_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length,
const unsigned char *input, unsigned char *output)
{
/* (c) by Pavel Janik and Pawel Kot */
@@ -955,11 +958,11 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
unsigned char *output_pos = output; /* Current pointer to the output buffer */
const unsigned char *input_pos = input; /* Current pointer to the input buffer */
unsigned char Rest = 0x00;
- int Bits;
+ size_t Bits;
Bits = offset ? offset : 7;
- while ((input_pos - input) < in_length) {
+ while ((size_t)(input_pos - input) < in_length) {
*output_pos = ((*input_pos & ByteMask) << (7 - Bits)) | Rest;
Rest = *input_pos >> Bits;
@@ -970,7 +973,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
if ((input_pos != input) || (Bits == 7)) output_pos++;
input_pos++;
- if ((output_pos - output) >= out_length) break;
+ if ((size_t)(output_pos - output) >= out_length) break;
/* After reading 7 octets we have read 7 full characters but
we have 7 bits as well. This is the next character */
@@ -987,7 +990,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
return output_pos - output;
}
-int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned char *output, int length)
+int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length)
{
/* (c) by Pavel Janik and Pawel Kot */
@@ -1004,7 +1007,7 @@ int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned ch
output_pos++;
}
- while ((input_pos - input) < length) {
+ while ((size_t)(input_pos - input) < length) {
unsigned char Byte = *input_pos;
*output_pos = Byte >> (7 - Bits);
@@ -1242,12 +1245,12 @@ void ReadUnicodeFile(unsigned char *Dest, const unsigned char *Source)
Dest[current] = 0;
}
-INLINE int GetBit(unsigned char *Buffer, size_t BitNum)
+int GetBit(unsigned char *Buffer, size_t BitNum)
{
return Buffer[BitNum / 8] & (1 << (7 - (BitNum % 8)));
}
-INLINE int SetBit(unsigned char *Buffer, size_t BitNum)
+int SetBit(unsigned char *Buffer, size_t BitNum)
{
return Buffer[BitNum / 8] |= 1 << (7 - (BitNum % 8));
}
@@ -1361,9 +1364,9 @@ void GetBufferI(unsigned char *Source,
* We replace single ~ chars into it. When user give double ~, it's replaced
* to single ~
*/
-void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
+void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i,current = 0;
+ size_t i,current = 0;
gboolean special=FALSE;
for (i = 0; i < len; i++) {
@@ -1395,9 +1398,9 @@ void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *sr
dest[current] = 0x00;
}
-void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
+void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i=0,current=0;
+ size_t i=0,current=0;
for (i=0;i<len;i++) {
switch (src[2*i]) {
@@ -1860,7 +1863,7 @@ gboolean EncodeUTF8(char *dest, const unsigned char *src)
}
/* Decode UTF8 char to Unicode char */
-int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len)
+int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len)
{
if (len < 1) return 0;
if (src[0] < 128) {
@@ -1883,9 +1886,9 @@ int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len)
/* Make Unicode string from ISO-8859-1 string */
-void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, int len)
+void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i = 0, j = 0;
+ size_t i = 0, j = 0;
while (i < len) {
if (src[i] == '=' && i + 2 < len
@@ -1905,9 +1908,10 @@ void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src
}
/* Make Unicode string from UTF8 string */
-void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len)
+void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, size_t len)
{
- int i,j=0,z;
+ size_t i,j=0;
+ int z;
unsigned char mychar[10];
wchar_t ret;
@@ -1940,9 +1944,9 @@ void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len)
dest[j] = 0;
}
-void DecodeUTF8(unsigned char *dest, const char *src, int len)
+void DecodeUTF8(unsigned char *dest, const char *src, size_t len)
{
- int i=0,j=0,z;
+ size_t i=0,j=0,z;
wchar_t ret;
while (i < len) {
@@ -1959,13 +1963,13 @@ void DecodeUTF8(unsigned char *dest, const char *src, int len)
dest[j] = 0;
}
-void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
+void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len)
{
char *tmp;
char *pos, *pos_end;
const char *lastpos;
char *entity;
- unsigned long int c;
+ unsigned long long int c;
int tmplen;
/* Allocate buffer */
@@ -2015,7 +2019,7 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
} else {
c = strtoull(entity + 1, NULL, 10);
}
- dbgprintf(NULL, "Unicode char 0x%04lx\n", c);
+ dbgprintf(NULL, "Unicode char 0x%04llx\n", c);
tmplen = strlen(tmp);
tmplen += EncodeWithUTF8Alphabet(c, tmp + tmplen);
tmp[tmplen] = 0;
@@ -2044,9 +2048,9 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len)
tmp=NULL;
}
-void DecodeUTF7(unsigned char *dest, const unsigned char *src, int len)
+void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len)
{
- int i=0,j=0,z,p;
+ size_t i=0,j=0,z,p;
wchar_t ret;
while (i<=len) {
diff --git a/libgammu/misc/coding/coding.h b/libgammu/misc/coding/coding.h
index 69de058..0800a1c 100644
--- a/libgammu/misc/coding/coding.h
+++ b/libgammu/misc/coding/coding.h
@@ -33,8 +33,8 @@ gboolean myiswspace (unsigned const char *src);
void ReverseUnicodeString (unsigned char *String);
-void DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, int len);
-void EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, int len);
+void DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
+void EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
unsigned char *EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
unsigned char *DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
@@ -43,21 +43,21 @@ unsigned char *DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned cha
unsigned char EncodeWithBCDAlphabet (int value);
int DecodeWithBCDAlphabet (unsigned char value);
-void DecodeBCD (unsigned char *dest, const unsigned char *src, int len);
-void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, gboolean fill);
+void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len);
+void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill);
/* ------------------------------ UTF7 ------------------------------------- */
-void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len);
+void DecodeUTF7 (unsigned char *dest, const unsigned char *src, size_t len);
/* ---------------------------- ISO88591 ----------------------------------- */
-void DecodeISO88591 (unsigned char *dest, const char *src, int len);
-void DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, int len);
+void DecodeISO88591 (unsigned char *dest, const char *src, size_t len);
+void DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, size_t len);
/**
* Decodes UTF-8 text with XML entities to Unicode.
*/
-void DecodeXMLUTF8(unsigned char *dest, const char *src, int len);
+void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len);
/* ------------------------------- BASE64 ---------------------------------- */
void EncodeBASE64 (const unsigned char *Input, char *Output, const size_t Length);
@@ -68,8 +68,8 @@ void EncodeDefault (unsigned char *dest, const unsigned char *src, size_t *l
void DecodeDefault (unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet);
void FindDefaultAlphabetLen (const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen);
-int GSM_PackSevenBitsToEight (int offset, const unsigned char *input, unsigned char *output, int length);
-int GSM_UnpackEightBitsToSeven (int offset, int in_length, int out_length,
+int GSM_PackSevenBitsToEight (size_t offset, const unsigned char *input, unsigned char *output, size_t length);
+int GSM_UnpackEightBitsToSeven (size_t offset, size_t in_length, size_t out_length,
const unsigned char *input, unsigned char *output);
/* ----------------- Phone numbers according to GSM specs ------------------ */
diff --git a/libgammu/misc/misc.c b/libgammu/misc/misc.c
index 8866d3a..ced397b 100644
--- a/libgammu/misc/misc.c
+++ b/libgammu/misc/misc.c
@@ -149,7 +149,7 @@ int GSM_GetLocalTimezoneOffset() {
gmtime_r(&now, &tg);
localtime_r(&now, &tl);
// Returns offset including daylight saving (found as boolean in tl.tm_isdst).
- return mktime(&tl) - mktime(&tg);
+ return (int)(mktime(&tl) - mktime(&tg));
}
void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str)
@@ -367,7 +367,7 @@ gboolean CheckTime(GSM_DateTime *date)
date->Second <= 59;
}
-int GetLine(FILE *File, char *Line, int count)
+size_t GetLine(FILE *File, char *Line, int count)
{
int num;
@@ -398,12 +398,12 @@ void FreeLines(GSM_CutLines *lines)
lines->retval = NULL;
}
-void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines,
- const char *whitespaces, const int spaceslen,
- const char *quotes, const int quoteslen,
+void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines,
+ const char *whitespaces, const size_t spaceslen,
+ const char *quotes, const size_t quoteslen,
const gboolean eot)
{
- int i=0,number=0,j=0, lastquote = -1;
+ size_t i=0,number=0,j=0, lastquote = 0;
gboolean whitespace = TRUE, nowwhite = FALSE, insidequotes = FALSE;
/* Clean current lines */
@@ -414,9 +414,9 @@ void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines,
/* Go through message */
for (i = 0; i < messagesize; i++) {
/* Reallocate buffer if needed */
- if (number + 1 >= lines->allocated - 1) {
+ if (number + 2 >= lines->allocated) {
lines->allocated += 20;
- lines->numbers = (int *)realloc(lines->numbers, lines->allocated * sizeof(int));
+ lines->numbers = (size_t *)realloc(lines->numbers, lines->allocated * sizeof(size_t));
if (lines->numbers == NULL) {
return;
}
diff --git a/libgammu/misc/misc.h b/libgammu/misc/misc.h
index f702589..7875635 100644
--- a/libgammu/misc/misc.h
+++ b/libgammu/misc/misc.h
@@ -35,11 +35,11 @@ typedef struct {
/**
* Cut points.
*/
- int *numbers;
+ size_t *numbers;
/**
* Number of currently allocated entries.
*/
- int allocated;
+ size_t allocated;
/**
* Storage for return value.
*/
@@ -49,7 +49,7 @@ typedef struct {
/**
* Calculates string cut points to split it to lines.
*/
-void SplitLines(const char *message, const int messagesize, GSM_CutLines *lines, const char *whitespaces, const int spaceslen, const char *quotes, const int quoteslen, const gboolean eot);
+void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines, const char *whitespaces, const size_t spaceslen, const char *quotes, const size_t quoteslen, const gboolean eot);
/**
* Returns pointer to static buffer containing line.