addattr: minor cleanup.

This commit is contained in:
Axel Dörfler 2015-03-13 12:38:04 +01:00
parent e40dece194
commit 06732c7c71
3 changed files with 25 additions and 26 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2004-2015, Axel Dörfler, axeld@pinc-software.de.
* 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)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2004-2015, Axel Dörfler, axeld@pinc-software.de.
* 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 */

View File

@ -1,6 +1,6 @@
/*
* Copyright 2010, Jérôme Duval.
* Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2004-2015, Axel Dörfler, axeld@pinc-software.de.
* 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);