Setting file attributes using native C / C ++ functions

I know how to set file attributes on Windows using the SetFileAttributes function. But I'm wondering if there could be a built-in C / C ++ function, can it do that too?

+6
c ++ c
source share
4 answers

No no. Such standard functions do not define either the C ++ standard or the C standard.

The reason for this is that there are very few common functions in this area in different operating systems. For example, UNIX-like operating systems have an “executable” attribute, while operating systems like Windows use a file extension to determine their health.

+11
source share

Windows has the _ chmod function, which mimics the behavior of the chmod function on Unix.

+4
source share

If "native", you mean in the standard C library, then no. File "attributes" is an OS-specific extension, so it will not be displayed in any standard set of functions. If we want to extend our interface to POSIX, that is, functions such as fchmod, but this only handles UNIX-style file modes that are not as expressive as Windows file attributes.

In general, you can answer any question about the form "Is there a STANDARD function / object for OS-FEATURES", saying: "It is possible if STANDARD exists only for the OS. Otherwise, no."

+4
source share

For C ++ you can try boost :: filesystem .

0
source share

All Articles