1 /* Copyright (C) 2003-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
29 int (*fp
) (const char *, mode_t
);
34 { creat
, "creat", true },
35 { mkdir
, "mkdir", false },
36 { mkfifo
, "mkfifo", false },
38 #define nfcts (sizeof (fcts) / sizeof (fcts[0]))
42 work (const char *fname
, int mask
)
46 for (i
= 0; i
< nfcts
; ++i
)
49 int fd
= fcts
[i
].fp (fname
, 0777);
52 printf ("cannot %s %s: %m\n", fcts
[i
].name
, fname
);
58 if (stat64 (fname
, &st
) == -1)
60 printf ("cannot stat %s after %s: %m\n", fname
, fcts
[i
].name
);
64 if ((st
.st_mode
& mask
) != 0)
66 printf ("mask not successful after %s: %x still set\n",
67 fcts
[i
].name
, (unsigned int) (st
.st_mode
& mask
));
76 static pthread_barrier_t bar
;
82 pthread_barrier_wait (&bar
);
84 int result
= work (arg
, 022);
86 pthread_barrier_wait (&bar
);
88 pthread_barrier_wait (&bar
);
90 return (work (arg
, 0) | result
) ? (void *) -1l : NULL
;
95 do_test (const char *fname
)
100 result
|= work (fname
, 0);
102 pthread_barrier_init (&bar
, NULL
, 2);
105 if (pthread_create (&th
, NULL
, tf
, (void *) fname
) != 0)
107 puts ("cannot create thread");
112 result
|= work (fname
, 022);
114 pthread_barrier_wait (&bar
);
116 pthread_barrier_wait (&bar
);
120 pthread_barrier_wait (&bar
);
123 if (pthread_join (th
, &res
) != 0)
125 puts ("join failed");
131 return result
|| res
!= NULL
;
134 #define TEST_FUNCTION do_test (argc < 2 ? "/tmp/tst-umask.tmp" : argv[1])
135 #include "../test-skeleton.c"