addattr: minor cleanup.
This commit is contained in:
parent
e40dece194
commit
06732c7c71
@ -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.
|
* Copyright 2002, Sebastian Nozzi.
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
ssize_t
|
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));
|
ssize_t bytes = fs_write_attr(fd, name, type, 0, &value, sizeof(Type));
|
||||||
if (bytes < 0)
|
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
|
/*! Writes an attribute to a node, taking the type into account and
|
||||||
* converting the value accordingly
|
converting the value accordingly
|
||||||
*
|
|
||||||
* On success it will return the amount of bytes written
|
|
||||||
* On failure it returns an error code (negative number)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
On success it will return the amount of bytes written
|
||||||
|
On failure it returns an error code (negative number)
|
||||||
|
*/
|
||||||
static ssize_t
|
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;
|
uint64 uint64value = 0;
|
||||||
int64 int64value = 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
|
/*! Adds an attribute to a file for the given type, name and value
|
||||||
* Converts the value accordingly in case of numeric or boolean types
|
Converts the value accordingly in case of numeric or boolean types
|
||||||
*
|
|
||||||
* On success, it returns B_OK, or else an appropriate error code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
On success, it returns B_OK, or else an appropriate error code.
|
||||||
|
*/
|
||||||
status_t
|
status_t
|
||||||
addAttr(const char *file, type_code type, const char *name,
|
addAttr(const char* file, type_code type, const char* name,
|
||||||
const char *value, size_t length, bool resolveLinks)
|
const char* value, size_t length, bool resolveLinks)
|
||||||
{
|
{
|
||||||
int fd = open(file, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE));
|
int fd = open(file, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE));
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -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.
|
* Copyright 2002, Sebastian Nozzi.
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
@ -11,7 +11,8 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
status_t addAttr(const char *file, type_code attrType, const char *attrName,
|
status_t addAttr(const char* file, type_code attrType, const char* attrName,
|
||||||
const char *attrValue, size_t length, bool resolveLinks);
|
const char* attrValue, size_t length, bool resolveLinks);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _ADD_ATTR_H */
|
#endif /* _ADD_ATTR_H */
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010, Jérôme Duval.
|
* 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.
|
* Copyright 2002, Sebastian Nozzi.
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the MIT license.
|
* 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
|
On failure, B_BAD_VALUE is returned and "result" is not modified
|
||||||
*/
|
*/
|
||||||
static status_t
|
static status_t
|
||||||
typeForString(const char *string, type_code *_result)
|
typeForString(const char* string, type_code* _result)
|
||||||
{
|
{
|
||||||
for (uint32 i = 0; i < kNumSupportedTypes; i++) {
|
for (uint32 i = 0; i < kNumSupportedTypes; i++) {
|
||||||
if (!strcmp(string, kSupportedTypes[i].name)) {
|
if (!strcmp(string, kSupportedTypes[i].name)) {
|
||||||
@ -134,7 +134,7 @@ invalidAttrType(const char *attrTypeName)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
invalidBoolValue(const char *value)
|
invalidBoolValue(const char* value)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", kProgramName,
|
fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", kProgramName,
|
||||||
value);
|
value);
|
||||||
@ -146,10 +146,10 @@ invalidBoolValue(const char *value)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
type_code attrType = B_STRING_TYPE;
|
type_code attrType = B_STRING_TYPE;
|
||||||
char *attrValue = NULL;
|
char* attrValue = NULL;
|
||||||
size_t valueFileLength = 0;
|
size_t valueFileLength = 0;
|
||||||
bool resolveLinks = true;
|
bool resolveLinks = true;
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ main(int argc, char *argv[])
|
|||||||
" bytes\n", size);
|
" bytes\n", size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
attrValue = (char *)malloc(size);
|
attrValue = (char*)malloc(size);
|
||||||
if (attrValue != NULL)
|
if (attrValue != NULL)
|
||||||
status = file.Read(attrValue, size);
|
status = file.Read(attrValue, size);
|
||||||
else
|
else
|
||||||
@ -215,7 +215,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (argc - optind < 1)
|
if (argc - optind < 1)
|
||||||
usage(1);
|
usage(1);
|
||||||
const char *attrName = argv[optind++];
|
const char* attrName = argv[optind++];
|
||||||
|
|
||||||
if (argc - optind < 1)
|
if (argc - optind < 1)
|
||||||
usage(1);
|
usage(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user