Mac/Linux executable extension?

BlitzMax Forums/BlitzMax Programming/Mac/Linux executable extension?

EOF(Posted 2005) [#1]
Hi Linux/Mac users,

How would I filter out unwanted files from a list and only allow executables to show on Linux/Mac using RequestFile()?
' cross-platform executable extension filter
?Win32
Const ext$="Executable:exe"
?Linux
Const ext$=""
?Mac
Const ext$=""
?
f$=RequestFile$("Choose Executable",ext$)



ImaginaryHuman(Posted 2005) [#2]
On mac I think the excecutable has a .app extension.


Perturbatio(Posted 2005) [#3]
is it not the directory that has a .app extensions? (heresay and conjecture).


JazzieB(Posted 2005) [#4]
On Linux, executables don't have an extension. The files simply have a flag in their attributes to say whether they are executable or not. These files tend not to have an extension, but it doesn't mean that files with an extension aren't executable! Unless there's a way of retrieving this attribute information, you're kind of stuck! There doesn't appear to be anything that can do this at the moment - other than third-party workarounds.


Perturbatio(Posted 2005) [#5]
There doesn't appear to be anything that can do this at the moment

Other than FileMode


EOF(Posted 2005) [#6]
Any ideas what 'bits' indicate the file is executable?

*EDIT I have gathered this info:
Unix Permissions


charpos  description        characters
=======  =================  =========================
1        file type          [d] directory   [-] file
2,3,4    owner permissions  [r] read [w] write [x] executable
5,6,7    group permissions  [r] read [w] write [x] executable
8,9,0    access permissions [r] read [w] write [x] executable


-------------------------------

example:

permissions  - rwx r-x --x
charpos      1 234 567 890

filetype is 'file' (as indicated by char 1)
owner has full permissions (see chars 2,3,4)
group can read and launch executable (chars 5,6,7)
everyone else can run the executable (chars 8,9,0)



Perturbatio(Posted 2005) [#7]
this might help:
http://www.freeos.com/articles/3127/


EOF(Posted 2005) [#8]
Thanks Pert. See above.

Ok, should I test for group, access, or owner eXecutable permissions?


JazzieB(Posted 2005) [#9]
FileMode seems a funny name for a function that returns file attributes! I just did a quick scan through the docs to see if I could find anything that would help - it's no wonder I missed this one!

Anyway, nice to know it's there and it will be something that will come in very useful in the future.

As for Jim's question, I suppose it would depend on what it is you want to do, but I'm guessing (no Linux expert) that the group permissions would be the ones to check, as the access permissions are likely to be the same in terms of executing the file. I may be wrong.


FlameDuck(Posted 2005) [#10]
Ok, should I test for group, access, or owner eXecutable permissions?
Depends on who is logged into the system, and which groups he/she/it belongs to. If the file is world execute permissions, then it should be a safe bet.

Group and owner permissions are only good if you know the group or username of the user in question.


EOF(Posted 2005) [#11]
Hey thanks FD.

One last question ...
What values do - , d , r , w , x represent?

A collegue at works thinks:

r = 1
w = 2
x = 4


FlameDuck(Posted 2005) [#12]
Jim,
The "-" means it's forbidden, aka. 0.

As for r,w,x, he's close. It's the other way around. Think of it as a Octal bit pattern - if that helps. :o>


EOF(Posted 2005) [#13]
Flame,
I've looked at the Filemode example and the brl.filesystem code. Max appears to ignore the 1st character (filetype) and only handle the permissions.
A 'mode & 511' value is returned.

I'm rusty at binary stuff but, can you test if this returns True if the *nix file is an executable?
Function IsUnixExe(file$)
  Return FileMode(file$) | %001001001
End Function



xlsior(Posted 2005) [#14]
.