#include <string.h>
#include <sys/types.h>
#include <ctype.h>
+#include <stdio.h>
/* default strtoxx_or_err() exit code */
#ifndef STRTOXX_EXIT_CODE
extern char *strappend(const char *s, const char *suffix);
extern const char *split(const char **state, size_t *l, const char *separator, int quoted);
+extern int skip_fline(FILE *fp);
+
#endif
#define RTC_AF 0x20
#define RTC_UF 0x10
-#define MAX_LINE 1024
+#define ADJTIME_ZONE_STRLEN 8
#define RTC_PATH "/sys/class/rtc/%s/device/power/wakeup"
#define SYS_POWER_STATE_PATH "/sys/power/state"
errx(EXIT_FAILURE, _("write error"));
}
-
static int read_clock_mode(struct rtcwake_control *ctl)
{
FILE *fp;
- char linebuf[MAX_LINE];
+ char linebuf[ADJTIME_ZONE_STRLEN];
fp = fopen(ctl->adjfile, "r");
if (!fp)
return -1;
- /* skip first line */
- if (!fgets(linebuf, MAX_LINE, fp)) {
- fclose(fp);
- return -1;
- }
-
- /* skip second line */
- if (!fgets(linebuf, MAX_LINE, fp)) {
+ /* skip two lines */
+ if (skip_fline(fp) || skip_fline(fp)) {
fclose(fp);
return -1;
}
/* read third line */
- if (!fgets(linebuf, MAX_LINE, fp)) {
+ if (!fgets(linebuf, sizeof linebuf, fp)) {
fclose(fp);
return -1;
}
ctl->clock_mode = CM_UTC;
else if (strncmp(linebuf, "LOCAL", 5) == 0)
ctl->clock_mode = CM_LOCAL;
+ else if (ctl->verbose)
+ warnx(_("unexpected third line in: %s: %s"), ctl->adjfile, linebuf);
fclose(fp);