merge
commit
ff0bd4e552
|
@ -66,6 +66,8 @@ extern int nanosleep(const struct timespec *req, struct timespec *rem);
|
|||
|
||||
#ifdef _POSIX_SOURCE
|
||||
extern char *tzname[2];
|
||||
extern long timezone;
|
||||
extern int daylight;
|
||||
#endif
|
||||
|
||||
#endif /* __TIME_H */
|
||||
|
|
|
@ -243,6 +243,13 @@ converts its numerical argument, a character number, to a
|
|||
.SM UTF
|
||||
string
|
||||
.TP
|
||||
.BI substr( s , " m")
|
||||
the maximum length substring of
|
||||
.I s
|
||||
that begins at position
|
||||
.IR m
|
||||
counted from 1.
|
||||
.TP
|
||||
.BI substr( s , " m" , " n\fL)
|
||||
the
|
||||
.IR n -character
|
||||
|
@ -303,6 +310,10 @@ If
|
|||
is not given,
|
||||
.B $0
|
||||
is used.
|
||||
.B &
|
||||
in
|
||||
.I t
|
||||
is replaced by the match.
|
||||
.TP
|
||||
.B gsub
|
||||
same as
|
||||
|
|
|
@ -255,6 +255,30 @@ Append the pattern space to
|
|||
if a replacement
|
||||
was made.
|
||||
.RE
|
||||
.IP
|
||||
An ampersand
|
||||
.L &
|
||||
appearing in the replacement
|
||||
is replaced by the string matching the regular expression.
|
||||
The characters
|
||||
.BI \e n\f1,
|
||||
where
|
||||
.I n
|
||||
is a digit,
|
||||
are replaced by the text matched by the
|
||||
.IR n -th
|
||||
regular subexpression
|
||||
enclosed between
|
||||
.L (
|
||||
and
|
||||
.LR ) .
|
||||
When
|
||||
nested parenthesized subexpressions
|
||||
are present,
|
||||
.I n
|
||||
is determined by counting occurrences of
|
||||
.L (
|
||||
starting from the left.
|
||||
.TP
|
||||
.BI t " label"
|
||||
Test.
|
||||
|
|
|
@ -110,8 +110,8 @@ mktime(struct tm *t)
|
|||
d = ptm->tm_hour;
|
||||
ptm = localtime(&a);
|
||||
d -= ptm->tm_hour;
|
||||
if(d < 0)
|
||||
d += 24;
|
||||
// if(d < 0)
|
||||
// d += 24;
|
||||
if(t->tm_isdst == 0 && ptm->tm_isdst)
|
||||
d--;
|
||||
if(t->tm_isdst > 0 && !ptm->tm_isdst)
|
||||
|
|
|
@ -6,136 +6,54 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define TZFILE "/etc/TZ"
|
||||
|
||||
static char TZ[128];
|
||||
static char std[32] = "GMT0";
|
||||
static char dst[32];
|
||||
char *tzname[2] = {
|
||||
std, dst
|
||||
};
|
||||
time_t tzoffset, tzdstoffset;
|
||||
int tzdst = 0;
|
||||
long timezone;
|
||||
int daylight;
|
||||
|
||||
static int
|
||||
offset(char *env, time_t *off)
|
||||
{
|
||||
int n, sign;
|
||||
size_t len, retlen;
|
||||
|
||||
retlen = 0;
|
||||
sign = 1;
|
||||
/*
|
||||
* strictly, no sign is allowed in the 'time' part of the
|
||||
* dst start/stop rules, but who cares?
|
||||
*/
|
||||
if (*env == '-' || *env == '+') {
|
||||
if (*env++ == '-')
|
||||
sign = -1;
|
||||
retlen++;
|
||||
}
|
||||
if ((len = strspn(env, ":0123456789")) == 0)
|
||||
return 0;
|
||||
retlen += len;
|
||||
for (*off = 0; len && isdigit(*env); len--) /* hours */
|
||||
*off = *off*10 + (*env++ - '0')*60*60;
|
||||
if (len) {
|
||||
if (*env++ != ':')
|
||||
return 0;
|
||||
len--;
|
||||
}
|
||||
for (n = 0; len && isdigit(*env); len--) /* minutes */
|
||||
n = n*10 + (*env++ - '0')*60;
|
||||
*off += n;
|
||||
if (len) {
|
||||
if (*env++ != ':')
|
||||
return 0;
|
||||
len--;
|
||||
}
|
||||
for (n = 0; len && isdigit(*env); len--) /* seconds */
|
||||
n = n*10 + (*env++ - '0');
|
||||
*off = (*off + n)*sign;
|
||||
return retlen;
|
||||
}
|
||||
|
||||
/*
|
||||
* TZ=stdoffset[dst[offset][,start[/time],end[/time]]]
|
||||
*/
|
||||
void
|
||||
tzset(void)
|
||||
{
|
||||
char *env, *p, envbuf[128];
|
||||
int fd, i;
|
||||
size_t len, retlen;
|
||||
time_t off;
|
||||
char *env, *p, *q;
|
||||
|
||||
if((p = getenv("timezone")) == 0)
|
||||
goto error;
|
||||
if((env = malloc(strlen(p) + 1)) == 0)
|
||||
goto error;
|
||||
strcpy(env, p);
|
||||
if((p = strchr(env, ' ')) == 0)
|
||||
goto error;
|
||||
*p = 0;
|
||||
strncpy(std, env, sizeof std);
|
||||
q = p + 1;
|
||||
if((p = strchr(q, ' ')) == 0)
|
||||
goto error;
|
||||
timezone = - atoi(q);
|
||||
q = p + 1;
|
||||
if((p = strchr(q, ' ')) == 0)
|
||||
goto nodst;
|
||||
*p = 0;
|
||||
strncpy(dst, q, sizeof dst);
|
||||
q = p + 1;
|
||||
daylight = 1;
|
||||
free(env);
|
||||
return;
|
||||
|
||||
/*
|
||||
* get the TZ environment variable and check for validity.
|
||||
* the implementation-defined manner for dealing with the
|
||||
* leading ':' format is to reject it.
|
||||
* if it's ok, stash a copy away for quick comparison next time.
|
||||
*/
|
||||
if ((env = getenv("TZ")) == 0) {
|
||||
if ((fd = open(TZFILE, O_RDONLY)) == -1)
|
||||
return;
|
||||
if (read(fd, envbuf, sizeof(envbuf)-1) == -1) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
for (i = 0; i < sizeof(envbuf); i++) {
|
||||
if (envbuf[i] != '\n')
|
||||
continue;
|
||||
envbuf[i] = '\0';
|
||||
break;
|
||||
}
|
||||
env = envbuf;
|
||||
}
|
||||
if (strcmp(env, TZ) == 0)
|
||||
return;
|
||||
if (*env == 0 || *env == ':')
|
||||
return;
|
||||
strncpy(TZ, env, sizeof(TZ)-1);
|
||||
TZ[sizeof(TZ)-1] = 0;
|
||||
/*
|
||||
* get the 'std' string.
|
||||
* before committing, check there is a valid offset.
|
||||
*/
|
||||
if ((len = strcspn(env, ":0123456789,-+")) == 0)
|
||||
return;
|
||||
if ((retlen = offset(env+len, &off)) == 0)
|
||||
return;
|
||||
for (p = std, i = len+retlen; i; i--)
|
||||
*p++ = *env++;
|
||||
*p = 0;
|
||||
tzoffset = -off;
|
||||
/*
|
||||
* get the 'dst' string (if any).
|
||||
*/
|
||||
if (*env == 0 || (len = strcspn(env, ":0123456789,-+")) == 0)
|
||||
return;
|
||||
for (p = dst; len; len--)
|
||||
*p++ = *env++;
|
||||
*p = 0;
|
||||
/*
|
||||
* optional dst offset.
|
||||
* default is one hour.
|
||||
*/
|
||||
tzdst = 1;
|
||||
if (retlen = offset(env+len, &off)) {
|
||||
tzdstoffset = -off;
|
||||
env += retlen;
|
||||
}
|
||||
else
|
||||
tzdstoffset = tzoffset + 60*60;
|
||||
/*
|
||||
* optional rule(s) for start/end of dst.
|
||||
*/
|
||||
if (*env == 0 || *env != ',' || *(env+1) == 0)
|
||||
return;
|
||||
env++;
|
||||
/*
|
||||
* we could go on...
|
||||
* but why bother?
|
||||
*/
|
||||
error:
|
||||
strcpy(std, "GMT0");
|
||||
dst[0] = '\0';
|
||||
timezone = 0;
|
||||
daylight = 0;
|
||||
if(env != 0)
|
||||
free(env);
|
||||
return;
|
||||
|
||||
nodst:
|
||||
dst[0] = '\0';
|
||||
daylight = 0;
|
||||
free(env);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -678,8 +678,7 @@ void inittimezone(PyObject *m) {
|
|||
PyModule_AddIntConstant(m, "timezone", _timezone);
|
||||
#else /* !PYOS_OS2 */
|
||||
#ifdef PLAN9APE
|
||||
//PyModule_AddIntConstant(m, "timezone", timezone);
|
||||
PyModule_AddIntConstant(m, "timezone", 0);
|
||||
PyModule_AddIntConstant(m, "timezone", timezone);
|
||||
#endif
|
||||
#endif /* PYOS_OS2 */
|
||||
#ifdef HAVE_ALTZONE
|
||||
|
@ -689,14 +688,12 @@ void inittimezone(PyObject *m) {
|
|||
PyModule_AddIntConstant(m, "altzone", _timezone-3600);
|
||||
#else /* !PYOS_OS2 */
|
||||
#ifdef PLAN9APE
|
||||
//PyModule_AddIntConstant(m, "altzone", timezone-3600);
|
||||
PyModule_AddIntConstant(m, "altzone", 3600);
|
||||
PyModule_AddIntConstant(m, "altzone", timezone-3600);
|
||||
#endif
|
||||
#endif /* PYOS_OS2 */
|
||||
#endif
|
||||
#ifdef PLAN9APE
|
||||
//PyModule_AddIntConstant(m, "daylight", daylight);
|
||||
PyModule_AddIntConstant(m, "daylight", 0);
|
||||
PyModule_AddIntConstant(m, "daylight", daylight);
|
||||
PyModule_AddObject(m, "tzname",
|
||||
Py_BuildValue("(zz)", tzname[0], tzname[1]));
|
||||
#endif
|
||||
|
|
|
@ -45,7 +45,6 @@ typedef unsigned short u_short;
|
|||
typedef unsigned long u_long;
|
||||
|
||||
#define EISCONN 63
|
||||
#define EWOULDBLOCK 64
|
||||
|
||||
#define FD_SETSIZE 96 /* see /sys/include/ape/sys/select.h */
|
||||
|
||||
|
|
Loading…
Reference in New Issue