mirror of
https://github.com/ksherlock/dot_clean.git
synced 2025-04-07 18:38:43 +00:00
split xattr functions.
This commit is contained in:
parent
855c19eda5
commit
3e3be4f9e3
4
Makefile
4
Makefile
@ -1,10 +1,12 @@
|
||||
LINK.o = $(LINK.cc)
|
||||
CXXFLAGS += -std=c++11 -g -Wall
|
||||
|
||||
dot_clean: dot_clean.o mapped_file.o finder_info_helper.o
|
||||
dot_clean: dot_clean.o mapped_file.o finder_info_helper.o xattr.o
|
||||
|
||||
mapped_file.o : mapped_file.cpp mapped_file.h unique_resource.h
|
||||
|
||||
dot_clean.o : dot_clean.cpp mapped_file.h applefile.h defer.h
|
||||
|
||||
finder_info_helper.o: finder_info_helper.cpp finder_info_helper.h
|
||||
|
||||
xattr.o : xattr.c xattr.h
|
||||
|
@ -8,25 +8,17 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "xattr.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <sys/xattr.h>
|
||||
#define XATTR_FINDERINFO_NAME "user.com.apple.FinderInfo"
|
||||
#define XATTR_RESOURCEFORK_NAME "user.com.apple.ResourceFork"
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/extattr.h>
|
||||
#endif
|
||||
|
||||
#if defined(_AIX)
|
||||
#include <sys/ea.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (_WIN32)
|
||||
#define XATTR_FINDERINFO_NAME "AFP_AfpInfo"
|
||||
@ -206,94 +198,6 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* extended attributes functions.
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return fgetxattr(fd, xattr, NULL, 0, 0, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetxattr(fd, xattr, buffer, size, 0, 0);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetxattr(fd, xattr, buffer, size, 0, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremovexattr(fd, xattr, 0);
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return fgetxattr(fd, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetxattr(fd, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetxattr(fd, xattr, buffer, size, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremovexattr(fd, xattr);
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
return extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, xattr, buffer, size);
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, xattr);
|
||||
}
|
||||
|
||||
#elif defined(_AIX)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
/*
|
||||
struct stat64x st;
|
||||
if (fstatea(fd, xattr, &st) < 0) return -1;
|
||||
return st.st_size;
|
||||
*/
|
||||
return fgetea(fd, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetea(fd, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetea(fd, xattr, buffer, size, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremoveea(fd, xattr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int fi_open(const std::string &path, bool read_only) {
|
||||
|
||||
#if defined(__sun__)
|
||||
|
101
xattr.c
Normal file
101
xattr.c
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
#include "xattr.h"
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <sys/xattr.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/extattr.h>
|
||||
#endif
|
||||
|
||||
#if defined(_AIX)
|
||||
#include <sys/ea.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* extended attributes functions.
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return fgetxattr(fd, xattr, NULL, 0, 0, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetxattr(fd, xattr, buffer, size, 0, 0);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetxattr(fd, xattr, buffer, size, 0, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremovexattr(fd, xattr, 0);
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return fgetxattr(fd, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetxattr(fd, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetxattr(fd, xattr, buffer, size, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremovexattr(fd, xattr);
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
return extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, xattr, buffer, size);
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, xattr);
|
||||
}
|
||||
|
||||
#elif defined(_AIX)
|
||||
ssize_t size_xattr(int fd, const char *xattr) {
|
||||
/*
|
||||
struct stat64x st;
|
||||
if (fstatea(fd, xattr, &st) < 0) return -1;
|
||||
return st.st_size;
|
||||
*/
|
||||
return fgetea(fd, xattr, NULL, 0);
|
||||
}
|
||||
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size) {
|
||||
return fgetea(fd, xattr, buffer, size);
|
||||
}
|
||||
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size) {
|
||||
if (fsetea(fd, xattr, buffer, size, 0) < 0) return -1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int remove_xattr(int fd, const char *xattr) {
|
||||
return fremoveea(fd, xattr);
|
||||
}
|
||||
|
||||
#endif
|
27
xattr.h
Normal file
27
xattr.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef xattr_h
|
||||
#define xattr_h
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef ENOATTR
|
||||
#define ENOATTR ENODATA
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ssize_t size_xattr(int fd, const char *xattr);
|
||||
ssize_t read_xattr(int fd, const char *xattr, void *buffer, size_t size);
|
||||
ssize_t write_xattr(int fd, const char *xattr, const void *buffer, size_t size);
|
||||
int remove_xattr(int fd, const char *xattr);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user