How element types are assigned

In various contexts, one or more file types may be determined for an existing file system object, or for a name to be used for a new object. When you create a new element and do not specify an element type, the file type for the element is determined by default.

The file-typing routines use predefined and user-defined magic files, as described in the cc.magic reference page. A magic file can use many different techniques to determine a file type, including file name pattern-matching, stat(2) data, and standard magic numbers on Linux and the UNIX system.

For example, the magic files in Sample magic file on Linux the UNIX system and Sample magic file on the Windows system specify several file types for each kind of file listed in Files used in a typical project .

Sample magic file on Linux the UNIX system

(1)
c_src src_file text_file file: -name "*.c" ;
(2)
hdr_file text_file file: -name "*.h" ;
(3)
frm_doc binary_delta_file doc file: -magic 0, "<MakerFile" ;
(4)
manpage src_file text_file file: -name "*.[1-9]" ;
(5)
archive derived_file file: -magic 32, "archive" ;
(6)
sunexec derived_file file: -magic 40, "SunBin" ;

Sample magic file on the Windows® system

(1)
c_src src_file text_file file: -name "*.c";
(2)
hdr_file text_file file: -name "*.h" ;
(3)
frm_doc binary_delta_file doc file: -magic 0, "<MakerFile" ;
(4)
library derived_file file: -name "*.lib";
(5)
program compressed_file: -name "*.exe" ;