Using shell commands versus C equivalents

Gregory Shapiro gshapiro at freebsd.org
Wed Jun 13 15:58:45 UTC 2007


>  Sorry -- actually I meant that (along similar lines), there was a program 
>  with the following lines:
> 
>  vsystem("/bin/chmod +x %s", filename);
> 
>  and I replaced it with:
> 
>  chmod(filename, (mode_t) ( S_IXUSR | S_IXGRP | S_IXOTH ));

Those two lines have different effects.  The first adds the execute bit
to the file.  The second replaces the current permissions with only the
execute bit.  To have the same affect, you need to stat() the file,
and then use bitwise-or to add the S_IXUSR | S_IXGRP | S_IXOTH bits to
st_mode and use that new st_mode with chmod().


More information about the freebsd-hackers mailing list