chmod() Change File Permission Setting
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
int chmod(pathname, pmode);
char *pathname; Name of file
int pmode; Permission setting
chmod() changes the permission setting of the file specified by
'pathname'. The permission setting controls whether the file has
read-only or read and write access. To change the permission setting,
set the 'pmode' value to:
S_IWRITE for write permission
S_IREAD for read permission
S_IREAD | S_IWRITE for read and write permission
Returns: Zero if the permission setting is successfully changed,
or -1 if there is an error, in which case errno is set to
ENOENT (file not found).
Notes: Under MS-DOS all files are readable; you cannot have a
write-only file. If write permission is not specified,
the file is made read-only.
-------------------------------- Example ---------------------------------
The following statements change the file to read-only status:
#include <sys\stat.h>
#include <io.h>
int result;
main()
{
result = chmod("invoice.bak", S_IREAD);
if (result == -1)
perror("can't change permission mode");
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster