_dos_getfileattr, _dos_setfileattr
raw OCR
Changes file access mode.
Defined in header <dos.h>
Syntax
#include <dos.h>
int _dos_getfileattr(const char *path, unsigned *attribp);
int _dos_setfileattr(const char path, unsigned attrib);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ |
Remarks
_dos_getfileattr fetches the DOS file attributes for the file path. The attributes are stored at the location pointed to by attribp.
_dos_setfileattr sets the DOS file attributes for the file path to the value attrib.
The DOS file attributes can be a OR combination of the following symbolic constants (defined in dos.h):
| _A_RDONLY | Read-only attribute |
| _A_HIDDEN | Hidden file |
| _A_SYSTEM | System file |
| _A_VOLID | Volume label |
| _A_SUBDIR | Directory |
| _A_ARCH | Archive |
| _A_NORMAL | Normal file (no attribute bits set) |
Return value
Upon successful completion, _dos_getfileattr and _dos_setfileattr return 0. Otherwise, these functions return the DOS error code, and the global variable errno is set to the following: ENOENT Path or file name not found
See also
chmodStat
Example
#include <stdio.h>
#include <dos.h>
int main (void)
char filename [128];
unsigned attrib;
printf( "Enter a file name:");
scanf("%s", filename);
if (_dos_getfileattr(filename,&attrib) != 0) {
perror ("Unable to obtain file attributes");
return 1;
}
if (attrib & _A_RDONLY) {
printf("%s currently read-only, making it read-write. \n", filename);
attrib &= ~_A_RDONLY;
}
else (
printf("%s currently read-write, making it read-only. \n", filename);
attrib 1= _A_RDONLY;
}
if (_dos_setfileattr (filename,attrib) != 0)
perror ("Unable to set file attributes");
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `dos_getfileattr, _clos_setfileattr` read as `_dos_getfileattr, _dos_setfileattr`
Stable link: /3.1/dos.h/_dos_getfileattr/
· short form /3.1/_dos_getfileattr/