c - Data type of command line args -
i'm struggling convert executable program function can call within main routine. written, executable looks this:
int main(int argc, char* argv[]){ //do stuff if(setxattr(argv[4], tmpstr, argv[3], strlen(argv[3]), 0)){ perror("setxattr error"); exit(exit_failure); } //do more stuff }
i can call follows , works successfully:
./set_attributes -s encrypted 1 ~/text.txt
but want move function embedded in program. part failing strlen(argv[3])
. new function looks this:
int set_encr_attr(char* fpath, int value) { char* userstr = null; /* check value set either 0 or 1 */ if (!( (value == 0) || (value == 1) )) { return -1; } //do stuff (including malloc(userstr) strcpy(userstr, xattr_user_prefix); /* set attribute */ if(setxattr(fpath, userstr, value, 1, 0)){ perror("setxattr error"); exit(exit_failure); } return exit_success; }
as can see, i've replaced fourth argument number 1, since i've checked value being passed in either 0 or 1, must have strlen of 1. i've tried few other things, error:
xattr_new.c: in function ‘set_encr_attr’:
xattr_new.c:52:2: warning: passing argument 3 of ‘setxattr’ makes pointer integer without cast [enabled default]
/usr/include/i386-linux-gnu/sys/xattr.h:40:12: note: expected ‘const void *’ argument of type ‘int’
when play this, can see strlen(argv[3]) == 1, don't understand why can't replace integer 1. typing issue, i've tried casting (which think bad idea), can't make work.
can help? thanks!
1
integer, "1"
string, character array of length 2, containing ascii character '1' (value 49) followed null byte (terminator). function doesn't want integer, wants char pointer. strlen("1")
= 1 because string delimited null byte.
Comments
Post a Comment