1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
.\" vi: tw=80
.\"
.\" BSD Zero Clause License
.\"
.\" Copyright (c) 2022 Thomas Voss
.\"
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
.\" AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
.\" OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
.\" PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: October 12 2022 $
.Dt LUXINIT 3
.Os
.Sh NAME
.Nm luxinit ,
.Nm luxfree
.Nd initialise and destroy a lux_t object
.Sh LIBRARY
.Lb liblux
.Sh SYNOPSIS
.In lux.h
.Ft int
.Fn luxinit "lux_t *disp"
.Ft void
.Fn luxfree "lux_t *disp"
.Sh DESCRIPTION
The
.Fn luxinit
function initialises the values of the
.Vt lux_t
structure pointed to by
.Va disp .
Allocation of
.Va disp
is left up to the user.
All
.Vt lux_t
structures should be initialised with the
.Fn luxinit
function before being used with any other library functions.
.Pp
The
.Fn luxfree
function does the opposite of the
.Fn luxinit
function, cleaning up all the resources used by the
.Vt lux_t
structure pointed to by
.Va disp .
This function should be called for all
.Vt lux_t
structures that have been initialised by
.Fn luxinit
after they are no longer required.
.Sh RETURN VALUES
The
.Fn luxinit
function returns the file descriptor of the directory containing the backlight
files located in
.Pa /sys/class/backlight
on success.
On error, \-1 is returned and
.Va errno
is set to indicate the error.
.Pp
The
.Fn luxfree
function returns no value.
.Sh EXAMPLES
The following program initialises a new
.Vt lux_t
structure, uses it to set the display brightness to 100%, and then frees the
resources used by the structure.
.Bd -literal -offset indent
#include <err.h>
#include <stdlib.h>
#include <lux.h>
int
main(void)
{
lux_t disp;
if (luxinit(&disp) == -1)
err(EXIT_FAILURE, "luxinit");
luxsetp(&disp, 100.0);
luxfree(&disp);
return EXIT_SUCCESS;
}
.Ed
.Sh ERRORS
.Fn luxinit
can fail with any of the errors specified for
.Fn fdopendir ,
.Fn open ,
.Fn openat ,
or
.Fn readdir .
.Sh SEE ALSO
.Xr lux.h 0 ,
.Xr luxdec 3 ,
.Xr luxdecp 3 ,
.Xr luxget 3 ,
.Xr luxgetp 3 ,
.Xr luxinc 3 ,
.Xr luxincp 3 ,
.Xr luxmax 3 ,
.Xr luxset 3 ,
.Xr luxsetp 3
.Sh AUTHORS
.An Thomas Voss Aq Mt mail@thomasvoss.com
|