]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libpthread/nptl/sem_unlink.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libpthread / nptl / sem_unlink.c
1 /* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
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/>.  */
18
19 #include <errno.h>
20 #include <semaphore.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include "semaphoreP.h"
25
26
27 int
28 sem_unlink (
29      const char *name)
30 {
31   char *fname;
32   size_t namelen;
33
34   /* Determine where the shmfs is mounted.  */
35   INTUSE(__pthread_once) (&__namedsem_once, __where_is_shmfs);
36
37   /* If we don't know the mount points there is nothing we can do.  Ever.  */
38   if (mountpoint.dir == NULL)
39     {
40       __set_errno (ENOSYS);
41       return -1;
42     }
43
44   /* Construct the filename.  */
45   while (name[0] == '/')
46     ++name;
47
48   if (name[0] == '\0')
49     {
50       /* The name "/" is not supported.  */
51       __set_errno (ENOENT);
52       return -1;
53     }
54   namelen = strlen (name);
55
56   /* Create the name of the file.  */
57   fname = (char *) alloca (mountpoint.dirlen + namelen + 1);
58   mempcpy (mempcpy (fname, mountpoint.dir, mountpoint.dirlen),
59              name, namelen + 1);
60
61   /* Now try removing it.  */
62   int ret = unlink (fname);
63   if (ret < 0 && errno == EPERM)
64     __set_errno (EACCES);
65   return ret;
66 }