[haiku-commits] haiku: hrev48894 - in src/bin/addattr: . src/bin

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 13 Mar 2015 18:09:14 +0100 (CET)

hrev48894 adds 3 changesets to branch 'master'
old head: e40dece194839e6e0c738137467da9f6c7468d27
new head: 78c9dabd9e6a969385b9c1346c4918027b63d1cf
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=78c9dabd9e6a+%5Ee40dece19483

----------------------------------------------------------------------------

06732c7c7183: addattr: minor cleanup.

31a414d453b2: listattr: added support for B_TIME_TYPE.

78c9dabd9e6a: addattr: added support for B_TIME_TYPE.
  
  * Using parsedate().

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 50 insertions(+), 31 deletions(-)
src/bin/addattr/addAttr.cpp | 40 ++++++++++++++++++++++++----------------
src/bin/addattr/addAttr.h   |  7 ++++---
src/bin/addattr/main.cpp    | 23 ++++++++++++-----------
src/bin/listattr.cpp        | 11 ++++++++++-

############################################################################

Commit:      06732c7c7183ff41620a802729d90605ba46d567
URL:         http://cgit.haiku-os.org/haiku/commit/?id=06732c7c7183
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Fri Mar 13 11:38:04 2015 UTC

addattr: minor cleanup.

----------------------------------------------------------------------------

diff --git a/src/bin/addattr/addAttr.cpp b/src/bin/addattr/addAttr.cpp
index b4ff765..5dd1eaa 100644
--- a/src/bin/addattr/addAttr.cpp
+++ b/src/bin/addattr/addAttr.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2006, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2004-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Copyright 2002, Sebastian Nozzi.
  *
  * Distributed under the terms of the MIT license.
@@ -23,7 +23,7 @@
 
 template<class Type>
 ssize_t
-writeAttrValue(int fd, const char *name, type_code type, Type value)
+writeAttrValue(int fd, const char* name, type_code type, Type value)
 {
        ssize_t bytes = fs_write_attr(fd, name, type, 0, &value, sizeof(Type));
        if (bytes < 0)
@@ -33,15 +33,14 @@ writeAttrValue(int fd, const char *name, type_code type, 
Type value)
 }
 
 
-/**    Writes an attribute to a node, taking the type into account and
- *     converting the value accordingly
- *
- *     On success it will return the amount of bytes written
- *     On failure it returns an error code (negative number)
- */
+/*!    Writes an attribute to a node, taking the type into account and
+       converting the value accordingly
 
+       On success it will return the amount of bytes written
+       On failure it returns an error code (negative number)
+*/
 static ssize_t
