This program has been written under Mac OS X 10.4
when setxattr fails it gives this output :
setxattr failed
: Result too large
Code:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<errno.h>
#include<sys/syslimits.h>
#include<sys/xattr.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
struct stat statbuf ;
int ret ;
char buf[PATH_MAX + 1] ;
char *name = "com.apple.FinderInfo" ;
size_t size = 4096 ;
void *value ;
ssize_t count , xattr_size ;
if(argc == 3)
{
ret = lstat(argv[1] , &statbuf) ;
if(ret != 0)
{
perror("lstat failed\n");
return 0;
}
if(S_ISLNK(statbuf.st_mode))
printf("%s is a symbolic link\n",argv[1]) ;
ret = readlink(argv[1] , buf , PATH_MAX) ;
if(ret == -1)
{
perror("readlink failed\n");
return 0;
}
else
printf("target of %s = %s\n",argv[1],buf) ;
count = getxattr(argv[1],name,NULL,size,0,XATTR_NOFOLLOW) ;
if(count == -1)
printf("getxattr failed\n") ;
else
{
printf("count = %u\n",count) ;
value=malloc(count + 1) ;
xattr_size = getxattr(argv[1],name,value,count+1,0,XATTR_NOFOLLOW) ;
if(xattr_size == -1)
{
printf("getxattr failed\n");
return 0;
}
}
ret = symlink(buf , argv[2]) ;
if(ret != 0)
{
perror("symlink failed\n");
return 0;
}
else
{
printf("symbolic link created\n") ;
ret = setxattr(argv[2],name,value,size,0,XATTR_NOFOLLOW) ;
if(ret == 0)
printf("setxattr success\n");
else
perror("setxattr failed\n");
}
}
return 0;
}
when setxattr fails it gives this output :
setxattr failed
: Result too large