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