aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs_misc.c69
-rw-r--r--src/fs/gnunet-publish.c2
2 files changed, 1 insertions, 70 deletions
diff --git a/src/fs/fs_misc.c b/src/fs/fs_misc.c
index ee24fa250..bca16e545 100644
--- a/src/fs/fs_misc.c
+++ b/src/fs/fs_misc.c
@@ -159,73 +159,4 @@ GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData
159} 159}
160 160
161 161
162/**
163 * Return the current year (i.e. '2011').
164 */
165unsigned int
166GNUNET_FS_get_current_year ()
167{
168 time_t tp;
169 struct tm *t;
170
171 tp = time (NULL);
172 t = gmtime (&tp);
173 if (t == NULL)
174 return 0;
175 return t->tm_year + 1900;
176}
177
178
179/**
180 * Convert a year to an expiration time of January 1st of that year.
181 *
182 * @param year a year (after 1970, please ;-)).
183 * @return absolute time for January 1st of that year.
184 */
185struct GNUNET_TIME_Absolute
186GNUNET_FS_year_to_time (unsigned int year)
187{
188 struct GNUNET_TIME_Absolute ret;
189 time_t tp;
190 struct tm t;
191
192 memset (&t, 0, sizeof (t));
193 if (year < 1900)
194 {
195 GNUNET_break (0);
196 return GNUNET_TIME_absolute_get (); /* now */
197 }
198 t.tm_year = year - 1900;
199 t.tm_mday = 1;
200 t.tm_mon = 1;
201 t.tm_wday = 1;
202 t.tm_yday = 1;
203 tp = mktime (&t);
204 GNUNET_break (tp != (time_t) - 1);
205 ret.abs_value_us = tp * 1000LL * 1000LL; /* seconds to microseconds */
206 return ret;
207}
208
209
210/**
211 * Convert an expiration time to the respective year (rounds)
212 *
213 * @param at absolute time
214 * @return year a year (after 1970), 0 on error
215 */
216unsigned int
217GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at)
218{
219 struct tm *t;
220 time_t tp;
221
222 tp = at.abs_value_us / 1000LL / 1000LL; /* microseconds to seconds */
223 t = gmtime (&tp);
224 if (t == NULL)
225 return 0;
226 return t->tm_year + 1900;
227
228}
229
230
231/* end of fs_misc.c */ 162/* end of fs_misc.c */
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 58beb371c..f960503c2 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -866,7 +866,7 @@ main (int argc, char *const *argv)
866 GNUNET_GETOPT_OPTION_END 866 GNUNET_GETOPT_OPTION_END
867 }; 867 };
868 bo.expiration_time = 868 bo.expiration_time =
869 GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); 869 GNUNET_TIME_year_to_time (GNUNET_TIME_get_current_year () + 2);
870 870
871 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 871 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
872 return 2; 872 return 2;