Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dustin L. Howett
rexattr
Commits
4c8bf5a0
Commit
4c8bf5a0
authored
Sep 26, 2016
by
Dustin L. Howett
Browse files
rexattr
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
rexattr.cc
0 → 100644
View file @
4c8bf5a0
#include
<ftw.h>
#include
<sys/time.h>
#include
<sys/resource.h>
#include
<sys/types.h>
#include
<attr/xattr.h>
#include
<cstdio>
#include
<cstring>
#include
<vector>
std
::
vector
<
char
>
g_xaBuffer
(
16384
);
std
::
vector
<
char
>
g_xaList
(
2048
);
int
main
(
int
argc
,
char
**
argv
,
char
**
envp
)
{
struct
stat
sb
;
struct
rlimit
rlim
;
getrlimit
(
RLIMIT_NOFILE
,
&
rlim
);
nftw
(
argv
[
1
],
[](
const
char
*
fpath
,
const
struct
stat
*
sb
,
int
typeflag
,
struct
FTW
*
ftwbuf
)
{
ssize_t
lSize
=
-
1
;
do
{
lSize
=
llistxattr
(
fpath
,
g_xaList
.
data
(),
g_xaList
.
capacity
());
if
(
lSize
<
0
&&
errno
==
ERANGE
)
{
g_xaList
.
reserve
(
g_xaList
.
capacity
()
*
2
);
}
else
if
(
lSize
<
0
)
{
perror
(
"failed to get xa list"
);
return
1
;
}
}
while
(
lSize
<
0
);
if
(
lSize
==
0
)
{
return
0
;
}
llistxattr
(
fpath
,
g_xaList
.
data
(),
lSize
);
fprintf
(
stderr
,
"%s
\n
"
,
fpath
);
const
char
*
lbuf
=
g_xaList
.
data
();
for
(
const
char
*
xa
=
lbuf
;
xa
<
lbuf
+
lSize
;
xa
+=
strlen
(
xa
)
+
1
)
{
ssize_t
xaSize
=
-
1
;
do
{
xaSize
=
lgetxattr
(
fpath
,
xa
,
g_xaBuffer
.
data
(),
g_xaBuffer
.
capacity
());
if
(
xaSize
<
0
&&
errno
==
ERANGE
)
{
g_xaBuffer
.
reserve
(
g_xaBuffer
.
capacity
()
*
2
);
}
else
if
(
xaSize
<
0
)
{
perror
(
"failed to read xattr"
);
return
1
;
}
}
while
(
xaSize
<
0
);
lremovexattr
(
fpath
,
xa
);
lsetxattr
(
fpath
,
xa
,
g_xaBuffer
.
data
(),
xaSize
,
XATTR_CREATE
);
}
return
0
;
},
rlim
.
rlim_max
/
2
,
FTW_PHYS
|
FTW_MOUNT
);
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment