~kdsch/bl

f81b3582b6068486dde0f75aa01dfa0e1c106147 — Karl Schultheisz 2 years ago 113632c master
cut another syscall; avoid magic numbers

No need to bother the operating system to close the
file descriptor, because it will clean up after me.

Also, -1 is less readable than INDEX_INVALID.
1 files changed, 10 insertions(+), 7 deletions(-)

M lib.c
M lib.c => lib.c +10 -7
@@ 11,6 11,10 @@
#define BR (ROOT "brightness")
#define len(x) (sizeof(x)/sizeof(x[0]))

enum {
	INDEX_INVALID = -1,
};

/* magic numbers at which an increase in brightness
 * has been found to actually make a difference.
 * There are probably more, but these suffice. */


@@ 31,7 35,7 @@ index(unsigned x)
		}
	}

	return -1;
	return INDEX_INVALID;
}

static unsigned


@@ 40,7 44,7 @@ inc(unsigned x)
	unsigned y = rate.num * x / rate.den;
	int j = index(y);

	if (-1 == j) {
	if (INDEX_INVALID == j) {
		/* y is large; we don't care */
		return y;
	}


@@ 74,7 78,7 @@ dec(unsigned x)
	unsigned y = rate.den * x / rate.num;
	int j = index(y);

	if ((x && index(x) != j) || j == -1) {
	if ((x && index(x) != j) || j == INDEX_INVALID) {
		return y;
	}



@@ 116,9 120,8 @@ path_get(const char *pathname)
		die("path_get: open");
	}

	unsigned x = get(fd);
	close(fd);
	return x;
	return get(fd);
	// intentionally leaking fd
}

static void


@@ 139,7 142,7 @@ scale(char dir)
		break;
	}

	close(fd);
	// intentionally leaking fd
}

int