1 /* Copyright (C) 2003-2017 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
30 int (*fp
) (const char *, mode_t
);
35 { creat
, "creat", true },
36 { mkdir
, "mkdir", false },
37 { mkfifo
, "mkfifo", false },
39 #define nfcts (sizeof (fcts) / sizeof (fcts[0]))
43 work (const char *fname
, int mask
)
47 for (i
= 0; i
< nfcts
; ++i
)
50 int fd
= fcts
[i
].fp (fname
, 0777);
53 printf ("cannot %s %s: %m\n", fcts
[i
].name
, fname
);
59 if (stat64 (fname
, &st
) == -1)
61 printf ("cannot stat %s after %s: %m\n", fname
, fcts
[i
].name
);
65 if ((st
.st_mode
& mask
) != 0)
67 printf ("mask not successful after %s: %x still set\n",
68 fcts
[i
].name
, (unsigned int) (st
.st_mode
& mask
));
77 static pthread_barrier_t bar
;
83 pthread_barrier_wait (&bar
);
85 int result
= work (arg
, 022);
87 pthread_barrier_wait (&bar
);
89 pthread_barrier_wait (&bar
);
91 return (work (arg
, 0) | result
) ? (void *) -1l : NULL
;
96 do_test (const char *fname
)
101 result
|= work (fname
, 0);
103 pthread_barrier_init (&bar
, NULL
, 2);
106 if (pthread_create (&th
, NULL
, tf
, (void *) fname
) != 0)
108 puts ("cannot create thread");
113 result
|= work (fname
, 022);
115 pthread_barrier_wait (&bar
);
117 pthread_barrier_wait (&bar
);
121 pthread_barrier_wait (&bar
);
124 if (pthread_join (th
, &res
) != 0)
126 puts ("join failed");
132 return result
|| res
!= NULL
;
135 #define TEST_FUNCTION do_test (argc < 2 ? "/tmp/tst-umask.tmp" : argv[1])
136 #include "../test-skeleton.c"