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
);
49 void atm_fail(const char *message
) {
54 long int atm_read_int_or_fail(const char *str
, const char *msg
){
58 res
= strtol(str
, &s
, 10);
65 float atm_read_float_or_fail(const char *str
, const char *msg
){
69 res
= strtod(str
, &s
);
77 int atm_timestamp(void) {
80 clock_gettime(CLOCK_BOOTTIME
, &t
);
82 return t
.tv_sec
*10 + t
.tv_nsec
/100000000;
85 /* Find a uniq filename to a glob pattern,
86 * useful for ever changing sysfs paths
88 char *atm_globdup(const char *pattern
) {
92 glob(pattern
, 0, NULL
, &globbuf
);
93 if(globbuf
.gl_pathc
== 0) {
94 atm_log("WARNING: Can't match pattern '%s'", pattern
);
98 result
= strdup(*globbuf
.gl_pathv
);
99 if(globbuf
.gl_pathc
> 1)
100 atm_log("WARNING: Pattern '%s' matches multiple files. Using '%s'", pattern
, result
);