本文介绍了系统文件,读写o创建自定义元数据或属性扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
:
我正在寻找一种从任何文件读取,写入或创建(自定义)标签,扩展属性或元数据的方法。没有库和语言c或c ++。我想我可以用fopen,fread,fwrite,但不能如何访问元数据。
I am looking for a way to read, write or create (custom) tags, extended attributes or metadata from any file. Without libraries and language c or c + +. I think I can be with fopen, fread, fwrite, but not how to access the metadata.
先感谢,
推荐答案
Linux系统调用扩展属性操作 setxattr
, getxattr
和 remotexattr
。此程序可能会执行您要求的操作:
The Linux system calls for manipulating extended attributes are setxattr
, getxattr
, and remotexattr
. This program might do what you are asking for:
// UNTESTED
#include <sys/types.h>
#include <sys/xattr.h>
#include <cstring>
#include <cstdio>
int main () {
const char* file = "/work/a.txt";
const char* attr = "user.MyAttr";
const char* value = "MyValue";
int rc = setxattr(file, attr, value, strlen(value), 0);
if(rc < 0)
perror(file);
return !!rc;
}
这篇关于系统文件,读写o创建自定义元数据或属性扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!