Changeset 5713

When converting an arg to a number remember it may have an exponent

Comitted by:  mjagdis
Date:  Jun 04 2010 * 23:11 (about 1 year ago)

Affected files:

callweaver/trunk/funcs/func_core.c (unified diff)

r5680r5713
2121 * \brief Core functions
2222 *
2323 */
24 #include <ctype.h>
25 #include <errno.h>
26 #include <fenv.h>
27 #include <math.h>
2428 #include <stdio.h>
2529 #include <stdlib.h>
30 #include <string.h>
2631 #include <unistd.h>
27 #include <string.h>
28 #include <ctype.h>
29 #include <errno.h>
3032
3133 #include "callweaver.h"
3234
------
6769 });
6870
6971
72 static int argtol(const char *arg, long double scale)
73 {
74 long double secs;
75 char *end;
76 int res = 0;
77
78 secs = strtold(arg, &end);
79 if (!*end && !isnan(secs)) {
80 res = INT_MAX;
81
82 if (!isinf(secs)) {
83 feclearexcept(FE_ALL_EXCEPT);
84 errno = 0;
85 res = lroundl(secs * scale);
86 if (errno || fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_UNDERFLOW))
87 res = 0;
88 else if (fetestexcept(FE_OVERFLOW))
89 res = INT_MAX;
90 }
91 }
92
93 return res;
94 }
95
96
7097 static void wait_for_hangup(struct cw_channel *chan, char *s)
7198 {
7299 struct cw_frame *f;
73100 int waittime;
74101
75 if (!s || !strlen(s) || (sscanf(s, "%d", &waittime) != 1) || (waittime < 0))
76 waittime = -1;
77 if (waittime > -1)
78 cw_safe_sleep(chan, waittime * 1000);
102 if (s && s[0] && (waittime = argtol(s, 1000)) >= 0)
103 cw_safe_sleep(chan, waittime);
79104 else {
80105 while (cw_waitfor(chan, -1) >= 0 && (f = cw_read(chan)))
81106 cw_fr_free(f);
------
302327
303328 static int pbx_builtin_answer(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result)
304329 {
305 int delay = (argc > 0 ? atoi(argv[0]) : 0);
330 int delay = (argc > 0 && argv[0][0] ? argtol(argv[0], 1) : 0);
306331 int res;
307
332
308333 CW_UNUSED(result);
309334
310335 if (chan->_state == CW_STATE_UP)
------
482507
483508 static int pbx_builtin_wait(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result)
484509 {
485 double ms;
510 int res = 0;
486511
487 CW_UNUSED(result);
512 CW_UNUSED(result);
488513
489 /* Wait for "n" seconds */
490 if (argc > 0 && (ms = atof(argv[0])))
491 return cw_safe_sleep(chan, (int)(ms * 1000.0));
492 return 0;
514 /* Wait for "n" seconds */
515 if (argc > 0 && argv[0][0])
516 res = cw_safe_sleep(chan, argtol(argv[0], 1000));
517
518 return 0;
493519 }
494520
495521 static int pbx_builtin_waitexten(struct cw_channel *chan, int argc, char **argv, struct cw_dynstr *result)