From 492795c4c890b0ed34eb4df190ed0376e9f01df9 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 19 Jun 2009 08:38:24 -0500 Subject: [PATCH] Add utility function --- src/smsutil.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/smsutil.c b/src/smsutil.c index d6147681..6d4ac127 100644 --- a/src/smsutil.c +++ b/src/smsutil.c @@ -1933,6 +1933,11 @@ unsigned char *sms_decode_datagram(GSList *sms_list, long *out_len) return buf; } +static inline int sms_text_capacity_gsm(int max, int offset) +{ + return max - (offset * 8 + 6) / 7; +} + /*! * Decodes a list of SMSes that contain a text in either 7bit or UCS2 encoding. * The list must be sorted in order of the sequence number. This function @@ -1985,7 +1990,7 @@ char *sms_decode_text(GSList *sms_list) if (charset == SMS_CHARSET_7BIT) { unsigned char buf[160]; long written; - int max_chars = udl - (taken * 8 + 6) / 7; + int max_chars = sms_text_capacity_gsm(udl, taken); unpack_7bit_own_buf(ud + taken, udl_in_bytes - taken, taken, FALSE, max_chars,