0

Any system call in C to change the permission of a file in HP-UX??

user205688
  • 153
  • 1
  • 1
  • 7

1 Answers1

4

See chmod (documentation) in sys/stat.h. The example below comes from the documentation. HP-UX is POSIX compliant so you can use those functions as well as standard functions from the C library.

The following example sets the file permission bits for a file named /home/cnd/mod1, then calls the stat() function to verify the permissions.

#include <sys/types.h>
#include <sys/stat.h>

int status;
struct stat buffer
...
chmod("home/cnd/mod1", S_IRWXU|S_IRWXG|S_IROTH|S_IWOTH);
status = stat("home/cnd/mod1", &buffer;);
cHao
  • 84,970
  • 20
  • 145
  • 172
Jeff Foster
  • 43,770
  • 11
  • 86
  • 103
  • Hi Jeff, Thanks for your reply. When i run the program as SU the chmod is working. But when i run it as a non-root user, chmod is failing and returning -1. I need it to work in non-root user mode, what should i do???... – user205688 Apr 06 '11 at 11:57
  • Hi jeff, i think setuid will work. but i don't know how to use it in this context. do u ve any idea of how to use it??? – user205688 Apr 06 '11 at 12:25
  • Not without context, answering another question in the comments of this question doesn't seem like a great idea. Why don't you take a look at opening a new question with a better description of your problem? – Jeff Foster Apr 06 '11 at 12:26