home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / posix / sys / stat / is_exec.txh < prev    next >
Encoding:
Text File  |  1995-11-12  |  1.8 KB  |  42 lines

  1. @node _is_executable, io
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <sys/stat.h>
  6.  
  7. int _is_executable(const char *path, int fhandle, const char *extension);
  8. @end example
  9.  
  10. @subheading Description
  11.  
  12. This function determines if a file is executable under DOS/DJGPP
  13. environment.  The file may be given either by its @var{path} or its file
  14. handle @var{fhandle}.  If @var{extension} is non-NULL and non-empty, it is
  15. used first to look up in a list of known extensions which determine
  16. whether the file is executable.  (If the _STAT_EXEC_EXT bit of the
  17. @ref{_djstat_flags} global variable is not set, this step is skipped.)
  18. If @var{extension} is unavailable or not enough to determine the result,
  19. the first 2 bytes of the file are checked to contain one of the known
  20. @cite{magic numbers} identifying the file as executable.  If the file's 2
  21. first bytes need to be read but the read fails, 0 is returned and errno is
  22. set.  (The file is only searched for magic number if the _STAT_EXEC_MAGIC
  23. bit of the @xref{_djstat_flags} variable is set.)
  24.  
  25. Note that if _STAT_EXEC_MAGIC is set, but _STAT_EXEC_EXT is not, some
  26. files which shouldn't be flagged as executables (e.g., COFF *.o object
  27. files) will have their execute bit set, because they have the magic number
  28. signature at their beginning.  Therefore, only use the above combination
  29. if you want to debug the list of extensions provided in is_exec.c file.
  30.  
  31. If the file passed by its handle was open as write-only, and the extension
  32. alone isn't enough to determine whether the file is executable, then this
  33. function returns 0, because it cannot look at the @cite{magic number}.
  34.  
  35. This function is used internally by @code{f?stat()}; you are not supposed
  36. to call it directly.
  37.  
  38. @subheading Return Value
  39.  
  40. 1 for executable file, 0 otherwise (including in case of errors in
  41. accessing the file).
  42.