Header File
io.h
Category
Input/output Routines
Prototype
int _rtl_chmod(const char *path, int func [, int attrib]);
int _wrtl_chmod(const wchar_t *path, int func, ... );
Description
Gets or sets file attributes.
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
On success, _rtl_chmod returns the file attribute word.
On error, it returns a value of -1 and sets the global variable errno to one of the following values:
ENOENT |
Path or filename not found |
EACCES |
Permission denied |
Example
#include <errno.h> #include <stdio.h> #include <dir.h> #include <io.h> int get_file_attrib(char *filename); int main(void) { char filename[128]; int attrib; printf("Enter a filename:"); 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_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(_rtl_chmod(filename, 0)); }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
_rtl_chmod |
|
+ |
|
|
_wrtl_chmod |
|
NT only |
|
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|