File Types

  / Usr / include / bits / stat.h 

  / * Encoding of the file mode .* / 

  / * Take place Acer, 000 001111 000000000000 * / 

  # Define __S_IFMT 0170000 / * These bits determine file type .* / 

  / * 7 kinds of file types-* / 

  / * File types .* / 

  # Define __S_IFDIR 0040000 / * Directory * / 

  # Define __S_IFCHR 0020000 / * Character device * / 

  # Define __S_IFBLK 0060000 / * Block device * / 

  # Define __S_IFREG 0100000 / * Regular file * / 

  # Define __S_IFIFO 0010000 / * FIFO * / 

  # Define __S_IFLNK 0120000 / * Symbolic link * / 

  # Define __S_IFSOCK 0140000 / * Socket * / 

  16 bits. Designed to save inode corresponding to the mode of the document. 

  Fifo 000 000001 000000000000 1 

  Character device 000 000010 000000000000 2 

  Directory 000 000100 000000000000 4 

  Block device 000 000110 000000000000 6 

  Regular file 000 001000 000000000000 8 

  Symbolic link 000 001010 000000000000 10 

  Socket 000 001100 000000000000 12 

  ————————————————– ————————————– 

  / Usr / include / sys / stat.h 

  # Include <bits/stat.h> / * Hung-that is, from the document * / 

  / * 7 kinds of file types-test * / 

  / * Test macros for file types * / 

  # Define __S_ISTYPE (mode, the mask) (((mode) & __S_IFMT) == (mask)) 

  # Define S_ISDIR (mode) __S_ISTYPE ((mode), __S_IFDIR) 

  # Define S_ISCHR (mode) __S_ISTYPE ((mode), __S_IFCHR) 

  # Define S_ISBLK (mode) __S_ISTYPE ((mode), __S_IFBLK) 

  # Define S_ISREG (mode) __S_ISTYPE ((mode), __S_IFREG) 

  # Ifdef __S_IFIFO 

  # Define S_ISFIFO (mode) __S_ISTYPE ((mode), __S_IFIFO) 

  # Endif 

  # Ifdef __S_IFLNK 

  # Define S_ISLNK (mode) __S_ISTYPE ((mode), __S_IFLNK) 

  # Endif 

  # If defined __USE_BSD & &! Defined __S_IFLNK 

  # Define S_ISLNK (mode) 0 

  # Endif 

  # If (defined __USE_BSD | | defined __USE_UNIX98) / 

  & & Defined __S_IFSOCK 

  # Define S_ISSOCK (mode) __S_ISTYPE ((mode), __S_IFSOCK) 

  # Endif 

  All seven tests-coupled with the corresponding file types are attributable to the macro-__S_ISTYPE (mode, the mask) 

  The macro mode of operation is to take place and Acer __ S_IFMT conduct operations to remove mode section 12 to section 15, with the corresponding type of file-mask to compare results is a bool value. 

  ————————————————– ————————————– 

  Use test macros to test a file's type, for example: 

  File "dir" is a directory. First we get its information via any of the stat functions. 

  S_ISDIR (buf.st_mode) / * struct stat buf * / 

  __S_ISTYPE ((Buf.st_mode), __S_IFDIR) / * the corresponding file types-* / 

  ((Buf.st_mode) & 000 001111 000000000000) == (000 000100 000000000000) 

  / * Take place Acer * / 

  And computing, shielding other place, mainly extraction buf.st_mode section 12 to section 15, and the corresponding value of the type of document comparison. 

  Mode_t is unsigned 32 bits 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply