implemented write_int()
This commit is contained in:
parent
550fa7f18b
commit
73dc9bc0de
1 changed files with 21 additions and 11 deletions
30
ambientd.c
30
ambientd.c
|
|
@ -41,9 +41,11 @@ int get_luminance_raw (void)
|
||||||
|
|
||||||
// read a string from a file and convert it to int, should only be used for
|
// read a string from a file and convert it to int, should only be used for
|
||||||
// positive numbers since negative numbers mean an error
|
// positive numbers since negative numbers mean an error
|
||||||
int read_int(FILE *fp)
|
static int read_int(FILE *fp)
|
||||||
{
|
{
|
||||||
freopen(NULL, "r", fp);
|
if (freopen(NULL, "r", fp) == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
const char *p = fgets(STR_BUFFER, sizeof(STR_BUFFER), fp);
|
const char *p = fgets(STR_BUFFER, sizeof(STR_BUFFER), fp);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -55,7 +57,20 @@ int read_int(FILE *fp)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
float bezier(float t)
|
// write an intger value to a file as a string
|
||||||
|
static int write_int(FILE* fp, int value)
|
||||||
|
{
|
||||||
|
if (freopen(NULL, "w", fp) == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", value);
|
||||||
|
if (x <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return fputs(STR_BUFFER, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float bezier(float t)
|
||||||
{
|
{
|
||||||
const float B = 0.66;
|
const float B = 0.66;
|
||||||
const float D = 0.28;
|
const float D = 0.28;
|
||||||
|
|
@ -144,15 +159,10 @@ int main (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
brightness_adjusted = MIN(MAX(brightness_target + user_offset, min_brightness), max_brightness);
|
brightness_adjusted = MIN(MAX(brightness_target + user_offset, min_brightness), max_brightness);
|
||||||
// TODO: put this in write_int() function
|
x = write_int(brightness_fp, brightness_adjusted);
|
||||||
x = snprintf(STR_BUFFER, sizeof(STR_BUFFER), "%d", brightness_adjusted);
|
if (x < 0) {
|
||||||
if (x <= 0) {
|
|
||||||
fprintf(stderr, "Error in snprintf(): %s\n", strerror(errno));
|
|
||||||
}
|
|
||||||
if (fputs(STR_BUFFER, brightness_fp) == EOF) {
|
|
||||||
fprintf(stderr, "error writing brightness: %s\n", strerror(errno));
|
fprintf(stderr, "error writing brightness: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
rewind(brightness_fp);
|
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue