tags:

views:

407

answers:

4

Hi, I know how to set file attributes on Windows by using SetFileAttributes function. But I am wondering if there is a native C/C++ function can can do this too?

Thanks in advance.

+8  A: 

No there is not. Neither Standard C++ nor Standard C specify such functions.

The reason for this is that there is very little commonalirty of function in this area across different operating systems. For example, UNIX-like operatimng systems have an "executable" attribute, while Windows-like operating systems use the file extension to determine executability.

anon
+3  A: 

On windows there is a _chmod function which mimics the behavior of the chmod function on Unix.

JesperE
+4  A: 

If by "native", you mean in the C standard library, then no. File "attributes" are an OS specific extension, so won't appear in any standard function set. If we're willing to extend our remit to POSIX, then there are functions like fchmod, but this only handles UNIX style file modes, which are not as expressive as Windows file attributes.

In general, you can answer any question of the form "Is there a STANDARD function/object to do OS-SPECIFIC thing" by saying "Probably, if STANDARD exists only for OS. Otherwise, no".

Adam Wright
A: 

See the source code of SetFileAttributes...

I sincerely hope this was tongue-in-cheek.
Rob K