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