nsprpub/pr/src/misc/pripc.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/src/misc/pripc.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * File: pripc.c
    1.11 + *
    1.12 + * Description: functions for IPC support
    1.13 + */
    1.14 +
    1.15 +#include "primpl.h"
    1.16 +
    1.17 +#include <string.h>
    1.18 +
    1.19 +/*
    1.20 + * A POSIX IPC name must begin with a '/'.
    1.21 + * A POSIX IPC name on Solaris cannot contain any '/' except
    1.22 + * the required leading '/'.
    1.23 + * A POSIX IPC name on HP-UX and OSF1 must be a valid pathname
    1.24 + * in the file system.
    1.25 + *
    1.26 + * The ftok() function for System V IPC requires a valid pathname
    1.27 + * in the file system.
    1.28 + *
    1.29 + * A Win32 IPC name cannot contain '\'.
    1.30 + */
    1.31 +
    1.32 +static void _pr_ConvertSemName(char *result)
    1.33 +{
    1.34 +#ifdef _PR_HAVE_POSIX_SEMAPHORES
    1.35 +#if defined(SOLARIS)
    1.36 +    char *p;
    1.37 +
    1.38 +    /* Convert '/' to '_' except for the leading '/' */
    1.39 +    for (p = result+1; *p; p++) {
    1.40 +        if (*p == '/') {
    1.41 +            *p = '_';
    1.42 +        }
    1.43 +    }
    1.44 +    return;
    1.45 +#else
    1.46 +    return;
    1.47 +#endif
    1.48 +#elif defined(_PR_HAVE_SYSV_SEMAPHORES)
    1.49 +    return;
    1.50 +#elif defined(WIN32)
    1.51 +    return;
    1.52 +#endif
    1.53 +}
    1.54 +
    1.55 +static void _pr_ConvertShmName(char *result)
    1.56 +{
    1.57 +#if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY)
    1.58 +#if defined(SOLARIS)
    1.59 +    char *p;
    1.60 +
    1.61 +    /* Convert '/' to '_' except for the leading '/' */
    1.62 +    for (p = result+1; *p; p++) {
    1.63 +        if (*p == '/') {
    1.64 +            *p = '_';
    1.65 +        }
    1.66 +    }
    1.67 +    return;
    1.68 +#else
    1.69 +    return;
    1.70 +#endif
    1.71 +#elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY)
    1.72 +    return;
    1.73 +#elif defined(WIN32)
    1.74 +    return;
    1.75 +#else
    1.76 +    return;
    1.77 +#endif
    1.78 +}
    1.79 +
    1.80 +PRStatus _PR_MakeNativeIPCName(
    1.81 +    const char *name,
    1.82 +    char *result,
    1.83 +    PRIntn size,
    1.84 +    _PRIPCType type)
    1.85 +{
    1.86 +    if (strlen(name) >= (PRSize)size) {
    1.87 +        PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
    1.88 +        return PR_FAILURE;
    1.89 +    }
    1.90 +    strcpy(result, name);
    1.91 +    switch (type) {
    1.92 +        case _PRIPCSem:
    1.93 +            _pr_ConvertSemName(result);
    1.94 +            break;
    1.95 +        case _PRIPCShm:
    1.96 +            _pr_ConvertShmName(result);
    1.97 +            break;
    1.98 +        default:
    1.99 +            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
   1.100 +            return PR_FAILURE;
   1.101 +    }
   1.102 +    return PR_SUCCESS;
   1.103 +}

mercurial