* Now reports a proper error when the attribute file is empty (instead of just
printing the usage info). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22984 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+23
-13
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Axel Dörfler, [email protected].
|
* Copyright 2004-2007, Axel Dörfler, [email protected].
|
||||||
* Copyright 2002, Sebastian Nozzi.
|
* Copyright 2002, Sebastian Nozzi.
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
// supported types (if you add any, make sure that writeAttr() handles them properly)
|
// supported types (if you add any, make sure that writeAttr() handles
|
||||||
|
// them properly)
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
type_code type;
|
type_code type;
|
||||||
@@ -43,19 +44,19 @@ const struct {
|
|||||||
|
|
||||||
{B_RAW_TYPE, "raw"},
|
{B_RAW_TYPE, "raw"},
|
||||||
};
|
};
|
||||||
const uint32 kNumSupportedTypes = sizeof(kSupportedTypes) / sizeof(kSupportedTypes[0]);
|
const uint32 kNumSupportedTypes = sizeof(kSupportedTypes)
|
||||||
|
/ sizeof(kSupportedTypes[0]);
|
||||||
|
|
||||||
char *gProgramName;
|
char *gProgramName;
|
||||||
|
|
||||||
|
|
||||||
/** For the given string that the user specifies as attribute type
|
/*! For the given string that the user specifies as attribute type
|
||||||
* in the command line, this function tries to figure out the
|
in the command line, this function tries to figure out the
|
||||||
* corresponding Be API value.
|
corresponding Be API value.
|
||||||
*
|
|
||||||
* On success, "result" will contain that value
|
|
||||||
* On failure, B_BAD_VALUE is returned and "result" is not modified
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
On success, "result" will contain that value
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
@@ -107,9 +108,11 @@ assertArgument(int i, int argc)
|
|||||||
void
|
void
|
||||||
invalidAttrType(const char *attrTypeName)
|
invalidAttrType(const char *attrTypeName)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", gProgramName, attrTypeName);
|
fprintf(stderr, "%s: attribute type \"%s\" is not valid\n", gProgramName,
|
||||||
|
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, raw, or a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n");
|
fprintf(stderr, "\t\tbool, raw, or a numeric value (ie. 0x1234, 42, 'ABCD'"
|
||||||
|
", ...)\n");
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -118,7 +121,8 @@ invalidAttrType(const char *attrTypeName)
|
|||||||
void
|
void
|
||||||
invalidBoolValue(const char *value)
|
invalidBoolValue(const char *value)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", gProgramName, value);
|
fprintf(stderr, "%s: attribute value \"%s\" is not valid\n", gProgramName,
|
||||||
|
value);
|
||||||
fprintf(stderr, "\tBool accepts: 0, f, false, disabled, off,\n");
|
fprintf(stderr, "\tBool accepts: 0, f, false, disabled, off,\n");
|
||||||
fprintf(stderr, "\t\t1, t, true, enabled, on\n");
|
fprintf(stderr, "\t\t1, t, true, enabled, on\n");
|
||||||
|
|
||||||
@@ -160,6 +164,12 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
status = file.GetSize(&size);
|
status = file.GetSize(&size);
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
|
if (size == 0) {
|
||||||
|
fprintf(stderr, "%s: attribute value is empty: 0 bytes\n",
|
||||||
|
gProgramName);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (size > 4 * 1024 * 1024) {
|
if (size > 4 * 1024 * 1024) {
|
||||||
fprintf(stderr, "%s: attribute value is too large: %Ld bytes\n",
|
fprintf(stderr, "%s: attribute value is too large: %Ld bytes\n",
|
||||||
gProgramName, size);
|
gProgramName, size);
|
||||||
|
|||||||
Reference in New Issue
Block a user