|
a/pxattr.cpp |
|
b/pxattr.cpp |
|
... |
|
... |
25 |
|
25 |
|
26 |
/** \file pxattr.cpp
|
26 |
/** \file pxattr.cpp
|
27 |
\brief Portable External Attributes API
|
27 |
\brief Portable External Attributes API
|
28 |
*/
|
28 |
*/
|
29 |
|
29 |
|
|
|
30 |
// PXALINUX: platforms like kfreebsd which aren't linux but use the
|
|
|
31 |
// same xattr interface
|
30 |
#if defined(__gnu_linux__) || \
|
32 |
#if defined(__gnu_linux__) || \
|
31 |
(defined(__FreeBSD_kernel__)&&defined(__GLIBC__)&&!defined(__FreeBSD__)) ||\
|
33 |
(defined(__FreeBSD_kernel__)&&defined(__GLIBC__)&&!defined(__FreeBSD__)) ||\
|
32 |
defined(__CYGWIN__)
|
34 |
defined(__CYGWIN__)
|
33 |
#define PXALINUX
|
35 |
#define PXALINUX
|
34 |
#endif
|
36 |
#endif
|
35 |
|
37 |
|
36 |
// If the platform is not supported, let this file be empty instead of
|
38 |
// If the platform is not known yet, let this file be empty instead of
|
37 |
// breaking the compile, this will let the build work if the rest of
|
39 |
// breaking the compile, this will let the build work if the rest of
|
38 |
// the software is not actually calling us.
|
40 |
// the software is not actually calling us. If it does call us, this
|
|
|
41 |
// will bring attention to the necessity of a port.
|
|
|
42 |
//
|
|
|
43 |
// If the platform is known not to support extattrs (e.g.__OpenBSD__),
|
|
|
44 |
// just let the methods return errors (like they would on a non-xattr
|
|
|
45 |
// fs on e.g. linux)
|
|
|
46 |
|
|
|
47 |
#if defined(__DragonFly__) || defined(__OpenBSD__)
|
|
|
48 |
#define HAS_NO_XATTR
|
|
|
49 |
#endif
|
|
|
50 |
|
39 |
#if defined(__FreeBSD__) || defined(PXALINUX) || defined(__APPLE__)
|
51 |
#if defined(__FreeBSD__) || defined(PXALINUX) || defined(__APPLE__) \
|
|
|
52 |
|| defined(HAS_NO_XATTR)
|
40 |
|
53 |
|
41 |
|
54 |
|
42 |
#ifndef TEST_PXATTR
|
55 |
#ifndef TEST_PXATTR
|
43 |
#include <sys/types.h>
|
56 |
#include <sys/types.h>
|
44 |
#include <errno.h>
|
57 |
#include <errno.h>
|
|
... |
|
... |
50 |
#include <sys/uio.h>
|
63 |
#include <sys/uio.h>
|
51 |
#elif defined(PXALINUX)
|
64 |
#elif defined(PXALINUX)
|
52 |
#include <sys/xattr.h>
|
65 |
#include <sys/xattr.h>
|
53 |
#elif defined(__APPLE__)
|
66 |
#elif defined(__APPLE__)
|
54 |
#include <sys/xattr.h>
|
67 |
#include <sys/xattr.h>
|
|
|
68 |
#elif defined(HAS_NO_XATTR)
|
55 |
#else
|
69 |
#else
|
56 |
#error "Unknown system can't compile"
|
70 |
#error "Unknown system can't compile"
|
57 |
#endif
|
71 |
#endif
|
58 |
|
72 |
|
59 |
#include "pxattr.h"
|
73 |
#include "pxattr.h"
|
|
... |
|
... |
160 |
ret = getxattr(path.c_str(), name.c_str(), buf.buf, ret, 0, 0);
|
174 |
ret = getxattr(path.c_str(), name.c_str(), buf.buf, ret, 0, 0);
|
161 |
}
|
175 |
}
|
162 |
} else {
|
176 |
} else {
|
163 |
ret = fgetxattr(fd, name.c_str(), buf.buf, ret, 0, 0);
|
177 |
ret = fgetxattr(fd, name.c_str(), buf.buf, ret, 0, 0);
|
164 |
}
|
178 |
}
|
|
|
179 |
#else
|
|
|
180 |
errno = ENOTSUP;
|
165 |
#endif
|
181 |
#endif
|
166 |
|
182 |
|
167 |
if (ret >= 0)
|
183 |
if (ret >= 0)
|
168 |
value->assign(buf.buf, ret);
|
184 |
value->assign(buf.buf, ret);
|
169 |
return ret >= 0;
|
185 |
return ret >= 0;
|
|
... |
|
... |
255 |
}
|
271 |
}
|
256 |
} else {
|
272 |
} else {
|
257 |
ret = fsetxattr(fd, name.c_str(), value.c_str(),
|
273 |
ret = fsetxattr(fd, name.c_str(), value.c_str(),
|
258 |
value.length(), 0, opts);
|
274 |
value.length(), 0, opts);
|
259 |
}
|
275 |
}
|
|
|
276 |
#else
|
|
|
277 |
errno = ENOTSUP;
|
260 |
#endif
|
278 |
#endif
|
261 |
return ret >= 0;
|
279 |
return ret >= 0;
|
262 |
}
|
280 |
}
|
263 |
|
281 |
|
264 |
static bool
|
282 |
static bool
|
|
... |
|
... |
300 |
ret = removexattr(path.c_str(), name.c_str(), 0);
|
318 |
ret = removexattr(path.c_str(), name.c_str(), 0);
|
301 |
}
|
319 |
}
|
302 |
} else {
|
320 |
} else {
|
303 |
ret = fremovexattr(fd, name.c_str(), 0);
|
321 |
ret = fremovexattr(fd, name.c_str(), 0);
|
304 |
}
|
322 |
}
|
|
|
323 |
#else
|
|
|
324 |
errno = ENOTSUP;
|
305 |
#endif
|
325 |
#endif
|
306 |
return ret >= 0;
|
326 |
return ret >= 0;
|
307 |
}
|
327 |
}
|
308 |
|
328 |
|
309 |
static bool
|
329 |
static bool
|
|
... |
|
... |
382 |
ret = listxattr(path.c_str(), buf.buf, ret, 0);
|
402 |
ret = listxattr(path.c_str(), buf.buf, ret, 0);
|
383 |
}
|
403 |
}
|
384 |
} else {
|
404 |
} else {
|
385 |
ret = flistxattr(fd, buf.buf, ret, 0);
|
405 |
ret = flistxattr(fd, buf.buf, ret, 0);
|
386 |
}
|
406 |
}
|
|
|
407 |
#else
|
|
|
408 |
errno = ENOTSUP;
|
387 |
#endif
|
409 |
#endif
|
|
|
410 |
|
|
|
411 |
if (ret < 0)
|
|
|
412 |
return false;
|
388 |
|
413 |
|
389 |
char *bufstart = buf.buf;
|
414 |
char *bufstart = buf.buf;
|
390 |
|
415 |
|
391 |
// All systems return a 0-separated string list except FreeBSD
|
416 |
// All systems return a 0-separated string list except FreeBSD
|
392 |
// which has length, value pairs, length is a byte.
|
417 |
// which has length, value pairs, length is a byte.
|