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

Function expandNextArg

popt/popt.c:647–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647static const char *
648expandNextArg(poptContext con, const char * s)
649{
650 const char * a = NULL;
651 char *t, *t_tmp, *te;
652 size_t tn = strlen(s) + 1;
653 char c;
654
655 te = t = malloc(tn);
656 if (t == NULL) return NULL; /* XXX can't happen */
657 *t = '\0';
658 while ((c = *s++) != '\0') {
659 switch (c) {
660#if 0 /* XXX can't do this */
661 case '\\': /* escape */
662 c = *s++;
663 break;
664#endif
665 case '!':
666 if (!(s[0] == '#' && s[1] == ':' && s[2] == '+'))
667 break;
668 /* XXX Make sure that findNextArg deletes only next arg. */
669 if (a == NULL) {
670 if ((a = findNextArg(con, 1U, 1)) == NULL)
671 break;
672 }
673 s += sizeof("#:+") - 1;
674
675 tn += strlen(a);
676 { size_t pos = (size_t) (te - t);
677 if ((t_tmp = realloc(t, tn)) == NULL) { /* XXX can't happen */
678 free(t);
679 return NULL;
680 }
681 t = t_tmp;
682 te = stpcpy(t + pos, a);
683 }
684 continue;
685 break;
686 default:
687 break;
688 }
689 *te++ = c;
690 }
691 *te++ = '\0';
692 /* If the new string is longer than needed, shorten. */
693 if ((t + tn) > te) {
694 if ((te = realloc(t, (size_t)(te - t))) == NULL)
695 free(t);
696 t = te;
697 }
698 return t;
699}
700
701static void poptStripArg(poptContext con, int which)
702{

Callers 1

poptGetNextOptFunction · 0.85

Calls 2

findNextArgFunction · 0.85
stpcpyFunction · 0.85

Tested by

no test coverage detected