Use strtol()...thread safe and get rid of those ugly casts. And faster, too!
This commit is contained in:
parent
e209c4645f
commit
7a7994b41a
1 changed files with 11 additions and 9 deletions
20
phoned/cid.c
20
phoned/cid.c
|
@ -27,7 +27,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/cid.c,v 1.4 2005/06/18 20:40:15 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/cid.c,v 1.5 2005/06/18 20:51:29 dcp1990 Exp $ */
|
||||||
/* system includes */
|
/* system includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -54,13 +54,12 @@ cid_t* parse_cid(char* cidstring)
|
||||||
char cbyte, cbyte2;
|
char cbyte, cbyte2;
|
||||||
char bytebuf[10];
|
char bytebuf[10];
|
||||||
char date[7];
|
char date[7];
|
||||||
time_t rnow;
|
|
||||||
struct tm *ctm;
|
|
||||||
char cidtime[7];
|
char cidtime[7];
|
||||||
char name[128];
|
char name[128];
|
||||||
char phone[128];
|
char phone[128];
|
||||||
int cur = 0, sz, fbcou = 0;
|
int cur = 0, sz, fbcou = 0;
|
||||||
short int finl = 0;
|
short int finl = 0;
|
||||||
|
char *ct;
|
||||||
cid_t* c;
|
cid_t* c;
|
||||||
c = malloc(sizeof(cid_t));
|
c = malloc(sizeof(cid_t));
|
||||||
memset(msg, 0, sizeof msg);
|
memset(msg, 0, sizeof msg);
|
||||||
|
@ -72,19 +71,18 @@ cid_t* parse_cid(char* cidstring)
|
||||||
cidstring[strlen(cidstring)] = 0;
|
cidstring[strlen(cidstring)] = 0;
|
||||||
sz = strlen(cidstring);
|
sz = strlen(cidstring);
|
||||||
finl = (sz / 2) - 2;
|
finl = (sz / 2) - 2;
|
||||||
rnow = time(NULL);
|
strcpy(bytebuf, "0x");
|
||||||
ctm = localtime(&rnow);
|
|
||||||
for(cur = 0; cur <= sz; cur++) {
|
for(cur = 0; cur <= sz; cur++) {
|
||||||
cbyte = cidstring[cur++];
|
cbyte = cidstring[cur++];
|
||||||
cbyte2 = cidstring[cur];
|
cbyte2 = cidstring[cur];
|
||||||
sprintf(bytebuf, "0x%c%c", cbyte, cbyte2);
|
bytebuf[2] = cbyte; bytebuf[3] = cbyte2;
|
||||||
sscanf(bytebuf, "%X", (int*)&cch);
|
cch = strtol(bytebuf, NULL, 16);
|
||||||
if(cch == 0) continue;
|
if(cch == 0) continue;
|
||||||
if(fbcou <= finl) {
|
if(fbcou <= finl) {
|
||||||
finalbuf[fbcou] = cch;
|
finalbuf[fbcou] = cch;
|
||||||
fbcou++;
|
fbcou++;
|
||||||
} else break;
|
} else break;
|
||||||
memset(bytebuf, 0, sizeof(bytebuf));
|
/* perche? memset(bytebuf, 0, sizeof(bytebuf)); */
|
||||||
cbyte = 0;
|
cbyte = 0;
|
||||||
cbyte2 = 0;
|
cbyte2 = 0;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +156,11 @@ cid_t* parse_cid(char* cidstring)
|
||||||
#endif
|
#endif
|
||||||
c->name = strdup(name);
|
c->name = strdup(name);
|
||||||
c->number = strdup(phone);
|
c->number = strdup(phone);
|
||||||
sscanf(cidtime, "%d:%d", (int*)&c->hour, (int*)&c->minute);
|
ct = strchr(cidtime, ':');
|
||||||
|
if(ct != NULL) *ct = '\0';
|
||||||
|
c->hour = strtol(cidtime, NULL, 10);
|
||||||
|
c->minute = strtol(ct + 1, NULL, 10);
|
||||||
|
*ct = ':';
|
||||||
date[2] = 0x0;
|
date[2] = 0x0;
|
||||||
c->month = strtol(date, NULL, 10);
|
c->month = strtol(date, NULL, 10);
|
||||||
c->day = strtol(date + 3, NULL, 10);
|
c->day = strtol(date + 3, NULL, 10);
|
||||||
|
|
Loading…
Reference in a new issue