nsprpub/pr/src/misc/pripc.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * File: pripc.c
michael@0 8 *
michael@0 9 * Description: functions for IPC support
michael@0 10 */
michael@0 11
michael@0 12 #include "primpl.h"
michael@0 13
michael@0 14 #include <string.h>
michael@0 15
michael@0 16 /*
michael@0 17 * A POSIX IPC name must begin with a '/'.
michael@0 18 * A POSIX IPC name on Solaris cannot contain any '/' except
michael@0 19 * the required leading '/'.
michael@0 20 * A POSIX IPC name on HP-UX and OSF1 must be a valid pathname
michael@0 21 * in the file system.
michael@0 22 *
michael@0 23 * The ftok() function for System V IPC requires a valid pathname
michael@0 24 * in the file system.
michael@0 25 *
michael@0 26 * A Win32 IPC name cannot contain '\'.
michael@0 27 */
michael@0 28
michael@0 29 static void _pr_ConvertSemName(char *result)
michael@0 30 {
michael@0 31 #ifdef _PR_HAVE_POSIX_SEMAPHORES
michael@0 32 #if defined(SOLARIS)
michael@0 33 char *p;
michael@0 34
michael@0 35 /* Convert '/' to '_' except for the leading '/' */
michael@0 36 for (p = result+1; *p; p++) {
michael@0 37 if (*p == '/') {
michael@0 38 *p = '_';
michael@0 39 }
michael@0 40 }
michael@0 41 return;
michael@0 42 #else
michael@0 43 return;
michael@0 44 #endif
michael@0 45 #elif defined(_PR_HAVE_SYSV_SEMAPHORES)
michael@0 46 return;
michael@0 47 #elif defined(WIN32)
michael@0 48 return;
michael@0 49 #endif
michael@0 50 }
michael@0 51
michael@0 52 static void _pr_ConvertShmName(char *result)
michael@0 53 {
michael@0 54 #if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY)
michael@0 55 #if defined(SOLARIS)
michael@0 56 char *p;
michael@0 57
michael@0 58 /* Convert '/' to '_' except for the leading '/' */
michael@0 59 for (p = result+1; *p; p++) {
michael@0 60 if (*p == '/') {
michael@0 61 *p = '_';
michael@0 62 }
michael@0 63 }
michael@0 64 return;
michael@0 65 #else
michael@0 66 return;
michael@0 67 #endif
michael@0 68 #elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY)
michael@0 69 return;
michael@0 70 #elif defined(WIN32)
michael@0 71 return;
michael@0 72 #else
michael@0 73 return;
michael@0 74 #endif
michael@0 75 }
michael@0 76
michael@0 77 PRStatus _PR_MakeNativeIPCName(
michael@0 78 const char *name,
michael@0 79 char *result,
michael@0 80 PRIntn size,
michael@0 81 _PRIPCType type)
michael@0 82 {
michael@0 83 if (strlen(name) >= (PRSize)size) {
michael@0 84 PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
michael@0 85 return PR_FAILURE;
michael@0 86 }
michael@0 87 strcpy(result, name);
michael@0 88 switch (type) {
michael@0 89 case _PRIPCSem:
michael@0 90 _pr_ConvertSemName(result);
michael@0 91 break;
michael@0 92 case _PRIPCShm:
michael@0 93 _pr_ConvertShmName(result);
michael@0 94 break;
michael@0 95 default:
michael@0 96 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
michael@0 97 return PR_FAILURE;
michael@0 98 }
michael@0 99 return PR_SUCCESS;
michael@0 100 }

mercurial