Simple Code To Implement C's stat() function On Linux And Unix
Mar 07, 2009, 16:03 (5 Talkback[s])
(Other stories by Mike Tremell)
Re-Imagining Linux Platforms to Meet the Needs of Cloud Service Providers
[ Thanks to Mike
Golvach for this link. ]
"The most interesting part for me was figuring out how
to decipher the "file mode" information. If you check your system's
"stat" manpage, you'll see that there are actually a good deal of
macros already written-in that make printing out plain English file
types and modes much simpler, but I decided to keep it cryptic. I
take my modes like I take my permissions; in octal ;)
"Here's a sample run of the program - just using one file to
make it simple (it should be noted, also, that you can only run
this command against file types that you have permission to read.
If you run this as your regular user on a file owned by root with
700 permissions, you'll get the "File or Directory Not Found!"
error, which is, technically, incorrect. My God, am I a lazy C
programmer. No wonder I get beat up so bad every time I goof around
with it on here ;)"