Back to index

lightning-sunbird  0.9+nobinonly
pripc.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * File: pripc.c
00040  *
00041  * Description: functions for IPC support
00042  */
00043 
00044 #include "primpl.h"
00045 
00046 #include <string.h>
00047 
00048 /*
00049  * A POSIX IPC name must begin with a '/'.
00050  * A POSIX IPC name on Solaris cannot contain any '/' except
00051  * the required leading '/'.
00052  * A POSIX IPC name on HP-UX and OSF1 must be a valid pathname
00053  * in the file system.
00054  *
00055  * The ftok() function for System V IPC requires a valid pathname
00056  * in the file system.
00057  *
00058  * A Win32 IPC name cannot contain '\'.
00059  */
00060 
00061 static void _pr_ConvertSemName(char *result)
00062 {
00063 #ifdef _PR_HAVE_POSIX_SEMAPHORES
00064 #if defined(SOLARIS)
00065     char *p;
00066 
00067     /* Convert '/' to '_' except for the leading '/' */
00068     for (p = result+1; *p; p++) {
00069         if (*p == '/') {
00070             *p = '_';
00071         }
00072     }
00073     return;
00074 #else
00075     return;
00076 #endif
00077 #elif defined(_PR_HAVE_SYSV_SEMAPHORES)
00078     return;
00079 #elif defined(WIN32)
00080     return;
00081 #endif
00082 }
00083 
00084 static void _pr_ConvertShmName(char *result)
00085 {
00086 #if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY)
00087 #if defined(SOLARIS)
00088     char *p;
00089 
00090     /* Convert '/' to '_' except for the leading '/' */
00091     for (p = result+1; *p; p++) {
00092         if (*p == '/') {
00093             *p = '_';
00094         }
00095     }
00096     return;
00097 #else
00098     return;
00099 #endif
00100 #elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY)
00101     return;
00102 #elif defined(WIN32)
00103     return;
00104 #else
00105     return;
00106 #endif
00107 }
00108 
00109 PRStatus _PR_MakeNativeIPCName(
00110     const char *name,
00111     char *result,
00112     PRIntn size,
00113     _PRIPCType type)
00114 {
00115     if (strlen(name) >= (PRSize)size) {
00116         PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
00117         return PR_FAILURE;
00118     }
00119     strcpy(result, name);
00120     switch (type) {
00121         case _PRIPCSem:
00122             _pr_ConvertSemName(result);
00123             break;
00124         case _PRIPCShm:
00125             _pr_ConvertShmName(result);
00126             break;
00127         default:
00128             PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
00129             return PR_FAILURE;
00130     }
00131     return PR_SUCCESS;
00132 }