12 #include "libautomation.h"
14 char *atm_stradd(char *dest
, const char *source
, int *size
) {
20 memcpy(dest
, source
, len
);
27 int atm_echo(const char *str
, const char *filename
) {
30 fd
= open(filename
, O_WRONLY
);
34 ret
= write(fd
, str
, strlen(str
));
40 void atm_log(const char *fmt
, ...) {
44 vfprintf(stderr
, fmt
, ap
);
48 void atm_fail(const char *message
) {
53 long int atm_read_int_or_fail(const char *str
, const char *msg
){
57 res
= strtol(str
, &s
, 10);
64 float atm_read_float_or_fail(const char *str
, const char *msg
){
68 res
= strtod(str
, &s
);
76 int atm_timestamp(void) {
79 clock_gettime(CLOCK_BOOTTIME
, &t
);
81 return t
.tv_sec
*10 + t
.tv_nsec
/100000000;
84 /* Find a uniq filename to a glob pattern,
85 * useful for ever changing sysfs paths
87 char *atm_globdup(const char *pattern
) {
91 glob(pattern
, 0, NULL
, &globbuf
);
92 if(globbuf
.gl_pathc
== 0) {
93 atm_log("WARNING: Can't match pattern '%s'", pattern
);
97 result
= strdup(*globbuf
.gl_pathv
);
98 if(globbuf
.gl_pathc
> 1)
99 atm_log("WARNING: Pattern '%s' matches multiple files. Using '%s'", pattern
, result
);