| 1 |
/*=========================================================================== |
| 2 |
Copyright (C) 1995-2009 European Southern Observatory (ESO) |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License as |
| 6 |
published by the Free Software Foundation; either version 2 of |
| 7 |
the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public |
| 15 |
License along with this program; if not, write to the Free |
| 16 |
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge, |
| 17 |
MA 02139, USA. |
| 18 |
|
| 19 |
Correspondence concerning ESO-MIDAS should be addressed as follows: |
| 20 |
Internet e-mail: [email protected] |
| 21 |
Postal address: European Southern Observatory |
| 22 |
Data Management Division |
| 23 |
Karl-Schwarzschild-Strasse 2 |
| 24 |
D 85748 Garching bei Muenchen |
| 25 |
GERMANY |
| 26 |
===========================================================================*/ |
| 27 |
|
| 28 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 29 |
.TYPE Module |
| 30 |
.NAME oshenv.c |
| 31 |
.LANGUAGE C |
| 32 |
.AUTHOR IPG-ESO Garching |
| 33 |
.CATEGORY Host operating system interfaces. Host services. |
| 34 |
.ENVIRONMENT UNIX (BSD / SYSV) |
| 35 |
.COMMENTS |
| 36 |
Provide miscellaneous host services. |
| 37 |
There are routines translating logicals (environment), |
| 38 |
getting current process and login info. |
| 39 |
.VERSION 0.0 25-Aug-1986 Definition. J. D. Ponz |
| 40 |
.VERSION 1.0 28-Oct-1986 Programmation. B. Pirenne |
| 41 |
.VERSION 1.5 14-Apr-1987 bsd-sysv compatible. B. Pirenne |
| 42 |
.VERSION 1.6 15-Jul-1987 oshcpu returns a real number; date through a |
| 43 |
structure. B. Pirenne |
| 44 |
.VERSION 1.7 10-Dec-1987 Cosmetic changes I. Suisalu |
| 45 |
.VERSION 2.0 08-Feb-1989 putenv() does not exist in pure BSD. CGS |
| 46 |
.VERSION 2.1 06-Mar-1990 Added oshpid oshuser oshprn (login infos) |
| 47 |
.VERSION 2.2 23-May-1990 Corrected bug in BSD version FO |
| 48 |
.VERSION 2.3 01-Aug-1990 Added oshostname routine (FO) |
| 49 |
.VERSION 2.4 910911 oshset removed because of putenv. CG |
| 50 |
.VERSION 2.5 920120 lint: table argument in oshenv removed. CG. |
| 51 |
.VERSION 2.6 930209 ohsostname routine removed. CG. |
| 52 |
|
| 53 |
090324 last modif |
| 54 |
------------------------------------------------------------*/ |
| 55 |
|
| 56 |
#include <stdlib.h> |
| 57 |
#include <sys/types.h> |
| 58 |
#include <unistd.h> |
| 59 |
#include <errno.h> |
| 60 |
#include <osparms.h> |
| 61 |
#include <proto_os.h> /* ANSI-C prototyping */ |
| 62 |
|
| 63 |
#define DEBUG 0 |
| 64 |
|
| 65 |
|
| 66 |
char *getenv(); |
| 67 |
|
| 68 |
#define FINISH goto FIN |
| 69 |
|
| 70 |
/*========================================================================== |
| 71 |
* Logical Name Translations |
| 72 |
*==========================================================================*/ |
| 73 |
|
| 74 |
/*==========================================================================*/ |
| 75 |
/* ARGSUSED */ |
| 76 |
char *oshenv(logname,table) |
| 77 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 78 |
.PURPOSE |
| 79 |
Translate logical names into physical names., according to a table. |
| 80 |
.METHOD |
| 81 |
Searches the system variable list for the logname. |
| 82 |
.RETURNS Address of equivalence name / NULL when logname not found |
| 83 |
.REMARKS table is used only in VMS environment (default is LNM$FILE_DEV). |
| 84 |
Translation is not case-dependent on VMS. Use recursive translation. |
| 85 |
------------------------------------------------------------*/ |
| 86 |
char *logname; /* IN : logical name */ |
| 87 |
char *table; /* IN : name of the table to look for (VMS only) */ |
| 88 |
{ |
| 89 |
register char *p; |
| 90 |
|
| 91 |
oserror = 0; |
| 92 |
|
| 93 |
/* 1. Skip the eventual trailing $ */ |
| 94 |
|
| 95 |
p = logname; |
| 96 |
if (*p == '$') p++; |
| 97 |
|
| 98 |
/* 2. Do the logical translation */ |
| 99 |
|
| 100 |
p = getenv(p); |
| 101 |
if (!p) oserror = errno; |
| 102 |
|
| 103 |
return(p); |
| 104 |
} |
| 105 |
|
| 106 |
int oshpid() |
| 107 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 108 |
.PURPOSE Get process number of current process. |
| 109 |
.RETURNS Process id. |
| 110 |
.REMARK Only for VMS. |
| 111 |
-------------------------------------------------------------------- */ |
| 112 |
{ |
| 113 |
return(getpid()); |
| 114 |
} |