| 1 |
/************************************************************************* |
| 2 |
* |
| 3 |
* TESTUTIL-CLOSEDIR.C, Superseded closedir function for test purpose |
| 4 |
* Copyright (C) 2019-2026 Xavier Delaruelle |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation, either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
************************************************************************/ |
| 20 |
|
| 21 |
#include <dirent.h> |
| 22 |
|
| 23 |
#if defined (__APPLE__) |
| 24 |
|
| 25 |
int my_closedir(DIR *dirp) |
| 26 |
{ |
| 27 |
return -1; |
| 28 |
} |
| 29 |
|
| 30 |
/* Code injection with DYLD interposing */ |
| 31 |
__attribute__((used)) |
| 32 |
static struct { |
| 33 |
const void *replacement; |
| 34 |
const void *replacee; |
| 35 |
} interposers[] |
| 36 |
__attribute__((section("__DATA,__interpose"))) = { |
| 37 |
{ (const void *)my_closedir, (const void *)closedir } |
| 38 |
}; |
| 39 |
|
| 40 |
#else |
| 41 |
|
| 42 |
int closedir(DIR *dirp) |
| 43 |
{ |
| 44 |
return -1; |
| 45 |
} |
| 46 |
|
| 47 |
#endif |
| 48 |
|
| 49 |
/* vim:set tabstop=3 shiftwidth=3 expandtab autoindent: */ |