| 1 |
#if defined(__WIN32__) && !defined(__CYGWIN__) |
| 2 |
/* Mostly skip on Windows, cf. main file why. */ |
| 3 |
|
| 4 |
int expect_open_to_fail () { return 1; } |
| 5 |
|
| 6 |
void my_verify_not_exists (const char *dir) { } |
| 7 |
void my_mkdir (const char *dir) { } |
| 8 |
void my_rmdir (const char *dir) { } |
| 9 |
|
| 10 |
#else |
| 11 |
|
| 12 |
#include <sys/stat.h> /* For mkdir + permission bits. */ |
| 13 |
#include <unistd.h> /* For rmdir. */ |
| 14 |
#include <errno.h> /* For errno. */ |
| 15 |
#include <stdio.h> /* For perror. */ |
| 16 |
#include <stdlib.h> /* For abort. */ |
| 17 |
|
| 18 |
|
| 19 |
int expect_open_to_fail () { return 0; } |
| 20 |
|
| 21 |
void |
| 22 |
my_verify_not_exists (const char *dir) |
| 23 |
{ |
| 24 |
struct stat path_stat; |
| 25 |
int err = stat (dir, &path_stat); |
| 26 |
if (err && errno == ENOENT) |
| 27 |
return; /* OK */ |
| 28 |
if (err) |
| 29 |
perror ("my_verify_not_exists"); |
| 30 |
else |
| 31 |
printf ("my_verify_not_exists: pathname %s still exists\n", dir); |
| 32 |
abort (); |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
my_mkdir (const char *dir) |
| 37 |
{ |
| 38 |
int err; |
| 39 |
struct stat path_stat; |
| 40 |
|
| 41 |
/* Check whether 'dir' exists and is a directory. */ |
| 42 |
err = stat (dir, &path_stat); |
| 43 |
if (err && errno != ENOENT) |
| 44 |
{ |
| 45 |
perror ("my_mkdir: failed to call stat for directory"); |
| 46 |
abort (); |
| 47 |
} |
| 48 |
if (err == 0 && !S_ISDIR (path_stat.st_mode)) |
| 49 |
{ |
| 50 |
printf ("my_mkdir: pathname %s is not a directory\n", dir); |
| 51 |
abort (); |
| 52 |
} |
| 53 |
|
| 54 |
err = mkdir (dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
| 55 |
if (err != 0) |
| 56 |
{ |
| 57 |
perror ("my_mkdir: failed to create directory"); |
| 58 |
abort (); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
my_rmdir (const char *dir) |
| 64 |
{ |
| 65 |
rmdir (dir); |
| 66 |
} |
| 67 |
|
| 68 |
#endif /* !defined(__WIN32__) || defined(__CYGWIN__) */ |