~ubuntu-branches/ubuntu/quantal/uclibc/quantal

« back to all changes in this revision

Viewing changes to librt/shm.c

  • Committer: Bazaar Package Importer
  • Author(s): Hector Oron
  • Date: 2011-06-11 03:06:20 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110611030620-ywjfvyuqvrpsm282
Tags: 0.9.32-1
* New upstream release
* Add myself as maintainer
* Bump standards version 
* Add Vcs-Git, Vcs-Browser and Homepage fields
* Add watch file 

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#include <features.h>
7
7
#include <sys/types.h>
8
8
#include <sys/stat.h>
 
9
#include <sys/mman.h>
9
10
#include <fcntl.h>
10
11
#include <unistd.h>
11
12
#include <stdlib.h>
24
25
 * Returns a malloc'ed buffer containing the OS specific path
25
26
 * to the shm filename or NULL upon failure.
26
27
 */
27
 
static __attribute_noinline__ char* get_shm_name(const char*name) __nonnull((1));
28
 
static char* get_shm_name(const char*name)
 
28
static __attribute_noinline__ char* get_shm_name(const char *name) __nonnull((1));
 
29
static char* get_shm_name(const char *name)
29
30
{
30
31
        char *path;
31
32
        int i;
56
57
 
57
58
int shm_open(const char *name, int oflag, mode_t mode)
58
59
{
59
 
        int fd, old_errno;
 
60
        int fd;
60
61
        char *shm_name = get_shm_name(name);
61
62
 
62
63
        /* Stripped multiple '/' from start; may have set errno properly */
70
71
#else
71
72
        fd = open(shm_name, oflag, mode);
72
73
        if (fd >= 0) {
73
 
                int fdflags = fcntl(fd, F_GETFD, 0);
74
 
                if (fdflags >= 0)
75
 
                        fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
76
 
                if (fdflags < 0) {
77
 
                        close(fd);
78
 
                        fd = -1;
79
 
                }
 
74
                fcntl(fd, F_SETFD, FD_CLOEXEC);
 
75
                /* thus far, {G,S}ETFD only has this single flag,
 
76
                 * and setting it never fails.
 
77
                 *int fdflags = fcntl(fd, F_GETFD);
 
78
                 *if (fdflags >= 0)
 
79
                 *      fdflags = fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC);
 
80
                 *if (fdflags < 0) {
 
81
                 *      close(fd);
 
82
                 *      fd = -1;
 
83
                 *}
 
84
                 */
80
85
        }
81
86
#endif
82
 
        old_errno = errno;
83
 
        free(shm_name);
84
 
        errno = old_errno;
 
87
        free(shm_name); /* doesn't affect errno */
85
88
        return fd;
86
89
}
87
90
 
88
91
int shm_unlink(const char *name)
89
92
{
90
93
        char *shm_name = get_shm_name(name);
91
 
        int ret, old_errno;
 
94
        int ret;
92
95
 
93
96
        /* Stripped multiple '/' from start; may have set errno properly */
94
97
        if (shm_name == NULL)
95
98
                return -1;
96
99
        ret = unlink(shm_name);
97
 
        old_errno = errno;
98
 
        free(shm_name);
99
 
        errno = old_errno;
 
100
        free(shm_name); /* doesn't affect errno */
100
101
        return ret;
101
102
}