1 /* Example for creating a struct dirent object for use with glob.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, if not, see <http://www.gnu.org/licenses/>.
25 mkdirent (const char *name
)
27 size_t dirent_size
= offsetof (struct dirent
, d_name
) + 1;
28 size_t name_length
= strlen (name
);
29 size_t total_size
= dirent_size
+ name_length
;
30 if (total_size
< dirent_size
)
35 struct dirent
*result
= malloc (total_size
);
38 result
->d_type
= DT_UNKNOWN
;
39 result
->d_ino
= 1; /* Do not skip this entry. */
40 memcpy (result
->d_name
, name
, name_length
+ 1);