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