Mercurial > noffle
annotate src/util.c @ 235:21f75cc470f4 noffle
[svn] * docs/noffle.conf.5: Correct typo in From: filter description.
* src/client.c: Fix memory leak in filter code.
* src/fetchlist.c: Write fetchlist to new file and update if written
correctly. Stops fetchlist being trashed on disc full. Also add
fetchlist dirty flag to save unnecessary rewrites.
author | bears |
---|---|
date | Mon, 11 Feb 2002 11:20:31 +0000 |
parents | ffb1848a39db |
children | fbff73fe5b40 |
rev | line source |
---|---|
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
1 /* |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
2 util.c |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
3 |
223
ffb1848a39db
[svn] * src/util.c: Improve (correct) error detection when updating
bears
parents:
206
diff
changeset
|
4 $Id: util.c 342 2001-12-09 12:31:57Z bears $ |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
5 */ |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
6 |
45
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
7 #if HAVE_CONFIG_H |
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
8 #include <config.h> |
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
9 #endif |
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
10 |
54
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
11 #if TIME_WITH_SYS_TIME |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
12 #include <sys/time.h> |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
13 #include <time.h> |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
14 #else |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
15 #if HAVE_SYS_TIME_H |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
16 #include <sys/time.h> |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
17 #else |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
18 #include <time.h> |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
19 #endif |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
20 #endif |
125d79c9e586
[svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents:
45
diff
changeset
|
21 |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
22 #include <errno.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
23 #include <ctype.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
24 #include <sys/types.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
25 #include <sys/stat.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
26 #include <fcntl.h> |
91 | 27 #include <stdlib.h> |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
28 #include <unistd.h> |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
29 #include "configfile.h" |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
30 #include "log.h" |
197
24d4cd032da5
[svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents:
186
diff
changeset
|
31 #include "portable.h" |
24d4cd032da5
[svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents:
186
diff
changeset
|
32 #include "util.h" |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
33 #include "wildmat.h" |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
34 |
91 | 35 #if defined(UTIL_TEST) |
36 #define Log_err printf | |
37 #endif | |
38 | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
39 static const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
40 nextWhiteSpace( const char *p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
41 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
42 while ( *p && ! isspace( *p ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
43 ++p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
44 return p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
45 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
46 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
47 static const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
48 nextNonWhiteSpace( const char *p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
49 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
50 while ( *p && isspace( *p ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
51 ++p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
52 return p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
53 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
54 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
55 const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
56 Utl_restOfLn( const char *line, unsigned int token ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
57 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
58 unsigned int i; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
59 const char *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
60 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
61 p = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
62 for ( i = 0; i < token; ++i ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
63 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
64 p = nextNonWhiteSpace( p ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
65 p = nextWhiteSpace( p ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
66 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
67 p = nextNonWhiteSpace( p ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
68 return p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
69 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
70 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
71 const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
72 Utl_getLn( Str result, const char *pos ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
73 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
74 int len = 0; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
75 const char *p = pos; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
76 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
77 if ( ! p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
78 return NULL; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
79 while ( *p != '\n' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
80 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
81 if ( *p == '\0' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
82 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
83 if ( len > 0 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
84 Log_err( "Line not terminated by newline: '%s'", pos ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
85 return NULL; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
86 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
87 *(result++) = *(p++); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
88 ++len; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
89 if ( len >= MAXCHAR - 1 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
90 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
91 *result = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
92 Log_err( "Utl_getLn: line too long: %s", result ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
93 return ++p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
94 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
95 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
96 *result = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
97 return ++p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
98 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
99 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
100 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
101 const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
102 Utl_ungetLn( const char *str, const char *p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
103 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
104 if ( str == p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
105 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
106 --p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
107 if ( *p != '\n' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
108 { |
185
fed1334d766b
[svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents:
164
diff
changeset
|
109 Log_err( "Utl_ungetLn: not at beginning of line" ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
110 return NULL; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
111 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
112 --p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
113 while ( TRUE ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
114 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
115 if ( p == str ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
116 return p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
117 if ( *p == '\n' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
118 return p + 1; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
119 --p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
120 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
121 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
122 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
123 const char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
124 Utl_getHeaderLn( Str result, const char *p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
125 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
126 const char * res = Utl_getLn( result, p ); |
202 | 127 Bool not_too_long_header = TRUE; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
128 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
129 /* Look for followon line if this isn't a blank line. */ |
109 | 130 if ( res != NULL && result[ 0 ] != '\0' && ! isspace( result[ 0 ] ) ) |
87 | 131 for(;;) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
132 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
133 Str nextLine; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
134 const char *here; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
135 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
136 here = res; |
87 | 137 nextLine[ 0 ] = '\0'; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
138 res = Utl_getLn( nextLine, res ); |
87 | 139 if ( res == NULL || nextLine[ 0 ] == '\0' |
109 | 140 || ! isspace( nextLine[ 0 ] ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
141 { |
87 | 142 res = here; |
143 break; | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
144 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
145 else |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
146 { |
202 | 147 if ( not_too_long_header && |
148 ( MAXCHAR > ( strlen( result ) + strlen( nextLine ) + 1 ) ) ) | |
149 { | |
150 Utl_catStr( result, "\n" ); | |
151 Utl_catStr( result, nextLine ); | |
152 } | |
153 else | |
154 { | |
155 Log_err( "Utl_getHeaderLn: skipped continued header: %s", nextLine ); | |
156 not_too_long_header = FALSE; | |
157 /* Now let poor little noffle skip the header continuations. */ | |
158 /* We really need to up the size limit of headers much */ | |
159 /* higher than MAXCHAR = 2048. mliss */ | |
160 } | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
161 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
162 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
163 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
164 return res; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
165 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
166 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
167 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
168 Utl_toLower( Str line ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
169 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
170 char *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
171 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
172 p = line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
173 while ( *p ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
174 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
175 *p = tolower( *p ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
176 ++p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
177 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
178 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
179 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
180 char * |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
181 Utl_stripWhiteSpace( char *line ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
182 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
183 char *p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
184 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
185 while ( isspace( *line ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
186 ++line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
187 p = line + strlen( line ) - 1; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
188 while ( isspace( *p ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
189 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
190 *p = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
191 --p; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
192 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
193 return line; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
194 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
195 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
196 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
197 Utl_stripComment( char *line ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
198 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
199 for ( ; *line != '\0'; line++ ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
200 if ( *line =='#' ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
201 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
202 *line = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
203 break; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
204 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
205 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
206 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
207 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
208 Utl_cpyStr( Str dst, const char *src ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
209 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
210 dst[ 0 ] = '\0'; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
211 strncat( dst, src, MAXCHAR ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
212 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
213 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
214 void |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
215 Utl_cpyStrN( Str dst, const char *src, int n ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
216 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
217 if ( n > MAXCHAR ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
218 n = MAXCHAR; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
219 dst[ 0 ] = '\0'; |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
220 strncat( dst, src, (size_t)n ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
221 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
222 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
223 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
224 Utl_catStr( Str dst, const char *src ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
225 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
226 strncat( dst, src, MAXCHAR - strlen( dst ) ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
227 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
228 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
229 void |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
230 Utl_catStrN( Str dst, const char *src, int n ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
231 { |
59
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
232 size_t un; |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
233 |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
234 ASSERT( n >= 0 ); |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
235 un = (size_t)n; |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
236 if ( un > MAXCHAR - strlen( dst ) ) |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
237 un = MAXCHAR - strlen( dst ); |
e612b263934f
[svn] Changed some variable types and used some casts to avoid compiler
enz
parents:
54
diff
changeset
|
238 strncat( dst, src, un ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
239 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
240 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
241 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
242 Utl_stamp( Str file ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
243 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
244 FILE *f; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
245 time_t t; |
206 | 246 Str tmpfname; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
247 |
206 | 248 snprintf( tmpfname, MAXCHAR, "%s/.#%d.stamp.update", |
249 Cfg_spoolDir(), (int) getpid() ); | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
250 time( &t ); |
206 | 251 if ( ! ( f = fopen( tmpfname, "w" ) ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
252 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
253 Log_err( "Could not open %s for writing (%s)", |
206 | 254 tmpfname, strerror( errno ) ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
255 return; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
256 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
257 fprintf( f, "%lu\n", t ); |
223
ffb1848a39db
[svn] * src/util.c: Improve (correct) error detection when updating
bears
parents:
206
diff
changeset
|
258 if ( fclose( f ) != 0 ) |
206 | 259 { |
260 Log_err( "Error stamping into file %s: %s", | |
261 tmpfname, strerror( errno ) ); | |
262 | |
263 } | |
264 else | |
265 { | |
266 if ( rename( tmpfname, file ) < 0 ) | |
267 Log_err( "Rename of stamp file %s to %s failed: %s", | |
268 tmpfname, file, strerror( errno ) ); | |
269 } | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
270 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
271 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
272 Bool |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
273 Utl_getStamp( time_t *result, Str file ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
274 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
275 FILE *f; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
276 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
277 if ( ! ( f = fopen( file, "r" ) ) ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
278 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
279 if ( fscanf( f, "%lu", result ) != 1 ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
280 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
281 Log_err( "File %s corrupted", file ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
282 fclose( f ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
283 return FALSE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
284 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
285 fclose( f ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
286 return TRUE; |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
287 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
288 |
91 | 289 static const char *DOTW[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", |
290 "Sat", NULL }; | |
291 static const char *MON[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", | |
292 "Aug", "Sep", "Oct", "Nov", "Dec", NULL }; | |
293 | |
127 | 294 /* |
295 * Calculate the difference between local time and GMT. This is INN's | |
296 * 'always-works' method. It assumes the time differences is < 24hrs. | |
297 * Sounds reasonable to me. It also assumes it can ignore seconds. | |
298 * Returns GMT - localtime minutes. It will also trash the localtime/ | |
299 * gmtime/etc. static buffer. | |
300 */ | |
301 static int | |
302 tzDiff( void ) | |
303 { | |
304 time_t now; | |
305 struct tm local, gmt, *tm; | |
306 static time_t nextCalc = 0; | |
307 static int res = 0; | |
308 | |
309 now = time( NULL ); | |
310 if ( now < nextCalc ) | |
311 return res; | |
312 | |
313 tm = localtime( &now ); | |
314 if ( tm == NULL ) | |
315 return 0; | |
316 local = *tm; | |
317 tm = gmtime( &now ); | |
318 if ( tm == NULL ) | |
319 return 0; | |
320 gmt = *tm; | |
321 | |
322 res = gmt.tm_yday - local.tm_yday; | |
323 if ( res < -1 ) | |
324 res = -1; /* Year rollover? */ | |
325 else if ( res > 1 ) | |
326 res = 1; | |
327 | |
328 res *= 24; | |
329 res += gmt.tm_hour - local.tm_hour; | |
330 res *= 60; | |
331 res += gmt.tm_min - local.tm_min; | |
332 | |
333 /* Need to recalc at start of next hour */ | |
334 nextCalc = now + ( 60 - local.tm_sec ) + 60 * ( 59 - local.tm_min ); | |
335 | |
336 return res; | |
337 } | |
338 | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
339 void |
91 | 340 Utl_newsDate( time_t t, Str res ) |
341 { | |
127 | 342 struct tm *local; |
343 long tzdiff, hoffset, moffset; | |
344 | |
345 tzdiff = - tzDiff(); | |
91 | 346 |
127 | 347 local = localtime( &t ); |
348 if ( local == NULL ) | |
349 { | |
350 Utl_cpyStr( res, "** localtime failure **" ); | |
351 return; | |
352 } | |
353 | |
91 | 354 hoffset = tzdiff / 60; |
355 moffset = tzdiff % 60; | |
127 | 356 if ( moffset < 0 ) |
357 moffset = - moffset; | |
91 | 358 |
127 | 359 sprintf( res, "%s, %d %s %4d %02d:%02d:%02d %+03ld%02ld", |
360 DOTW[local->tm_wday], local->tm_mday, | |
361 MON[local->tm_mon], local->tm_year + 1900, | |
362 local->tm_hour, local->tm_min, local->tm_sec, | |
91 | 363 hoffset, moffset ); |
364 } | |
365 | |
366 time_t | |
367 Utl_parseNewsDate( const char *s ) | |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
368 { |
91 | 369 struct tm tm; |
127 | 370 int wday, offset, tzoffset; |
91 | 371 char *p; |
372 time_t res; | |
373 | |
374 memset( &tm, 0, sizeof( tm ) ); | |
375 wday = -1; | |
127 | 376 tm.tm_isdst = -1; |
91 | 377 |
378 s = nextNonWhiteSpace( s ); | |
379 | |
380 /* Is this the day number, or a weekday? */ | |
381 if ( ! isdigit( *s ) ) | |
382 { | |
383 if ( strlen( s ) < 4 ) | |
384 return (time_t) -1; | |
385 | |
386 for ( wday = 0; DOTW[ wday ] != NULL; wday++ ) | |
186 | 387 if ( strncasecmp( DOTW[ wday ], s, 3 ) == 0 ) |
91 | 388 break; |
389 | |
390 if( DOTW[ wday ] == NULL || s[3] != ',' ) | |
391 return (time_t) -1; | |
392 | |
393 s += 4; | |
394 } | |
395 | |
396 /* Get the day number */ | |
397 tm.tm_mday = (int) strtol( s, &p, 10 ); | |
398 if ( p == s ) | |
399 return (time_t) -1; | |
400 s = p; | |
401 | |
402 /* Look for month name */ | |
403 s = nextNonWhiteSpace( s ); | |
404 if ( strlen( s ) < 4 ) | |
405 return (time_t) -1; | |
406 for ( tm.tm_mon = 0; MON[ tm.tm_mon ] != NULL; tm.tm_mon++ ) | |
186 | 407 if ( strncasecmp( MON[ tm.tm_mon ], s, 3 ) == 0 ) |
91 | 408 break; |
409 | |
410 if ( MON[ tm.tm_mon ] == NULL ) | |
411 return (time_t) -1; | |
412 s += 3; | |
413 | |
414 /* Year next */ | |
415 tm.tm_year = (int) strtol( s, &p, 10 ); | |
416 if ( p == s || ( tm.tm_year >= 100 && tm.tm_year < 1900 ) ) | |
417 return (time_t) -1; | |
418 if ( tm.tm_year >= 1900 ) | |
419 tm.tm_year -= 1900; | |
420 s = p; | |
421 | |
422 /* Hours */ | |
423 tm.tm_hour = (int) strtol( s, &p, 10 ); | |
424 if ( p == s || *p != ':' ) | |
425 return (time_t) -1; | |
426 s = ++p; | |
427 | |
428 /* Minutes */ | |
429 tm.tm_min = (int) strtol( s, &p, 10 ); | |
430 if ( p == s || ( *p != ':' && *p != ' ' ) ) | |
431 return (time_t) -1; | |
432 s = p; | |
433 | |
434 /* Seconds */ | |
435 if ( *s == ':' ) | |
436 { | |
437 s++; | |
438 tm.tm_sec = (int) strtol( s, &p, 10 ); | |
439 if ( p == s ) | |
440 return (time_t) -1; | |
441 s = p; | |
442 } | |
443 | |
444 /* GMT/UT or timezone offset */ | |
445 tzoffset = 0; | |
202 | 446 s = nextNonWhiteSpace( s ); |
186 | 447 if ( strncasecmp( s, "GMT", 3) == 0 ) |
91 | 448 s += 3; |
186 | 449 else if ( strncasecmp( s, "UT", 2 ) == 0 ) |
91 | 450 s += 2; |
451 else | |
452 { | |
127 | 453 offset = (int) strtol( s, &p, 10 ); |
202 | 454 if ( p == s ) |
455 return (time_t) -1; | |
91 | 456 s = p; |
127 | 457 tzoffset = ( offset / 100 ) * 60 + ( offset % 100 ); |
91 | 458 } |
459 | |
460 /* Check for following junk */ | |
461 if ( *s != '\0' && ! isspace( *s ) ) | |
462 return (time_t) -1; | |
463 | |
464 res = mktime( &tm ); | |
465 if ( res == (time_t) -1 ) | |
466 return res; | |
467 | |
468 if ( wday >= 0 && wday != tm.tm_wday ) | |
469 return (time_t) -1; | |
470 | |
127 | 471 /* Remove local time diff from res to give time as if GMT */ |
472 res -= tzDiff() * 60; | |
473 | |
474 /* And now adjust for tzoffset */ | |
475 res -= tzoffset * 60; | |
476 | |
91 | 477 return res; |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
478 } |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
479 |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
480 void |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
481 Utl_allocAndCpy( char **dst, const char *src ) |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
482 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
483 int len = strlen( src ); |
45
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
484 if ( ! ( *dst = malloc( (size_t)len + 1 ) ) ) |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
485 { |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
486 Log_err( "Cannot allocate string with length %lu", strlen( src ) ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
487 exit( EXIT_FAILURE ); |
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
488 } |
45
32ba1198c6fa
[svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents:
43
diff
changeset
|
489 memcpy( *dst, src, (size_t)len + 1 ); |
43
2842f50feb55
[svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff
changeset
|
490 } |
91 | 491 |
164
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
492 sig_t |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
493 Utl_installSignalHandler( int sig, sig_t handler ) |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
494 { |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
495 struct sigaction act, oldAct; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
496 |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
497 act.sa_handler = handler; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
498 sigemptyset( &act.sa_mask ); |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
499 act.sa_flags = 0; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
500 if ( sig != SIGALRM ) |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
501 act.sa_flags |= SA_RESTART; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
502 if ( sigaction( sig, &act, &oldAct ) < 0 ) |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
503 return SIG_ERR; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
504 return oldAct.sa_handler; |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
505 } |
94f2e5607772
[svn] * src/client.c,src/protocol.c,src/util.h,src/util.c: Common up
bears
parents:
127
diff
changeset
|
506 |
91 | 507 #if defined(UTIL_TEST) |
508 | |
509 /* Test code borrowed from wildmat.c. Yep, still uses gets(). */ | |
510 extern char *gets(); | |
511 | |
512 int | |
513 main() | |
514 { | |
515 Str line; | |
516 time_t t; | |
517 | |
518 printf( "Util date tester. Enter date to test.\n" ); | |
519 printf( "A blank line exits the program.\n" ); | |
520 | |
521 for ( ; ; ) | |
522 { | |
127 | 523 t = time( NULL ); |
524 Utl_newsDate( t, line ); | |
525 printf( "\n(%s) Enter date: ", line ); | |
91 | 526 (void) fflush( stdout ); |
527 if ( gets( line ) == NULL || line[0] == '\0' ) | |
528 break; | |
529 | |
530 t = Utl_parseNewsDate( line ); | |
531 if ( t == (time_t) -1 ) | |
532 printf( "Date parse failed\n" ); | |
533 else | |
534 { | |
535 Utl_newsDate( t, line ); | |
127 | 536 printf( "Utl_newsDate -> '%s'\n", line ); |
91 | 537 } |
538 } | |
539 | |
540 exit(0); | |
541 /* NOTREACHED */ | |
542 } | |
543 #endif |