Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Node.h>
- #include <TypeConstants.h>
- #include <fs_attr.h>
- #include <stdio.h>
- #include <string.h>
- int
- main(int argc, char *argv[])
- {
- if (argc < 3) {
- printf("usage: %s <fileName> <attributeName> <valueToAppend>\n",
- argv[0]);
- exit(1);
- }
- const char *fileName = argv[1];
- const char *attrName = argv[2];
- const char *value = argv[3];
- BNode node(fileName);
- status_t result = node.InitCheck();
- if (result != B_OK) {
- printf("failed to open node \"%s\": %s\n", fileName, strerror(result));
- exit(2);
- }
- attr_info attrInfo;
- result = node.GetAttrInfo(attrName, &attrInfo);
- if (result == B_ENTRY_NOT_FOUND) {
- // No attribute yet, pretend it's there but has length 0
- attrInfo.type = B_STRING_TYPE;
- attrInfo.size = 0;
- } else if (result != B_OK) {
- printf("failed to get info for attribute \"%s\": %s\n", attrName,
- strerror(result));
- exit(3);
- }
- if (attrInfo.type != B_STRING_TYPE) {
- printf("attribute \"%s\" isn't a string, aborting\n", attrName);
- exit(4);
- }
- ssize_t written = node.WriteAttr(attrName, attrInfo.type, attrInfo.size,
- value, strlen(value));
- if (written < 0) {
- printf("failed to append to attribute: %s\n", strerror(written));
- exit(5);
- }
- printf("appended %" B_PRIdSSIZE " bytes to to attribute \"%s\" of \"%s\"\n",
- written, attrName, fileName);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement