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

Function getoptarg

src/pr.c:1169–1200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1167 a number. */
1168
1169static void
1170getoptarg (char *arg, char switch_char, char *character, int *number)
1171{
1172 if (!*arg)
1173 {
1174 error (0, 0, _("'-%c': Invalid argument: %s"), switch_char, quote (arg));
1175 usage (EXIT_FAILURE);
1176 }
1177
1178 if (!c_isdigit (*arg))
1179 *character = *arg++;
1180 if (*arg)
1181 {
1182 long int tmp_long;
1183 strtol_error e = xstrtol (arg, NULL, 10, &tmp_long, "");
1184 if (e == LONGINT_OK)
1185 {
1186 if (tmp_long <= 0)
1187 e = LONGINT_INVALID;
1188 else if (INT_MAX < tmp_long)
1189 e = LONGINT_OVERFLOW;
1190 }
1191 if (e != LONGINT_OK)
1192 {
1193 error (0, e & LONGINT_OVERFLOW ? EOVERFLOW : 0,
1194 _("'-%c' extra characters or invalid number in the argument: %s"),
1195 switch_char, quote (arg));
1196 usage (EXIT_FAILURE);
1197 }
1198 *number = tmp_long;
1199 }
1200}
1201
1202/* Set parameters related to formatting. */
1203

Callers 1

mainFunction · 0.85

Calls 1

usageFunction · 0.70

Tested by

no test coverage detected