MCPcopy Index your code
hub / github.com/RsyncProject/rsync / parse_arguments

Function parse_arguments

options.c:1361–2527  ·  view source on GitHub ↗

* Process command line arguments. Called on both local and remote. * * @retval 1 if all options are OK; with globals set to appropriate * values * * @retval 0 on error, with err_buf containing an explanation **/

Source from the content-addressed store, hash-verified

1359 * @retval 0 on error, with err_buf containing an explanation
1360 **/
1361int parse_arguments(int *argc_p, const char ***argv_p)
1362{
1363 poptContext pc;
1364 const char *arg, **argv = *argv_p;
1365 int argc = *argc_p;
1366 int opt, want_dest_type;
1367 int orig_protect_args = protect_args;
1368
1369 if (argc == 0) {
1370 strlcpy(err_buf, "argc is zero!\n", sizeof err_buf);
1371 return 0;
1372 }
1373
1374 set_refuse_options();
1375
1376#ifdef ICONV_OPTION
1377 if (!am_daemon && protect_args <= 0 && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)
1378 iconv_opt = strdup(arg);
1379#endif
1380
1381 /* TODO: Call poptReadDefaultConfig; handle errors. */
1382
1383 pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
1384 if (pc == NULL) {
1385 strlcpy(err_buf, "poptGetContext returned NULL\n", sizeof err_buf);
1386 return 0;
1387 }
1388 if (!am_server) {
1389 poptReadDefaultConfig(pc, 0);
1390 popt_unalias(pc, "--daemon");
1391 popt_unalias(pc, "--server");
1392 }
1393
1394 while ((opt = poptGetNextOpt(pc)) != -1) {
1395 /* most options are handled automatically by popt;
1396 * only special cases are returned and listed here. */
1397
1398 switch (opt) {
1399 case 'V':
1400 version_opt_cnt++;
1401 break;
1402
1403 case OPT_SERVER:
1404 if (!am_server) {
1405 /* Disable popt aliases on the server side and
1406 * then start parsing the options again. */
1407 poptFreeContext(pc);
1408 pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
1409 am_server = 1;
1410 }
1411#ifdef ICONV_OPTION
1412 iconv_opt = NULL;
1413#endif
1414 break;
1415
1416 case OPT_SENDER:
1417 if (!am_server) {
1418 usage(FERROR);

Callers 3

local_childFunction · 0.85
mainFunction · 0.85
rsync_moduleFunction · 0.85

Calls 15

strlcpyFunction · 0.85
set_refuse_optionsFunction · 0.85
poptGetContextFunction · 0.85
poptReadDefaultConfigFunction · 0.85
popt_unaliasFunction · 0.85
poptGetNextOptFunction · 0.85
poptFreeContextFunction · 0.85
usageFunction · 0.85
daemon_usageFunction · 0.85
poptGetOptArgFunction · 0.85
poptBadOptionFunction · 0.85
poptStrerrorFunction · 0.85

Tested by

no test coverage detected