michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * File: pripc.c michael@0: * michael@0: * Description: functions for IPC support michael@0: */ michael@0: michael@0: #include "primpl.h" michael@0: michael@0: #include michael@0: michael@0: /* michael@0: * A POSIX IPC name must begin with a '/'. michael@0: * A POSIX IPC name on Solaris cannot contain any '/' except michael@0: * the required leading '/'. michael@0: * A POSIX IPC name on HP-UX and OSF1 must be a valid pathname michael@0: * in the file system. michael@0: * michael@0: * The ftok() function for System V IPC requires a valid pathname michael@0: * in the file system. michael@0: * michael@0: * A Win32 IPC name cannot contain '\'. michael@0: */ michael@0: michael@0: static void _pr_ConvertSemName(char *result) michael@0: { michael@0: #ifdef _PR_HAVE_POSIX_SEMAPHORES michael@0: #if defined(SOLARIS) michael@0: char *p; michael@0: michael@0: /* Convert '/' to '_' except for the leading '/' */ michael@0: for (p = result+1; *p; p++) { michael@0: if (*p == '/') { michael@0: *p = '_'; michael@0: } michael@0: } michael@0: return; michael@0: #else michael@0: return; michael@0: #endif michael@0: #elif defined(_PR_HAVE_SYSV_SEMAPHORES) michael@0: return; michael@0: #elif defined(WIN32) michael@0: return; michael@0: #endif michael@0: } michael@0: michael@0: static void _pr_ConvertShmName(char *result) michael@0: { michael@0: #if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY) michael@0: #if defined(SOLARIS) michael@0: char *p; michael@0: michael@0: /* Convert '/' to '_' except for the leading '/' */ michael@0: for (p = result+1; *p; p++) { michael@0: if (*p == '/') { michael@0: *p = '_'; michael@0: } michael@0: } michael@0: return; michael@0: #else michael@0: return; michael@0: #endif michael@0: #elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY) michael@0: return; michael@0: #elif defined(WIN32) michael@0: return; michael@0: #else michael@0: return; michael@0: #endif michael@0: } michael@0: michael@0: PRStatus _PR_MakeNativeIPCName( michael@0: const char *name, michael@0: char *result, michael@0: PRIntn size, michael@0: _PRIPCType type) michael@0: { michael@0: if (strlen(name) >= (PRSize)size) { michael@0: PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); michael@0: return PR_FAILURE; michael@0: } michael@0: strcpy(result, name); michael@0: switch (type) { michael@0: case _PRIPCSem: michael@0: _pr_ConvertSemName(result); michael@0: break; michael@0: case _PRIPCShm: michael@0: _pr_ConvertShmName(result); michael@0: break; michael@0: default: michael@0: PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); michael@0: return PR_FAILURE; michael@0: } michael@0: return PR_SUCCESS; michael@0: }