MCPcopy Create free account
hub / github.com/coreboot/coreboot / permute_args

Function permute_args

payloads/libpayload/libc/getopt_long.c:113–143  ·  view source on GitHub ↗

* Exchange the block from nonopt_start to nonopt_end with the block * from nonopt_end to opt_end (keeping the same order of arguments * in each block). */

Source from the content-addressed store, hash-verified

111 * in each block).
112 */
113static void
114permute_args(int panonopt_start, int panonopt_end, int opt_end,
115 char * const *nargv)
116{
117 int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
118 char *swap;
119
120 /*
121 * compute lengths of blocks and number and size of cycles
122 */
123 nnonopts = panonopt_end - panonopt_start;
124 nopts = opt_end - panonopt_end;
125 ncycle = gcd(nnonopts, nopts);
126 cyclelen = (opt_end - panonopt_start) / ncycle;
127
128 for (i = 0; i < ncycle; i++) {
129 cstart = panonopt_end+i;
130 pos = cstart;
131 for (j = 0; j < cyclelen; j++) {
132 if (pos >= panonopt_end)
133 pos -= nnonopts;
134 else
135 pos += nopts;
136 swap = nargv[pos];
137 /* LINTED const cast */
138 ((char **) nargv)[pos] = nargv[cstart];
139 /* LINTED const cast */
140 ((char **)nargv)[cstart] = swap;
141 }
142 }
143}
144
145/*
146 * parse_long_options --

Callers 1

getopt_internalFunction · 0.85

Calls 1

gcdFunction · 0.85

Tested by

no test coverage detected