5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 15:42:53 +08:00
wails/v2/internal/xattr/xattr.go
2024-03-20 19:08:47 +11:00

35 lines
803 B
Go

package xattr
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <sys/xattr.h>
#include <stdlib.h>
#include <string.h>
void removeXattrFrom(const char *path) {
ssize_t xattrNamesSize = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
if (xattrNamesSize <= 0) return;
char *xattrNames = (char *)malloc(xattrNamesSize);
xattrNamesSize = listxattr(path, xattrNames, xattrNamesSize, XATTR_NOFOLLOW);
ssize_t pos = 0;
while (pos < xattrNamesSize) {
char *name = xattrNames + pos;
removexattr(path, name, XATTR_NOFOLLOW);
pos += strlen(name) + 1;
}
free(xattrNames);
}
*/
import "C"
import "unsafe"
func RemoveXAttr(filepath string) {
cpath := C.CString(filepath)
defer C.free(unsafe.Pointer(cpath))
C.removeXattrFrom(cpath)
}