-writeAttr(int fd, type_code type, const char *name, const char *value, size_t 
length)
+writeAttr(int fd, type_code type, const char* name, const char* value, size_t 
length)
 {
        uint64 uint64value = 0;
        int64 int64value = 0;
@@ -129,15 +128,14 @@ writeAttr(int fd, type_code type, const char *name, const 
char *value, size_t le
 }
 
 
-/**    Adds an attribute to a file for the given type, name and value
- *     Converts the value accordingly in case of numeric or boolean types
- *
- *     On success, it returns B_OK, or else an appropriate error code.
- */
+/*!    Adds an attribute to a file for the given type, name and value
+       Converts the value accordingly in case of numeric or boolean types
 
+       On success, it returns B_OK, or else an appropriate error code.
+*/
 status_t
-addAttr(const char *file, type_code type, const char *name,
-       const char *value, size_t length, bool resolveLinks)
+addAttr(const char* file, type_code type, const char* name,
+       const char* value, size_t length, bool resolveLinks)
 {
        int fd = open(file, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE));
        if (fd < 0)
diff --git a/src/bin/addattr/addAttr.h b/src/bin/addattr/addAttr.h
index 1190b01..d086261 100644
--- a/src/bin/addattr/addAttr.h
+++ b/src/bin/addattr/addAttr.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2006, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2004-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Copyright 2002, Sebastian Nozzi.
  *
  * Distributed under the terms of the MIT license.
@@ -11,7 +11,8 @@
 #include <SupportDefs.h>
 
 
-status_t addAttr(const char *file, type_code attrType, const char *attrName,
-       const char *attrValue, size_t length, bool resolveLinks);
+status_t addAttr(const char* file, type_code attrType, const char* attrName,
+       const char* attrValue, size_t length, bool resolveLinks);
+
 
 #endif /* _ADD_ATTR_H */
diff --git a/src/bin/addattr/main.cpp b/src/bin/addattr/main.cpp
index 50c89e1..3d77e50 100644
--- a/src/bin/addattr/main.cpp
+++ b/src/bin/addattr/main.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2010, Jérôme Duval.
- * Copyright 2004-2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2004-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Copyright 2002, Sebastian Nozzi.
  *
  * Distributed under the terms of the MIT license.
@@ -80,7 +80,7 @@ const uint32 kNumSupportedTypes = sizeof(kSupportedTypes)
        On failure, B_BAD_VALUE is returned and "result" is not modified
 */
 static status_t
-typeForString(const char *string, type_code *_result)
+typeForString(const char* string, type_code* _result)
 {
        for (uint32 i = 0; i < kNumSupportedTypes; i++) {
                if (!strcmp(string, kSupportedTypes[i].name)) {
@@ -134,7 +134,7 @@ invalidAttrType(const char *attrTypeName)
 
 
 void
-invalidBoolValue(const char *value)
+invalidBoolValue(const char* value)
 {
        fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", 
kProgramName,
                value);
@@ -146,10 +146,10 @@ invalidBoolValue(const char *value)
 
 
 int
-main(int argc, char *argv[])
+main(int argc, char* argv[])
 {
        type_code attrType = B_STRING_TYPE;
-       char *attrValue = NULL;
+       char* attrValue = NULL;
        size_t valueFileLength = 0;
        bool resolveLinks = true;
 
@@ -181,7 +181,7 @@ main(int argc, char *argv[])
                                                        " bytes\n", size);
                                                return 1;
                                        }
-                                       attrValue = (char *)malloc(size);
+                                       attrValue = (char*)malloc(size);
                                        if (attrValue != NULL)
                                                status = file.Read(attrValue, 
size);
                                        else
@@ -215,7 +215,7 @@ main(int argc, char *argv[])
        
        if (argc - optind < 1)
                usage(1);
-       const char *attrName = argv[optind++];
+       const char* attrName = argv[optind++];
 
        if (argc - optind < 1)
                usage(1);

############################################################################

Commit:      31a414d453b26ac0d50e16a40e3ff18a9f77613d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=31a414d453b2
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Fri Mar 13 12:44:22 2015 UTC

listattr: added support for B_TIME_TYPE.

----------------------------------------------------------------------------

diff --git a/src/bin/listattr.cpp b/src/bin/listattr.cpp
index 13e4010..00e0a19 100644
--- a/src/bin/listattr.cpp
+++ b/src/bin/listattr.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2004-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  * Copyright 2002, Ryan Fleet.
  *
  * Distributed under the terms of the MIT license.
@@ -111,6 +111,15 @@ show_attr_contents(BNode& node, const char* attribute, 
const attr_info& info)
                case B_BOOL_TYPE:
                        printf("%d\n", *((unsigned char *)buffer));
                        break;
+               case B_TIME_TYPE:
+               {
+                       char stringBuffer[256];
+                       struct tm timeInfo;
+                       localtime_r((time_t *)buffer, &timeInfo);
+                       strftime(stringBuffer, sizeof(stringBuffer), "%c", 
&timeInfo);
+                       printf("%s\n", stringBuffer);
+                       break;
+               }
                case B_STRING_TYPE:
                case B_MIME_STRING_TYPE:
                case 'MSIG':

############################################################################

Revision:    hrev48894
Commit:      78c9dabd9e6a969385b9c1346c4918027b63d1cf
URL:         http://cgit.haiku-os.org/haiku/commit/?id=78c9dabd9e6a
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Fri Mar 13 12:44:57 2015 UTC

addattr: added support for B_TIME_TYPE.

* Using parsedate().

----------------------------------------------------------------------------

diff --git a/src/bin/addattr/addAttr.cpp b/src/bin/addattr/addAttr.cpp
index 5dd1eaa..94b620d 100644
--- a/src/bin/addattr/addAttr.cpp
+++ b/src/bin/addattr/addAttr.cpp
@@ -12,6 +12,7 @@
 #include <Mime.h>
 
 #include <fs_attr.h>
+#include <parsedate.h>
 
 #include <ctype.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);
                }
 
+               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_MIME_STRING_TYPE:
                default:
diff --git a/src/bin/addattr/main.cpp b/src/bin/addattr/main.cpp
index 3d77e50..d1994ac 100644
--- a/src/bin/addattr/main.cpp
+++ b/src/bin/addattr/main.cpp
@@ -64,8 +64,9 @@ const struct {
 
        {B_BOOL_TYPE, "bool"},
 
-       {B_VECTOR_ICON_TYPE, "icon"},
+       {B_TIME_TYPE, "time"},
 
+       {B_VECTOR_ICON_TYPE, "icon"},
        {B_RAW_TYPE, "raw"},
 };
 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"
                "\t-P : Don't resolve links\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"
                "\tThe default is \"string\"\n", kProgramName, kProgramName);
 
@@ -121,12 +122,12 @@ usage(int returnValue)
 
 
 void
-invalidAttrType(const char *attrTypeName)
+invalidAttrType(const char* attrTypeName)
 {
        fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", 
kProgramName,
                attrTypeName);
        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");
 
        exit(1);


Other related posts:

  • » [haiku-commits] haiku: hrev48894 - in src/bin/addattr: . src/bin - axeld