MCPcopy Create free account
hub / github.com/coreutils/coreutils / set_suffix_length

Function set_suffix_length

src/split.c:164–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164static void
165set_suffix_length (intmax_t n_units, enum Split_type split_type)
166{
167#define DEFAULT_SUFFIX_LENGTH 2
168
169 int suffix_length_needed = 0;
170
171 /* The suffix auto length feature is incompatible with
172 a user specified start value as the generated suffixes
173 are not all consecutive. */
174 if (numeric_suffix_start)
175 suffix_auto = false;
176
177 /* Auto-calculate the suffix length if the number of files is given. */
178 if (split_type == type_chunk_bytes || split_type == type_chunk_lines
179 || split_type == type_rr)
180 {
181 intmax_t n_units_end = n_units - 1;
182 if (numeric_suffix_start)
183 {
184 intmax_t n_start;
185 strtol_error e = xstrtoimax (numeric_suffix_start, NULL, 10,
186 &n_start, "");
187 if (e == LONGINT_OK && n_start < n_units)
188 {
189 /* Restrict auto adjustment so we don't keep
190 incrementing a suffix size arbitrarily,
191 as that would break sort order for files
192 generated from multiple split runs. */
193 if (ckd_add (&n_units_end, n_units_end, n_start))
194 n_units_end = INTMAX_MAX;
195 }
196
197 }
198 idx_t alphabet_len = strlen (suffix_alphabet);
199 do
200 suffix_length_needed++;
201 while (n_units_end /= alphabet_len);
202
203 suffix_auto = false;
204 }
205
206 if (suffix_length) /* set by user */
207 {
208 if (suffix_length < suffix_length_needed)
209 error (EXIT_FAILURE, 0,
210 _("the suffix length needs to be at least %d"),
211 suffix_length_needed);
212 suffix_auto = false;
213 return;
214 }
215 else
216 suffix_length = MAX (DEFAULT_SUFFIX_LENGTH, suffix_length_needed);
217}
218
219void
220usage (int status)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected