_chmod
raw OCR
Gets or sets DOS file attributes.
Defined in header <dos.h>
Syntax
#include <dos.h>
#include <io.h>
int _chmod(const char *path, intfunc [,int attrib]);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
_chmod can either fetch or set the DOS file attributes. If funds 0, the function returns the current DOS attributes for the file, lifunc is 1, the attribute is set to attrih.
attrib can be one of the following symbolic constants (defined in dos.h):
| FA_RDONLY | Read-only attribute |
| FA_HIDDEN | Hidden file |
| FA__SYSTEM | System file |
| FA_LABEL | Volume label |
| FA_DIREC | Directory |
| FA ARCH | Archive |
Return value
Upon successful completion, _chmod returns the file attribute word; otherwise, it returns a value of -1.
In the event of an error, the global variable errno is set to one of the following:
ENOENT Path or file name not found EACCES Permission denied
See also
Example
#include <errno.h>
#include <stdio.h>
#include <dos.h>
#include <io.h>
int get_file_attrib(char *filename);
int main (void)
{
char filename [128];
int attrib;
printf ("Enter a file name:");
scanf("%s", filename);
attrib = get_file_attrib(filename) ;
if (attrib == -1)
switch (errno) {
case ENOENT : printf("Path or file not found.\n");
break;
case EACCES : printf("Permission denied. \n");
break;
default: printf("Error number: %d" , errno);
break;
, }
else
if (attrib & FA_RDONLY)
printf ("%s is read-only.\n", filename);
if (attrib & FA_HIDDEN)
printf ("%s is hidden.\n", filename);
if (attrib & FA_SYSTEM)
printf ("%s is a system file.\n", filename);
if (attrib & FA_LABEL)
printf("ls is a volume label.\n", filename);
if (attrib & FA_DIREC)
printf ("%s is a directory.\n", filename);
if (attrib & FA_ARCH)
printf ("%s is an archive file.\n", filename);
return 0;
}
/* returns the attributes of a DOS file */
int get_file_attrib(char *filename) {
return(_chinod(filename, 0));
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `chmod` read as `_chmod`
Stable link: /3.1/dos.h/_chmod/
· short form /3.1/_chmod/