#define WILDABBR " "
#endif /* !defined WILDABBR */
-static char wildabbr[] = "WILDABBR";
+static const char wildabbr[] = "WILDABBR";
/*
* In June 2004 it was decided UTC was a more appropriate default time
#ifdef NOTIFY_TZ
typedef struct {
int token;
- int notify_was_off;
int is_set;
} notify_tz_t;
static const char * getsecs(const char * strp, long * secsp);
static const char * getoffset(const char * strp, long * offsetp);
static const char * getrule(const char * strp, struct rule * rulep);
+#ifdef NOTIFY_TZ
+static void gmtload(struct state * sp, char *path);
+#else /* ! NOTIFY_TZ */
static void gmtload(struct state * sp);
+#endif /* NOTIFY_TZ */
#ifdef __LP64__
static struct tm * gmtsub(const time_t * timep, long offset,
struct tm * tmp);
const struct tm * btmp);
static time_t transtime(time_t janfirst, int year,
const struct rule * rulep, long offset);
+#ifdef NOTIFY_TZ
+static int tzload(const char * name, struct state * sp, char *path);
+#else /* ! NOTIFY_TZ */
static int tzload(const char * name, struct state * sp);
+#endif /* NOTIFY_TZ */
static int tzparse(const char * name, struct state * sp,
int lastditch);
static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER;
char * tzname[2] = {
- wildabbr,
- wildabbr
+ (char *)wildabbr,
+ (char *)wildabbr
};
/*
} \
}
#endif /* NOTIFY_TZ_LOG */
-/*--------------------------------------------------------------------
- * __notify_78945668_info__ is a global variable (defined in Libnotify)
- * that can be used to disable the notify mechanism. Set to a negative
- * value to disable. It can then be set back to zero to re-enable.
- *-------------------------------------------------------------------- */
-extern int __notify_78945668_info__;
-
-/*--------------------------------------------------------------------
- * fullname is used to pass the actual path of the timezone file to the
- * notify routines. If it is a nil string, that means no timezone file
- * is being used.
- *-------------------------------------------------------------------- */
-static char * fullname = NULL;
-
-static notify_tz_t gmt_notify = {-1, 0, 0};
-static notify_tz_t lcl_notify = {-1, 0, 0};
-static char notify_tz_name[] = NOTIFY_TZ_NAME;
+
+static notify_tz_t gmt_notify = {-1, 0};
+static notify_tz_t lcl_notify = {-1, 0};
+static const char notify_tz_name[] = NOTIFY_TZ_NAME;
#endif /* NOTIFY_TZ */
static long
#define NEED_DAYLIGHT 4
#define NEED_ALL (NEED_STD | NEED_DST | NEED_DAYLIGHT)
- tzname[0] = wildabbr;
- tzname[1] = wildabbr;
+ tzname[0] = (char *)wildabbr;
+ tzname[1] = (char *)wildabbr;
#ifdef USG_COMPAT
daylight = 0;
_st_set_timezone(0);
unsigned int nstat;
int ncheck;
- if (__notify_78945668_info__ < 0) {
-#ifdef NOTIFY_TZ_DEBUG
- if(!p->notify_was_off) NOTIFY_TZ_PRINTF("notify_check_tz: setting %s_notify->notify_was_off\n", (p == &lcl_notify ? "lcl" : "gmt"));
-#endif /* NOTIFY_TZ_DEBUG */
- p->notify_was_off = 1;
- return;
- }
- /* force rereading the timezone file if notify was off */
- if (p->notify_was_off) {
-#ifdef NOTIFY_TZ_DEBUG
- NOTIFY_TZ_PRINTF("notify_check_tz: saw %s_notify->notify_was_off\n", (p == &lcl_notify ? "lcl" : "gmt"));
-#endif /* NOTIFY_TZ_DEBUG */
- p->is_set = 0;
- p->notify_was_off = 0;
- return;
- }
if (p->token < 0)
return;
nstat = notify_check(p->token, &ncheck);
unsigned int nstat;
int ncheck;
- if (__notify_78945668_info__ < 0)
- return;
/*----------------------------------------------------------------
* Since we don't record the last time zone filename, just cancel
* (which should remove the file monitor) and setup from scratch
* Otherwise use com.apple.system.timezone.<fullpath>
*----------------------------------------------------------------*/
if (TZDEFAULT && strcmp(file, TZDEFAULT) == 0)
- name = notify_tz_name;
+ name = (char *)notify_tz_name;
else {
name = alloca(sizeof(notify_tz_name) + strlen(file) + 1);
if (name == NULL) {
#endif /* NOTIFY_TZ */
static int
+#ifdef NOTIFY_TZ
+tzload(name, sp, path)
+#else /* ! NOTIFY_TZ */
tzload(name, sp)
+#endif /* NOTIFY_TZ */
const char * name;
struct state * const sp;
+#ifdef NOTIFY_TZ
+char * path; /* copy full path if non-NULL */
+#endif /* NOTIFY_TZ */
{
const char * p;
int i;
if ((name[0] == ':' && name[1] == '/') ||
name[0] == '/' || strchr(name, '.'))
name = NULL;
+#ifdef NOTIFY_TZ
+ if (path)
+ *path = 0; /* default to empty string on error */
+#endif /* NOTIFY_TZ */
if (name == NULL && (name = TZDEFAULT) == NULL)
return -1;
{
** to hold the longest file name string that the implementation
** guarantees can be opened."
*/
-#ifdef NOTIFY_TZ
- if (!fullname) {
- fullname = malloc(FILENAME_MAX + 1);
- if (!fullname)
- return -1;
- }
-#else /* ! NOTIFY_TZ */
char fullname[FILENAME_MAX + 1];
-#endif /* NOTIFY_TZ */
if (name[0] == ':')
++name;
if (!doaccess) {
if ((p = TZDIR) == NULL)
return -1;
-#ifdef NOTIFY_TZ
- if ((strlen(p) + 1 + strlen(name) + 1) >= (FILENAME_MAX + 1))
-#else /* ! NOTIFY_TZ */
if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname)
-#endif /* NOTIFY_TZ */
return -1;
(void) strcpy(fullname, p);
(void) strcat(fullname, "/");
name = fullname;
}
#ifdef NOTIFY_TZ
- else
- strcpy(fullname, name);
+ if (path) {
+ if (strlen(name) > FILENAME_MAX)
+ return -1;
+ strcpy(path, name);
+ }
#endif /* NOTIFY_TZ */
if (doaccess && access(name, R_OK) != 0)
return -1;
return -1;
}
}
- load_result = tzload(TZDEFRULES, sp);
#ifdef NOTIFY_TZ
- *fullname = 0; /* mark fullname as invalid */
+ load_result = tzload(TZDEFRULES, sp, NULL);
+#else /* !NOTIFY_TZ */
+ load_result = tzload(TZDEFRULES, sp);
#endif /* NOTIFY_TZ */
if (load_result != 0)
sp->leapcnt = 0; /* so, we're off a little */
}
static void
+#ifdef NOTIFY_TZ
+gmtload(sp, path)
+#else /* ! NOTIFY_TZ */
gmtload(sp)
+#endif /* NOTIFY_TZ */
struct state * const sp;
+#ifdef NOTIFY_TZ
+char *path;
+#endif /* NOTIFY_TZ */
{
+#ifdef NOTIFY_TZ
+ if (tzload(gmt, sp, path) != 0)
+#else /* ! NOTIFY_TZ */
if (tzload(gmt, sp) != 0)
+#endif /* NOTIFY_TZ */
(void) tzparse(gmt, sp, TRUE);
}
}
}
#endif /* defined ALL_STATE */
+#ifdef NOTIFY_TZ
+ {
+ char fullname[FILENAME_MAX + 1];
+ if (tzload((char *) NULL, lclptr, fullname) != 0)
+ /*
+ * If fullname is empty (an error occurred) then
+ * default to the UTC path
+ */
+ gmtload(lclptr, *fullname ? NULL : fullname);
+ notify_register_tz(fullname, &lcl_notify);
+ }
+#else /* ! NOTIFY_TZ */
if (tzload((char *) NULL, lclptr) != 0)
gmtload(lclptr);
-#ifdef NOTIFY_TZ
- notify_register_tz(fullname, &lcl_notify);
#endif /* NOTIFY_TZ */
settzname();
_RWLOCK_UNLOCK(&lcl_rwlock);
lclptr->ttis[0].tt_abbrind = 0;
(void) strcpy(lclptr->chars, gmt);
#ifdef NOTIFY_TZ
- if (fullname)
- *fullname = 0;
+ notify_register_tz(NULL, &lcl_notify);
#endif /* NOTIFY_TZ */
- } else if (tzload(name, lclptr) != 0)
+ } else
+#ifdef NOTIFY_TZ
+ {
+ char fullname[FILENAME_MAX + 1];
+ /*
+ * parsedOK indicates whether tzparse() was called and
+ * succeeded. This means that TZ is a time conversion
+ * specification, so we don't need to register for
+ * notifications.
+ */
+ int parsedOK = FALSE;
+ if (tzload(name, lclptr, fullname) != 0)
+ if (name[0] == ':' || !(parsedOK = tzparse(name, lclptr, FALSE) == 0))
+ /*
+ * If fullname is empty (an error occurred) then
+ * default to the UTC path
+ */
+ (void) gmtload(lclptr, *fullname ? NULL : fullname);
+ notify_register_tz(parsedOK ? NULL : fullname, &lcl_notify);
+ }
+#else /* ! NOTIFY_TZ */
+ if (tzload(name, lclptr) != 0)
if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
(void) gmtload(lclptr);
-#ifdef NOTIFY_TZ
- notify_register_tz(fullname, &lcl_notify);
#endif /* NOTIFY_TZ */
settzname();
_RWLOCK_UNLOCK(&lcl_rwlock);
#endif /* NOTIFY_TZ */
gmtptr = (struct state *) malloc(sizeof *gmtptr);
if (gmtptr != NULL)
-#ifdef NOTIFY_TZ
- {
-#endif /* NOTIFY_TZ */
#endif /* defined ALL_STATE */
- gmtload(gmtptr);
#ifdef NOTIFY_TZ
+ {
+ char fullname[FILENAME_MAX + 1];
+ gmtload(gmtptr, fullname);
notify_register_tz(fullname, &gmt_notify);
-#ifdef ALL_STATE
}
-#endif
+#else /* ! NOTIFY_TZ */
+ gmtload(gmtptr);
#endif /* NOTIFY_TZ */
gmt_is_set = TRUE;
}