CONFIG

Denys Vlasenko vda.linux at googlemail.com
Sun Jul 20 18:07:42 UTC 2008


On Sunday 20 July 2008 19:24, dronnikov at gmail.com wrote:
> login: shrink /etc/securetty parsing code; -120 bytes.
> Please consider applying.

-	fp = fopen("/etc/securetty", "r");
-	if (!fp) {
-		/* A missing securetty file is not an error. */
-		return 1;
-	}
-	while (fgets(buf, sizeof(buf)-1, fp)) {
-		for (i = strlen(buf)-1; i >= 0; --i) {
-			if (!isspace(buf[i]))
+	char *buf;
+	int ret = 1;
+	parser_t *parser = config_open("/etc/securetty");
+	/* N.B. A missing securetty file is not an error. */
+	if (parser) {

Regression: config_open() uses fopen_or_warn_stdin().
I.e. now getty will always moan about "/etc/securetty" not found.
Looks like config_open() needs a param.

Hmm. The param can be "FILE* FAST_FUNC (*fopen_func)(const char *)" -
which fopen-class function to use:
- xfopen?
- fopen?
- fopen_or_warn_stdin?

Since first two do not match prototype, you will need to introduce
xfopen_for_read() and fopen_for_read(), which are useful anyway -
we can use those instead of longer xfopen():

	fopen(name, "r") // non FAST_FUNC, and more params
	fopen_for_read(name) // smaller!

and we have a lot of "r" fopens!
Can you submit a fixed version?
--
vda



More information about the busybox mailing list