Debian Codegraph @

libsrc/os/vms/oshproc.c

raw
1 /* @(#)oshproc.c 19.1 (ES0-DMD) 02/25/03 13:56:12 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 .TYPE Module
31 .NAME oshproc
32 .LANGUAGE C
33 .AUTHOR IPG-ESO Garching
34 .CATEGORY Host operating system interfaces. Host services.
35 .ENVIRONMENT VAX/VMS Version
36 .COMMENTS
37 Provide process host services.
38 These routines return process information.
39 The routines return always
40 a non-negative integer number on successful return.
41 Otherwise, a value of -1 is set to indicate an error
42 condition and the variable ``oserror'' contains the
43 symbolic error code.
44 .VERSION 0.0 25-Aug-1986 Definition. J. D. Ponz
45 .VERSION 1.0 13-Jan-1989 Programmation. B. Pirenne (ST--ECF)
46 Fr. Ochsenbein (ESO - IPG)
47 .VERSION 1.1 31-Aug-1990 Added oshost (Host Name) F.O.
48 .VERSION 1.2 17-Oct-1990: Removed GNU-nonunderstandable code...
49 .VERSION 1.3 09-Feb-1993: Removed GNU-nonunderstandable code.(oshostname)CG.
50 ------------------------------------------------------------*/
51
52 #define DEBUG 0
53
54 #include <osdefos.h>
55 #include <macrogen.h>
56 #ifdef EOF
57 #undef EOF
58 #endif
59
60 MID_EXTERN int oserror;
61 MID_EXTERN int vmserror;
62
63 #include <errno.h> /* System */
64 #include <ssdef.h> /* System */
65 #include <jpidef.h> /* System */
66 #include <syidef.h> /* System */
67
68 typedef struct {
69 unsigned short len;
70 unsigned short item_code;
71 char *buffer;
72 long *return_length;
73 } ITMLST;
74
75
76 int oshpid()
77 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
78 .PURPOSE Get process number of current process.
79 .RETURNS Process id.
80 .REMARK Only for VMS.
81 -------------------------------------------------------------------- */
82 {
83 static int PID;
84
85 static struct {
86 ITMLST itm_1;
87 long itm_end;
88 } items = {
89 { sizeof(int), JPI$_PID, (char *)&PID, (long *)0}, /* PID NUMBER */
90 0 /* end of items list*/
91 };
92
93 vmserror = sys$getjpi(0,0,0,&items,0,0,0);
94 if (vmserror & 1) ;
95 else {
96 PID = -1;
97 oserror = EVMSERR;
98 }
99 return(PID);
100 }
101
102 char *oshprn()
103 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104 .PURPOSE Get process name of current process.
105 .RETURNS Process name string.
106 .REMARK Only for VMS.
107 -------------------------------------------------------------------- */
108 {
109 static char PRN[16];
110 static long PRN_len;
111
112 static struct {
113 ITMLST itm_2;
114 long itm_end;
115 } items = {
116 { sizeof(PRN)-1, JPI$_PRCNAM, PRN, &PRN_len}, /* Proc name */
117 0 /* end of items list*/
118 };
119
120 vmserror = sys$getjpi(0,0,0,&items,0,0,0);
121 if (vmserror & 1)
122 PRN[PRN_len] = EOS;
123 else {
124 PRN[0] = EOS;
125 oserror = EVMSERR;
126 }
127 return(PRN);
128 }
129
130
131 char *oshuser()
132 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
133 .PURPOSE Get name of user who logged in.
134 .RETURNS User's name string
135 .REMARK
136 -------------------------------------------------------------------- */
137 {
138 static char username[24];
139 static long username_len;
140
141 static struct {
142 ITMLST itm_2;
143 long itm_end;
144 } items = {
145 { sizeof(username)-1, JPI$_USERNAME, username, &username_len},
146 0 /* end of items list*/
147 };
148
149 vmserror = sys$getjpi(0,0,0,&items,0,0,0);
150 if (vmserror & 1) { /* Remove useless blanks... */
151 while (username_len > 0)
152 if (username[--username_len] != ' ') break;
153 username[++username_len] = EOS;
154 }
155 else {
156 username[0] = EOS;
157 oserror = EVMSERR;
158 }
159 return(username);
160 }