addattr: added support for B_TIME_TYPE.

* Using parsedate().
This commit is contained in:
Axel Dörfler
2015-03-13 13:44:57 +01:00
parent 31a414d453
commit 78c9dabd9e
2 changed files with 15 additions and 4 deletions
+10
View File
@@ -12,6 +12,7 @@
#include <Mime.h> #include <Mime.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <parsedate.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
@@ -112,6 +113,15 @@ writeAttr(int fd, type_code type, const char* name, const char* value, size_t le
return writeAttrValue<uint8>(fd, name, B_BOOL_TYPE, boolValue); return writeAttrValue<uint8>(fd, name, B_BOOL_TYPE, boolValue);
} }
case B_TIME_TYPE:
{
time_t timeValue = parsedate(value, time(NULL));
if (timeValue < 0)
return B_BAD_VALUE;
return writeAttrValue<time_t>(fd, name, B_TIME_TYPE, timeValue);
}
case B_STRING_TYPE: case B_STRING_TYPE:
case B_MIME_STRING_TYPE: case B_MIME_STRING_TYPE:
default: default:
+5 -4
View File
@@ -64,8 +64,9 @@ const struct {
{B_BOOL_TYPE, "bool"}, {B_BOOL_TYPE, "bool"},
{B_VECTOR_ICON_TYPE, "icon"}, {B_TIME_TYPE, "time"},
{B_VECTOR_ICON_TYPE, "icon"},
{B_RAW_TYPE, "raw"}, {B_RAW_TYPE, "raw"},
}; };
const uint32 kNumSupportedTypes = sizeof(kSupportedTypes) const uint32 kNumSupportedTypes = sizeof(kSupportedTypes)
@@ -112,7 +113,7 @@ usage(int returnValue)
" or: %s [-f value-from-file] [-t type] [ -P ] attr file1 [file2...]\n\n" " or: %s [-f value-from-file] [-t type] [ -P ] attr file1 [file2...]\n\n"
"\t-P : Don't resolve links\n" "\t-P : Don't resolve links\n"
"\tType is one of:\n" "\tType is one of:\n"
"\t\tstring, mime, int, llong, float, double, bool, icon, raw\n" "\t\tstring, mime, int, llong, float, double, bool, time, icon, raw\n"
"\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n" "\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n"
"\tThe default is \"string\"\n", kProgramName, kProgramName); "\tThe default is \"string\"\n", kProgramName, kProgramName);
@@ -121,12 +122,12 @@ usage(int returnValue)
void void
invalidAttrType(const char *attrTypeName) invalidAttrType(const char* attrTypeName)
{ {
fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", kProgramName, fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", kProgramName,
attrTypeName); attrTypeName);
fprintf(stderr, "\tTry one of: string, mime, int, llong, float, double,\n"); fprintf(stderr, "\tTry one of: string, mime, int, llong, float, double,\n");
fprintf(stderr, "\t\tbool, icon, raw, or a numeric value (ie. 0x1234, 42, 'ABCD'" fprintf(stderr, "\t\tbool, time, icon, raw, or a numeric value (ie. 0x1234, 42, 'ABCD'"
", ...)\n"); ", ...)\n");
exit(1); exit(1);