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