my_dir.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. #ifndef MY_DIR_H
  13. #define MY_DIR_H
  14. #include "my_global.h"
  15. #include <sys/stat.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* Defines for my_dir and my_stat */
  20. #define MY_S_IFMT S_IFMT /* type of file */
  21. #define MY_S_IFDIR S_IFDIR /* directory */
  22. #define MY_S_IFCHR S_IFCHR /* character special */
  23. #define MY_S_IFBLK S_IFBLK /* block special */
  24. #define MY_S_IFREG S_IFREG /* regular */
  25. #define MY_S_IFIFO S_IFIFO /* fifo */
  26. #define MY_S_ISUID S_ISUID /* set user id on execution */
  27. #define MY_S_ISGID S_ISGID /* set group id on execution */
  28. #define MY_S_ISVTX S_ISVTX /* save swapped text even after use */
  29. #define MY_S_IREAD S_IREAD /* read permission, owner */
  30. #define MY_S_IWRITE S_IWRITE /* write permission, owner */
  31. #define MY_S_IEXEC S_IEXEC /* execute/search permission, owner */
  32. #define MY_S_ISDIR(m) (((m) & MY_S_IFMT) == MY_S_IFDIR)
  33. #define MY_S_ISCHR(m) (((m) & MY_S_IFMT) == MY_S_IFCHR)
  34. #define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK)
  35. #define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG)
  36. #define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO)
  37. /* Ensure these dosn't clash with anything in my_sys.h */
  38. #define MY_WANT_SORT 8192 /* my_lib; sort files */
  39. #define MY_WANT_STAT 16384 /* my_lib; stat files */
  40. #define MY_DONT_SORT 0
  41. /* typedefs for my_dir & my_stat */
  42. #ifdef USE_MY_STAT_STRUCT
  43. typedef struct my_stat
  44. {
  45. dev_t st_dev; /* major & minor device numbers */
  46. ino_t st_ino; /* inode number */
  47. ushort st_mode; /* file permissons (& suid sgid .. bits) */
  48. short st_nlink; /* number of links to file */
  49. ushort st_uid; /* user id */
  50. ushort st_gid; /* group id */
  51. dev_t st_rdev; /* more major & minor device numbers (???) */
  52. off_t st_size; /* size of file */
  53. time_t st_atime; /* time for last read */
  54. time_t st_mtime; /* time for last contens modify */
  55. time_t st_ctime; /* time for last inode or contents modify */
  56. } MY_STAT;
  57. #else
  58. #if(_MSC_VER)
  59. #define MY_STAT struct _stati64 /* 64 bit file size */
  60. #else
  61. #define MY_STAT struct stat /* Orginal struct have what we need */
  62. #endif
  63. #endif /* USE_MY_STAT_STRUCT */
  64. /* Struct describing one file returned from my_dir */
  65. typedef struct fileinfo
  66. {
  67. char *name;
  68. MY_STAT *mystat;
  69. } FILEINFO;
  70. typedef struct st_my_dir /* Struct returned from my_dir */
  71. {
  72. /*
  73. These members are just copies of parts of DYNAMIC_ARRAY structure,
  74. which is allocated right after the end of MY_DIR structure (MEM_ROOT
  75. for storing names is also resides there). We've left them here because
  76. we don't want to change code that uses my_dir.
  77. */
  78. struct fileinfo *dir_entry;
  79. uint number_of_files;
  80. } MY_DIR;
  81. extern MY_DIR *my_dir(const char *path,myf MyFlags);
  82. extern void my_dirend(MY_DIR *buffer);
  83. extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags);
  84. extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* MY_DIR_H */