X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=util.h;h=b55320e90128b432a3121c562a3723b271058baf;hp=5922a425f101e66dcbdaa19e4763c2cf9e6680ed;hb=HEAD;hpb=dd553bb0b2ac2fe7a1904d2f2670f37e3bb25ae6 diff --git a/util.h b/util.h index 5922a42..b55320e 100644 --- a/util.h +++ b/util.h @@ -1,7 +1,6 @@ -/* Cumulus: Smart Filesystem Backup to Dumb Servers - * - * Copyright (C) 2007 The Regents of the University of California - * Written by Michael Vrable +/* Cumulus: Efficient Filesystem Backup to the Cloud + * Copyright (C) 2007 The Cumulus Developers + * See the AUTHORS file for a list of contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +27,9 @@ #include #include +std::string string_printf(const char *fmt, ...) + __attribute__((format(printf, 1, 2))); + std::string uri_encode(const std::string &in); std::string uri_decode(const std::string &in); std::string encode_int(long long n, int base=10); @@ -35,6 +37,27 @@ std::string encode_int(long long n, int base=10); long long parse_int(const std::string &s); void cloexec(int fd); -void fatal(std::string msg); +void fatal(std::string msg) __attribute__((noreturn)); + +/* Date/time string formatting and parsing utility functions. All data and + * methods are static, so this class should not be instantiated. */ +class TimeFormat { +public: + // Abbreviated time format encoded in snapshot file names. + static const char FORMAT_FILENAME[]; + // A timestamp, in UTC, written out in an ISO 8601 format (compatible with + // the SQLite datetime function). + static const char FORMAT_ISO8601[]; + // Similar to the above, but including a timezone offset. + static const char FORMAT_LOCALTIME[]; + + static std::string format(time_t timestamp, const char *format, bool utc); + + static std::string isoformat(time_t timestamp) + { return format(timestamp, FORMAT_ISO8601, true); } + +private: + TimeFormat() { } +}; #endif // _LBS_TARSTORE_H