MCPcopy Create free account
hub / github.com/esnet/iperf / unit_atoi

Function unit_atoi

src/units.c:185–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183 * ------------------------------------------------------------------- */
184
185 iperf_size_t unit_atoi(const char *s)
186 {
187 double n;
188 char suffix = '\0';
189
190 assert(s != NULL);
191
192 /* scan the number and any suffices */
193 if (sscanf(s, "%lf%c", &n, &suffix) < 1) {
194 i_errno = IEUNITVAL;
195 errarg = s;
196 return 0;
197 }
198
199 /* convert according to [Tt Gg Mm Kk] */
200 switch (suffix)
201 {
202 case 't': case 'T':
203 n *= TERA_UNIT;
204 break;
205 case 'g': case 'G':
206 n *= GIGA_UNIT;
207 break;
208 case 'm': case 'M':
209 n *= MEGA_UNIT;
210 break;
211 case 'k': case 'K':
212 n *= KILO_UNIT;
213 break;
214 case '\0':
215 break;
216 default:
217 i_errno = IEUNITVAL;
218 errarg = s;
219 return 0;
220 }
221 return (iperf_size_t) n;
222 } /* end unit_atoi */
223
224/* -------------------------------------------------------------------
225 * constants for byte_printf

Callers 2

iperf_parse_argumentsFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…