/
| 317 | |
| 318 | /*****************************************************************************/ |
| 319 | char **pj_trim_argv (size_t argc, char *args) { |
| 320 | /****************************************************************************** |
| 321 | Create an argv-style array from elements placed in the argument string, args. |
| 322 | |
| 323 | args is a trimmed string as returned by pj_trim_argc(), and argc is the number |
| 324 | of trimmed strings found (i.e. the return value of pj_trim_args()). Hence, |
| 325 | int argc = pj_trim_argc (args); |
| 326 | char **argv = pj_trim_argv (argc, args); |
| 327 | will produce a classic style (argc, argv) pair from a string of whitespace |
| 328 | separated args. No new memory is allocated for storing the individual args |
| 329 | (they stay in the args string), but for the pointers to the args a new array |
| 330 | is allocated and returned. |
| 331 | |
| 332 | It is the duty of the caller to free this array. |
| 333 | ******************************************************************************/ |
| 334 | |
| 335 | if (nullptr==args) |
| 336 | return nullptr; |
| 337 | if (0==argc) |
| 338 | return nullptr; |
| 339 | |
| 340 | |
| 341 | /* turn the input string into an array of strings */ |
| 342 | char** argv = (char **) calloc (argc, sizeof (char *)); |
| 343 | if (nullptr==argv) |
| 344 | return nullptr; |
| 345 | for(size_t i = 0, j = 0; j < argc; j++) { |
| 346 | argv[j] = args + i; |
| 347 | char* str = argv[j]; |
| 348 | size_t nLen = strlen(str); |
| 349 | i += nLen + 1; |
| 350 | } |
| 351 | return argv; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | /*****************************************************************************/ |
no outgoing calls
no test coverage detected