Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

info1686

macrumors newbie
Original poster
Jan 21, 2009
13
0
This program has been written under Mac OS X 10.4

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
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
The size parameter should probably be the size of the data you are actually passing in, not some arbitrary max. size.
 

info1686

macrumors newbie
Original poster
Jan 21, 2009
13
0
in the setxattr call i changed size to xattr_size and now it works fine

Thanks for the help....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.