fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. struct Xattr_value
  7. {
  8. map<std::string, std::string> xattr_values;
  9. void *value;
  10. map<std::string, size_t> size;
  11. int flags;
  12. };
  13. map<std::string, struct Xattr_value *> xattr_list;
  14.  
  15. void setxattr(const char *path, const char *name, const char *value, size_t size, int flags){
  16.  
  17. std::string str_path(path);
  18. std::string str_name(name);
  19. std::string str_value(value);
  20.  
  21. if ( (xattr_list.find(str_path) != xattr_list.end()) ){
  22. printf ("setxattr. Path exist\n");
  23. xattr_list[str_path]->xattr_values[str_name] = str_value;
  24. xattr_list[str_path]->size[str_name] = size;
  25. }else{
  26. printf ("setxattr. Path NO exist\n");
  27. Xattr_value *thisval = new Xattr_value;
  28. thisval->xattr_values[str_name] = str_value;
  29. thisval->size[str_name] = size;
  30. //thisval->flags = flags;
  31. xattr_list[str_path] = thisval;
  32. }
  33.  
  34.  
  35. }
  36.  
  37. void getxattr(const char *path, const char *name, char *value, size_t size){
  38. std::string str_path(path);
  39. std::string str_name(name);
  40.  
  41. if ( (xattr_list.find(str_path) != xattr_list.end()) ){
  42. if ( xattr_list[str_path]->xattr_values.find(str_name) != xattr_list[str_path]->xattr_values.end() ){
  43. size = xattr_list[str_path]->size[str_name];
  44. value = (char *)malloc(6);
  45. value = "test";
  46. printf("Now I st the value %s\n", value);
  47. //strcpy(value,xattr_list[str_path]->xattr_values[str_name].c_str());
  48.  
  49.  
  50. }else{ printf("No name found on getxattr\n"); }
  51. }else{ printf("No path found on getxattr\n"); }
  52.  
  53.  
  54. }
  55.  
  56. int main() {
  57. printf("1\n");
  58.  
  59. const char *path = "path";
  60. char *name = "one key name";
  61. const char *value = "this 1";
  62. size_t size = 6;
  63. int flags = 1;
  64. setxattr(path, name, value, size, flags);
  65.  
  66. const char *name2 = "second key name";
  67. const char *value2 = "this 2";
  68. setxattr(path, name2, value2, size, flags);
  69.  
  70.  
  71.  
  72.  
  73. char *get_value;
  74. getxattr(path, name, get_value, size);
  75. get_value = (char *)malloc(size);
  76. printf("Now I get the value %s\n", get_value);
  77.  
  78.  
  79. }
Success #stdin #stdout 0s 3240KB
stdin
Standard input is empty
stdout
1
setxattr. Path NO exist
setxattr. Path exist
Now I st the value test
Now I get the value