Moved files to libCom/misc/os

This commit is contained in:
Janet B. Anderson
1999-10-12 19:32:17 +00:00
parent e5288818a0
commit 1fe31a37ac
21 changed files with 0 additions and 2141 deletions
-3
View File
@@ -1,3 +0,0 @@
The source files here are OS dependent
-104
View File
@@ -1,104 +0,0 @@
/* bsdSockResource.c */
/* share/src/libCom/os/generic/$Id$ */
/*
* Author: Jeff Hill
* Date: 04-05-94
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .00 mm-dd-yy iii Comment
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
#include "epicsAssert.h"
/*
* NOOP
*/
int bsdSockAttach()
{
return 1;
}
/*
* NOOP
*/
void bsdSockRelease()
{
}
/*
* ipAddrToHostName
*/
epicsShareFunc unsigned epicsShareAPI ipAddrToHostName
(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
{
struct hostent *ent;
if (bufSize<1) {
return 0;
}
ent = gethostbyaddr((char *) pAddr, sizeof (*pAddr), AF_INET);
if (ent) {
strncpy (pBuf, ent->h_name, bufSize);
pBuf[bufSize-1] = '\0';
return strlen (pBuf);
}
return 0;
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}
-27
View File
@@ -1,27 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "osiSock.h"
#define epicsExportSharedSymbols
#include "epicsAssert.h"
#include "osiSleep.h"
/*
* should work correctly on VMS, but there
* is probably a more efficent native call ...
*/
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
int status;
struct timeval tval;
assert (uSec<1000000);
tval.tv_sec = sec;
tval.tv_usec = uSec;
status = select (0, NULL, NULL, NULL, &tval);
if (status<0) {
fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n",
SOCKERRSTR(SOCKERRNO));
}
}
-11
View File
@@ -1,11 +0,0 @@
#define epicsExportSharedSymbols
#include "sigPipeIgnore.h"
/*
* NOOP
*/
epicsShareFunc void epicsShareAPI installSigPipeIgnore (void)
{
}
-4
View File
@@ -1,4 +0,0 @@
I took this from the GNU grep sources that should
also be part of the NT tools of this EPICS release.
-kuk-
-18
View File
@@ -1,18 +0,0 @@
On WIN32, libCom is build as a DLL Com.dll.
Because the sources are not adjusted to export all
functions 'automatically' with _declspec(dllexport),
a def-file 'Com.def' is used to list all
functions that should be included in the DLL.
It may well be that I missed to include some
functions in Com.def,
so if some function is missing in the DLL,
add a line to Com.def!
To rebuild the dll:
rm O.WIN32/Com.*
gnumake
-kuk-
-4
View File
@@ -1,4 +0,0 @@
I took this from the GNU grep sources that should
also be part of the NT tools of this EPICS release.
-kuk-
-137
View File
@@ -1,137 +0,0 @@
#!/bin/sh
#
# base/tools $Id$
# Author: Andrew Johnson (RGO)
# Date: 14-Mar-95
#
# Experimental Physics and Industrial Control System (EPICS)
#
# $Log$
# Revision 1.1.2.1 1996/11/25 19:28:53 jhill
# installed
#
# Revision 1.1 1996/11/02 02:12:53 jhill
# installed
#
# Revision 1.4 1996/06/25 21:48:33 jba
# Makefile includes now from base/src/config, removed all soft links
#
# Revision 1.3 1996/05/10 16:10:18 mrk
# remove hard path to base/include
#
# Revision 1.2 1995/09/29 22:16:27 jhill
# ms windows changes
#
# Revision 1.1 1995/08/17 20:22:09 jba
# Moved bldEnvData,blderrSymTbl, makeStatTbl to libCom dir
#
# Revision 1.3 1995/08/14 19:27:24 jhill
# extern => epicsShareExtern
#
# Revision 1.2 1995/05/04 09:49:24 anj
# Added CONFIG_SITE_ENV, changed envData to .c file
#
# Revision 1.1 1995/04/24 16:02:29 anj
# Moved environment parameter defaults to config/CONFIG_ENV
#
#
# tool to build envData.c from envDefs.h and config/CONFIG*ENV
# Usage bldEnvData
HERE=`/bin/pwd`
cd $1
CONFIG_DIR=`/bin/pwd`
cd ${HERE}
SRC=../envDefs.h
ENV_DATA=${CONFIG_DIR}/CONFIG_ENV
SITE_DATA=${CONFIG_DIR}/CONFIG_SITE_ENV
OBJ=envData.c
TOOL=`basename $0`
# Start by creating a list of the ENV_PARAM declarations
PARAMS=`sed -n -e 's/;//' \
-e 's/^[ ]*epicsShareExtern[ ][ ]*ENV_PARAM[ ][ ]*//p' \
${SRC}`
echo 'For some unknown reason, the bldEnvData script hangs on WIN32'
echo 'sometimes...'
echo 'The reason might be some too-small buffer in gnumake or knts,'
echo 'because from inside the O.WIN32 directory everything is fine.'
echo 'If this happens, simply cd to O.WIN32, type the line above'
echo '(the one that started bldEnvData) by hand and restart gnumake'
# Create a new header file
rm -rf ${OBJ}
cat >${OBJ} <<!EOF
/* ${HERE}/${OBJ}
*
* created by ${TOOL}
*
* from:
* ${SRC}
* ${ENV_DATA}
* ${SITE_DATA}
*
* `date`
*
*/
#define epicsExportSharedSymbols
#include "envDefs.h"
#include "shareLib.h"
!EOF
# Make sure no corresponding shell environment variables
unset ${PARAMS}
# Read the default values from the config file into shell variables
. ${ENV_DATA}
. ${SITE_DATA}
# Scan through the parameters to create the definition
for ENV in ${PARAMS}
do
# The set | grep ... construct does not work on WIN32
# so we give no error for missing DEFAULTS
#
# Get the default, complain if not present
# if [ `set | grep -c ${ENV}=` = 0 ];
# then
# echo No default value for ${ENV}
# DEFAULT=""
# else
VAR='$'${ENV}
DEFAULT=`eval echo ${VAR}`
# fi
# Add this definition to the header file
#echo ${ENV} = ${DEFAULT}
echo ENV_PARAM ${ENV}'={"'${ENV}'","'${DEFAULT}'"};' >>${OBJ}
done
# Now create an array pointing to all parameters
cat >>${OBJ} <<!EOF
ENV_PARAM* env_param_list[EPICS_ENV_VARIABLE_COUNT+1] = {
!EOF
# Contents are the addresses of each parameter
for ENV in ${PARAMS}
do
echo ' &'${ENV}, >>${OBJ}
done
# Finally finish list with 0
cat >>${OBJ} <<!EOF
0
};
!EOF
exit 0
-220
View File
@@ -1,220 +0,0 @@
/*
* $Id$
*
* WIN32 specific initialisation for bsd sockets,
* based on Chris Timossi's base/src/ca/windows_depend.c,
* and also further additions by Kay Kasemir when this was in
* dllmain.cc
*
* 7-1-97 -joh-
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Lawrence Berkley National Laboratory
*
* Modification Log:
* -----------------
*/
#ifndef _WIN32
#error This source is specific to WIN32
#endif
/*
* ANSI C
*/
#include <stdio.h>
/*
* WIN32 specific
*/
#include <winsock2.h>
#include <ws2tcpip.h>
#include <process.h>
#define epicsExportSharedSymbols
#include "epicsVersion.h"
#include "bsdSocketResource.h"
static unsigned nAttached = 0;
static WSADATA WsaData; /* version of winsock */
epicsShareFunc unsigned epicsShareAPI wsaMajorVersion()
{
return (unsigned) LOBYTE( WsaData.wVersion );
}
/*
* bsdSockAttach()
*/
epicsShareFunc int epicsShareAPI bsdSockAttach()
{
int status;
if (nAttached) {
nAttached++;
return TRUE;
}
#if _DEBUG
/* for gui applications, setup console for error messages */
if (AllocConsole())
{
char title[256];
DWORD titleLength = GetConsoleTitle(title, sizeof(title));
if (titleLength) {
titleLength = strlen (title);
strncat (title, " " BASE_VERSION_STRING, sizeof(title));
}
else {
strncpy(title, BASE_VERSION_STRING, sizeof(title));
}
title[sizeof(title)-1]= '\0';
SetConsoleTitle(title);
freopen( "CONOUT$", "a", stderr );
}
#endif
/*
* attach to win sock
*/
status = WSAStartup(MAKEWORD(/*major*/2,/*minor*/2), &WsaData);
if (status != 0) {
fprintf(stderr,
"Unable to attach to windows sockets version 2. error=%d\n", status);
fprintf(stderr,
"A Windows Sockets II update for windows 95 is available at\n");
fprintf(stderr,
"http://www.microsoft.com/windows95/info/ws2.htm");
return FALSE;
}
# if _DEBUG
fprintf(stderr, "EPICS attached to winsock version %s\n", WsaData.szDescription);
# endif
nAttached = 1u;
return TRUE;
}
/*
* bsdSockRelease()
*/
epicsShareFunc void epicsShareAPI bsdSockRelease()
{
if (nAttached) {
if (--nAttached==0u) {
WSACleanup();
# if _DEBUG
fprintf(stderr, "EPICS released winsock version %s\n", WsaData.szDescription);
# endif
memset (&WsaData, '\0', sizeof(WsaData));
}
}
}
/*
* ipAddrToHostName
*/
epicsShareFunc unsigned epicsShareAPI ipAddrToHostName
(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
{
struct hostent *ent;
if (bufSize<1) {
return 0;
}
ent = gethostbyaddr((char *) pAddr, sizeof (*pAddr), AF_INET);
if (ent) {
strncpy (pBuf, ent->h_name, bufSize);
pBuf[bufSize-1] = '\0';
return strlen (pBuf);
}
return 0;
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}
/*
* convertSocketErrorToString()
*/
epicsShareFunc const char * epicsShareAPI convertSocketErrorToString (int errnoIn)
{
static char errString[128];
static int init = 0;
/*
* unfortunately, this does not work ...
* and there is no obvious replacement ...
*/
#if 0
DWORD W32status;
W32status = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errnoIn,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
errString,
sizeof(errString)/sizeof(errString[0]),
NULL
);
if (W32status==0) {
sprintf (errString, "WIN32 Socket Library Error %d", errnoIn);
}
return errString;
#else
sprintf (errString, "WIN32 Socket Library Error %d", errnoIn);
return errString;
#endif
}
-73
View File
@@ -1,73 +0,0 @@
/*
* dllmain.c
*
* WIN32 specific initialisation for the Com library,
* based on Chris Timossi's base/src/ca/windows_depend.c,
* especially initializing:
* ositime
*
* 8-2-96 -kuk-
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Lawrence Berkley National Laboratory
*
* Modification Log:
* -----------------
*/
#include <winsock2.h>
#include <stdio.h>
#include "epicsVersion.h"
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
#ifndef _WIN32
#error This source is specific to WIN32
#endif
#if !defined(EPICS_DLL_NO)
BOOL WINAPI DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
if (!bsdSockAttach())
return FALSE;
# ifdef _DEBUG
fprintf(stderr, "Process attached to Com.dll version %s\n", EPICS_VERSION_STRING);
# endif
break;
case DLL_PROCESS_DETACH:
bsdSockRelease();
# ifdef _DEBUG
fprintf(stderr, "Process detached from Com.dll version %s\n", EPICS_VERSION_STRING);
# endif
break;
}
return TRUE;
}
#endif
-736
View File
@@ -1,736 +0,0 @@
/* Getopt for GNU.
NOTE: getopt is now part of the C library, so if you don't know what
"Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
before changing it!
Copyright (C) 1987, 88, 89, 90, 91, 92, 1993
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* NOTE!!! AIX requires this to be the first thing in the file.
Do not put ANYTHING before it! */
#if !defined (__GNUC__) && defined (_AIX)
#pragma alloca
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef _MSC_VER
#include <malloc.h>
#else
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not __GNUC__ */
#if defined (HAVE_ALLOCA_H) || (defined(sparc) && (defined(sun) || (!defined(USG) && !defined(SVR4) && !defined(__svr4__))))
#include <alloca.h>
#else
#ifndef _AIX
char *alloca ();
#endif
#endif /* alloca.h */
#endif
#endif /* not __GNUC__ */
#if !__STDC__ && !defined(const) && IN_GCC
#define const
#endif
/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. */
#ifndef _NO_PROTO
#define _NO_PROTO
#endif
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#undef alloca
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#else /* Not GNU C library. */
#define __alloca alloca
#endif /* GNU C library. */
/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
long-named option. Because this is not POSIX.2 compliant, it is
being phased out. */
/* #define GETOPT_COMPAT */
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
to intersperse the options with the other arguments.
As `getopt' works, it permutes the elements of ARGV so that,
when it is done, all the options precede everything else. Thus
all application programs are extended to handle flexible argument order.
Setting the environment variable POSIXLY_CORRECT disables permutation.
Then the behavior is completely standard.
GNU application programs can use a third alternative mode in which
they can distinguish the relative order of options and other arguments. */
#define epicsExportSharedSymbols
#include "getopt.h"
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
epicsShareDef char *optarg = 0;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
/* XXX 1003.2 says this must be 1 before any call. */
epicsShareDef int optind = 0;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
static char *nextchar;
/* Callers store zero here to inhibit the error message
for unrecognized options. */
epicsShareDef int opterr = 1;
/* Set to an option character which was unrecognized.
This must be initialized on some systems to avoid linking in the
system's own getopt implementation. */
epicsShareDef int optopt = '?';
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters.
PERMUTE is the default. We permute the contents of ARGV as we scan,
so that eventually all the non-options are at the end. This allows options
to be given in any order, even with programs that were not written to
expect this.
RETURN_IN_ORDER is an option available to programs that were written
to expect options and other ARGV-elements in any order and that care about
the ordering of the two. We describe each non-option ARGV-element
as if it were the argument of an option with character code 1.
Using `-' as the first character of the list of option characters
selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
#ifdef __GNU_LIBRARY__
/* We want to avoid inclusion of string.h with non-GNU libraries
because there are many ways it can cause trouble.
On some systems, it contains special magic macros that don't work
in GCC. */
#include <string.h>
#define my_index strchr
#define my_bcopy(src, dst, n) memcpy ((dst), (src), (n))
#else
/* Avoid depending on library functions or files
whose names are inconsistent. */
char *getenv ();
static char *
my_index (str, chr)
const char *str;
int chr;
{
while (*str)
{
if (*str == chr)
return (char *) str;
str++;
}
return 0;
}
static void
my_bcopy (from, to, size)
const char *from;
char *to;
int size;
{
int i;
for (i = 0; i < size; i++)
to[i] = from[i];
}
#endif /* GNU C library. */
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first of them;
`last_nonopt' is the index after the last of them. */
static int first_nonopt;
static int last_nonopt;
/* Exchange two adjacent subsequences of ARGV.
One subsequence is elements [first_nonopt,last_nonopt)
which contains all the non-options that have been skipped so far.
The other is elements [last_nonopt,optind), which contains all
the options processed since those non-options were skipped.
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
static void
exchange (argv)
char **argv;
{
int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
char **temp = (char **) __alloca (nonopts_size);
/* Interchange the two blocks of data in ARGV. */
my_bcopy ((char *) &argv[first_nonopt], (char *) temp, nonopts_size);
my_bcopy ((char *) &argv[last_nonopt], (char *) &argv[first_nonopt],
(optind - last_nonopt) * sizeof (char *));
my_bcopy ((char *) temp,
(char *) &argv[first_nonopt + optind - last_nonopt],
nonopts_size);
/* Update records for the slots the non-options now occupy. */
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
}
/* Scan elements of ARGV (whose length is ARGC) for option characters
given in OPTSTRING.
If an element of ARGV starts with '-', and is not exactly "-" or "--",
then it is an option element. The characters of this element
(aside from the initial '-') are option characters. If `getopt'
is called repeatedly, it returns successively each of the option characters
from each of the option elements.
If `getopt' finds another option character, it returns that character,
updating `optind' and `nextchar' so that the next call to `getopt' can
resume the scan with the following option character or ARGV-element.
If there are no more option characters, `getopt' returns `EOF'.
Then `optind' is the index in ARGV of the first ARGV-element
that is not an option. (The ARGV-elements have been permuted
so that those that are not options now come last.)
OPTSTRING is a string containing the legitimate option characters.
If an option character is seen that is not listed in OPTSTRING,
return '?' after printing an error message. If you set `opterr' to
zero, the error message is suppressed but we still return '?'.
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
so the following text in the same ARGV-element, or the text of the following
ARGV-element, is returned in `optarg'. Two colons mean an option that
wants an optional arg; if there is text in the current ARGV-element,
it is returned in `optarg', otherwise `optarg' is set to zero.
If OPTSTRING starts with `-' or `+', it requests different methods of
handling the non-option ARGV-elements.
See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
Long-named options begin with `--' instead of `-'.
Their names may be abbreviated as long as the abbreviation is unique
or is an exact match for some defined option. If they have an
argument, it follows the option name in the same ARGV-element, separated
from the option name by a `=', or else the in next ARGV-element.
When `getopt' finds a long-named option, it returns 0 if that option's
`flag' field is nonzero, the value of the option's `val' field
if the `flag' field is zero.
The elements of ARGV aren't really const, because we permute them.
But we pretend they're const in the prototype to be compatible
with other systems.
LONGOPTS is a vector of `struct option' terminated by an
element containing a name which is zero.
LONGIND returns the index in LONGOPT of the long-named option found.
It is only valid when a long-named option has been found by the most
recent call.
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
long-named options. */
int
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
int argc;
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
{
int option_index;
optarg = 0;
/* Initialize the internal data when the first call is made.
Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
if (optind == 0)
{
first_nonopt = last_nonopt = optind = 1;
nextchar = NULL;
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
{
ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+')
{
ordering = REQUIRE_ORDER;
++optstring;
}
else if (getenv ("POSIXLY_CORRECT") != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
}
if (nextchar == NULL || *nextchar == '\0')
{
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (last_nonopt != optind)
first_nonopt = optind;
/* Now skip any additional non-options
and extend the range of non-options previously skipped. */
while (optind < argc
&& (argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
&& (longopts == NULL
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
)
optind++;
last_nonopt = optind;
}
/* Special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp (argv[optind], "--"))
{
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
&& (longopts == NULL
|| argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif /* GETOPT_COMPAT */
)
{
if (ordering == REQUIRE_ORDER)
return EOF;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Start decoding its characters. */
nextchar = (argv[optind] + 1
+ (longopts != NULL && argv[optind][1] == '-'));
}
if (longopts != NULL
&& ((argv[optind][0] == '-'
&& (argv[optind][1] == '-' || long_only))
#ifdef GETOPT_COMPAT
|| argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
))
{
const struct option *p;
char *s = nextchar;
int exact = 0;
int ambig = 0;
const struct option *pfound = NULL;
int indfound;
while (*s && *s != '=')
s++;
/* Test all options for either exact match or abbreviated matches. */
for (p = longopts, option_index = 0; p->name;
p++, option_index++)
if (!strncmp (p->name, nextchar, s - nextchar))
{
if (s - nextchar == strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n",
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
optind++;
if (*s)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = s + 1;
else
{
if (opterr)
{
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
else
/* +option or -option */
fprintf (stderr,
"%s: option `%c%s' doesn't allow an argument\n",
argv[0], argv[optind - 1][0], pfound->name);
}
nextchar += strlen (nextchar);
return '?';
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)
optarg = argv[optind++];
else
{
if (opterr)
fprintf (stderr, "%s: option `%s' requires an argument\n",
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
#ifdef GETOPT_COMPAT
|| argv[optind][0] == '+'
#endif /* GETOPT_COMPAT */
|| my_index (optstring, *nextchar) == NULL)
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n",
argv[0], nextchar);
else
/* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
return '?';
}
}
/* Look at and handle the next option-character. */
{
char c = *nextchar++;
char *temp = my_index (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':')
{
if (opterr)
{
#if 0
if (c < 040 || c >= 0177)
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
argv[0], c);
else
fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
#endif
}
optopt = c;
return '?';
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
optarg = nextchar;
optind++;
}
else
optarg = 0;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (opterr)
{
#if 0
fprintf (stderr, "%s: option `-%c' requires an argument\n",
argv[0], c);
#else
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
#endif
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
int epicsShareAPI
getopt (argc, argv, optstring)
int argc;
char *const *argv;
const char *optstring;
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
(int *) 0,
0);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
the above definition of `getopt'. */
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
if (c == EOF)
break;
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */
-134
View File
@@ -1,134 +0,0 @@
/* Declarations for getopt.
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include "shareLib.h"
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
epicsShareExtern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns EOF, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
epicsShareExtern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
epicsShareExtern int opterr;
/* Set to an option character which was unrecognized. */
epicsShareExtern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if __STDC__
#if defined(__GNU_LIBRARY__)
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
epicsShareFunc extern int epicsShareAPI
getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
epicsShareFunc extern int epicsShareAPI getopt ();
#endif /* not __GNU_LIBRARY__ */
epicsShareFunc extern int epicsShareAPI
getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
epicsShareFunc extern int
epicsShareAPI getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
epicsShareFunc extern int epicsShareAPI getopt ();
epicsShareFunc extern int epicsShareAPI getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* not __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* _GETOPT_H */
-70
View File
@@ -1,70 +0,0 @@
#!/bin/sh
#
# makeStatTbl
# share/src/misc $Id$
# makeStatTbl - Create Error Symbol Table
#
# modification history
# --------------------
# 17-JUL-90 mrk Modified vxWorks makeStatTbl
#
# SYNOPSIS
# createErrSymTbl hdir [...] >errSymTbl.c
#
# DESCRIPTION
# This tool creates a symbol table (ERRSYMTAB) structure which contains the
# names and values of all the status codes defined in the .h files in the
# specified directory(s). The status codes must be prefixed with "S_"
# in order to be included in this table.
# A "err.h" file must exist in each hdir which defines the module
# numbers, eg. "M_". The table is created on standard output.
#
# This tool's primary use is for creating an error status table used
# by errPrint, and errSymFind.
#
# FILES
# errMdef.h module number file for each h directory
#
# SEE ALSO: errnoLib(1), symLib(1)
#*/
tmp=/tmp/mstt$$
# knts cannot handle this -kuk-
# trap "rm -f $tmp ; exit" 0 1 2 3 15
cat $* | egrep '^#define[ ]*S_' >$tmp
echo '/* status code symbol table */'
echo
echo '/* CREATED BY makeStatTbl'
echo ' * FROM '`pwd`
echo ' * ON '`date`
echo ' */'
echo
echo '#include "errMdef.h"'
echo '#include "errSymTbl.h"'
echo
cat $tmp
echo
echo 'LOCAL ERRSYMBOL symbols[] ='
echo ' {'
# -kuk- had to change "\2" into \"\2\" for knts
sed -e 's/^.*define[ ]*\(S_[a-zA-Z0-9_]*\).*\/\*\(.*\)\*\/.*/ {\"\2\", (long) \1},/' \
$tmp
echo ' };'
echo
echo 'LOCAL ERRSYMTAB symTbl ='
echo ' {'
echo ' NELEMENTS (symbols), /* current number of symbols in table */'
echo ' symbols, /* ptr to symbol array */'
echo ' };'
echo
echo 'ERRSYMTAB_ID errSymTbl = &symTbl;'
exit 0
-322
View File
@@ -1,322 +0,0 @@
//
// $Id$
//
// Author: Jeff Hill
//
//
//
// ANSI C
//
#include <math.h>
#include <time.h>
#include <limits.h>
#ifndef assert // allow other versions of assert
#include <assert.h>
#endif
//
// WIN32
//
#include <winsock2.h>
/*
* for _ftime()
*/
#include <sys/types.h>
#include <sys/timeb.h>
//
// EPICS
//
#define epicsExportSharedSymbols
#include <osiTime.h>
//
// performance counter last value, ticks per sec,
// and its offset from the EPICS epoch.
//
static LONGLONG perf_last, perf_freq, perf_offset;
//
// divide the offset into seconds and
// fractions of a second so that overflow is less
// likely (we dont know the magnitude of perf_freq
// until run time)
//
static LONGLONG perf_sec_offset=-1, perf_frac_offset;
static const SYSTEMTIME epicsEpochST = {
1990, // year
1, // month
1, // day of the week (Monday)
1, // day of the month
0, // hour
0, // min
0, // sec
0 // milli sec
};
static LONGLONG epicsEpoch;
static LONGLONG FILE_TIME_TICKS_PER_SEC = 10000000L;
/*
* synchronize()
*/
void osiTime::synchronize()
{
static int init = 0;
LONGLONG new_sec_offset, new_frac_offset;
LARGE_INTEGER parm;
LONGLONG secondsSinceBoot;
FILETIME currentTimeFT;
LONGLONG currentTime;
BOOL win32Stat;
//
// one time initialization of constants
//
if (!init) {
FILETIME epicsEpochFT;
//
// initialize elapsed time counters
//
// All CPUs running win32 currently have HR
// counters (Intel and Mips processors do)
//
assert (QueryPerformanceFrequency (&parm)!=0);
perf_freq = parm.QuadPart;
//
// convert the EPICS epoch to file time
//
win32Stat = SystemTimeToFileTime (&epicsEpochST, &epicsEpochFT);
assert (win32Stat!=0);
parm.LowPart = epicsEpochFT.dwLowDateTime;
parm.HighPart = epicsEpochFT.dwHighDateTime;
epicsEpoch = parm.QuadPart;
init = 1;
}
//
// its important that the following two time queries
// are close together (immediately adjacent to each
// other) in the code
//
GetSystemTimeAsFileTime (&currentTimeFT);
// this one is second because QueryPerformanceFrequency()
// has forced its code to load
assert (QueryPerformanceCounter (&parm)!=0);
perf_last = parm.QuadPart;
parm.LowPart = currentTimeFT.dwLowDateTime;
parm.HighPart = currentTimeFT.dwHighDateTime;
currentTime = parm.QuadPart;
//
// check for strange date, and clamp to the
// epics epoch if so
//
if (currentTime>epicsEpoch) {
//
// compute the offset from the EPICS epoch
//
LONGLONG diff = currentTime - epicsEpoch;
//
// compute the seconds offset and the
// fractional offset part in the FILETIME timebase
//
new_sec_offset = diff / FILE_TIME_TICKS_PER_SEC;
new_frac_offset = diff % FILE_TIME_TICKS_PER_SEC;
//
// compute the fractional second offset in the performance
// counter time base
//
new_frac_offset = (new_frac_offset*perf_freq) / FILE_TIME_TICKS_PER_SEC;
}
else {
new_sec_offset = 0;
new_frac_offset = 0;
}
//
// subtract out the perormance counter ticks since the
// begining of windows
//
secondsSinceBoot = perf_last / perf_freq;
if (new_sec_offset>=secondsSinceBoot) {
new_sec_offset -= secondsSinceBoot;
LONGLONG fracSinceBoot = perf_last % perf_freq;
if (new_frac_offset>=fracSinceBoot) {
new_frac_offset -= fracSinceBoot;
}
else if (new_sec_offset>0) {
//
// borrow
//
new_sec_offset--;
new_frac_offset += perf_freq - fracSinceBoot;
}
else {
new_frac_offset = 0;
}
}
else {
new_sec_offset = 0;
new_frac_offset = 0;
}
#if 0
//
// calculate the change
//
{
double change;
change = (double) (perf_sec_offset-new_sec_offset)*perf_freq +
(perf_frac_offset-new_frac_offset);
change /= perf_freq;
printf ("The performance counter drifted by %f sec\n", change);
}
#endif
//
// update the current value
//
perf_sec_offset = new_sec_offset;
perf_frac_offset = new_frac_offset;
}
//
// osiTime::osdGetCurrent ()
//
osiTime osiTime::osdGetCurrent ()
{
LONGLONG time_cur, time_sec, time_remainder;
LARGE_INTEGER parm;
unsigned long sec, nsec;
/*
* lazy init
*/
if (perf_sec_offset<0) {
osiTime::synchronize();
}
/*
* dont need to check status since it was checked once
* during initialization to see if the CPU has HR
* counters (Intel and Mips processors do)
*/
QueryPerformanceCounter (&parm);
time_cur = parm.QuadPart;
if (perf_last > time_cur) { /* must have been a timer roll-over */
/*
* must have been a timer roll-over
* It takes 9.223372036855e+18/perf_freq sec
* to roll over this counter (perf_freq is 1193182
* sec on my system). This is currently about 245118 years.
*
* attempt to add number of seconds in a 64 bit integer
* in case the timer resolution improves
*/
perf_sec_offset += MAXLONGLONG / perf_freq;
perf_frac_offset += MAXLONGLONG % perf_freq;
if (perf_frac_offset>=perf_freq) {
perf_sec_offset++;
perf_frac_offset -= perf_freq;
}
}
time_sec = time_cur / perf_freq;
time_remainder = time_cur % perf_freq;
/*
* add time (sec) since the EPICS epoch
*/
time_sec += perf_sec_offset;
time_remainder += perf_frac_offset;
if (time_remainder>=perf_freq) {
time_sec += 1;
time_remainder -= perf_freq;
}
perf_last = time_cur;
sec = (unsigned long) (time_sec%ULONG_MAX);
nsec = (unsigned long) ((time_remainder*nSecPerSec)/perf_freq);
return osiTime (sec, nsec);
}
//
// gmtime_r ()
//
// from posix real time
//
struct tm *gmtime_r (const time_t *pAnsiTime, struct tm *pTM)
{
HANDLE thisThread = GetCurrentThread ();
struct tm *p;
int oldPriority;
BOOL win32Success;
oldPriority = GetThreadPriority (thisThread);
if (oldPriority==THREAD_PRIORITY_ERROR_RETURN) {
return NULL;
}
win32Success = SetThreadPriority (thisThread, THREAD_PRIORITY_TIME_CRITICAL);
if (!win32Success) {
return NULL;
}
p = gmtime (pAnsiTime);
if (p!=NULL) {
*pTM = *p;
}
win32Success = SetThreadPriority (thisThread, oldPriority);
assert (win32Success);
return p;
}
//
// localtime_r ()
//
// from posix real time
//
struct tm *localtime_r (const time_t *pAnsiTime, struct tm *pTM)
{
HANDLE thisThread = GetCurrentThread ();
struct tm *p;
int oldPriority;
BOOL win32Success;
oldPriority = GetThreadPriority (thisThread);
if (oldPriority==THREAD_PRIORITY_ERROR_RETURN) {
return NULL;
}
win32Success = SetThreadPriority (thisThread, THREAD_PRIORITY_TIME_CRITICAL);
if (!win32Success) {
return NULL;
}
p = localtime (pAnsiTime);
if (p!=NULL) {
*pTM = *p;
}
win32Success = SetThreadPriority (thisThread, oldPriority);
assert (win32Success);
return p;
}
-19
View File
@@ -1,19 +0,0 @@
#include <windows.h>
#define epicsExportSharedSymbols
#include "osiSleep.h"
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
unsigned milliSec;
milliSec = uSec / 1000;
milliSec += sec * 1000;
if (milliSec==0u) {
milliSec = 1;
}
Sleep (milliSec); // time-out interval in milliseconds
}
-11
View File
@@ -1,11 +0,0 @@
#define epicsExportSharedSymbols
#include "sigPipeIgnore.h"
/*
* NOOP
*/
epicsShareFunc void epicsShareAPI installSigPipeIgnore (void)
{
}
-5
View File
@@ -1,5 +0,0 @@
The source files here are OS dependent. The implementation
is generic enough that it can be used on several OS and therefore is the
default implementation.
-104
View File
@@ -1,104 +0,0 @@
/* bsdSockResource.c */
/* share/src/libCom/os/generic/$Id$ */
/*
* Author: Jeff Hill
* Date: 04-05-94
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .00 mm-dd-yy iii Comment
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define epicsExportSharedSymbols
#include "bsdSocketResource.h"
#include "epicsAssert.h"
/*
* NOOP
*/
int bsdSockAttach()
{
return 1;
}
/*
* NOOP
*/
void bsdSockRelease()
{
}
/*
* ipAddrToHostName
*/
epicsShareFunc unsigned epicsShareAPI ipAddrToHostName
(const struct in_addr *pAddr, char *pBuf, unsigned bufSize)
{
struct hostent *ent;
if (bufSize<1) {
return 0;
}
ent = gethostbyaddr((char *) pAddr, sizeof (*pAddr), AF_INET);
if (ent) {
strncpy (pBuf, ent->h_name, bufSize);
pBuf[bufSize-1] = '\0';
return strlen (pBuf);
}
return 0;
}
/*
* hostToIPAddr ()
*/
epicsShareFunc int epicsShareAPI hostToIPAddr
(const char *pHostName, struct in_addr *pIPA)
{
struct hostent *phe;
phe = gethostbyname (pHostName);
if (phe && phe->h_addr_list[0]) {
if (phe->h_addrtype==AF_INET && phe->h_length<=sizeof(struct in_addr)) {
struct in_addr *pInAddrIn = (struct in_addr *) phe->h_addr_list[0];
*pIPA = *pInAddrIn;
/*
* success
*/
return 0;
}
}
/*
* return indicating an error
*/
return -1;
}
-33
View File
@@ -1,33 +0,0 @@
//
// should move the time stuff into a different header
//
#include "osiSock.h"
#include "epicsAssert.h"
#define epicsExportSharedSymbols
#include "osiTime.h"
//
// osiTime::synchronize()
//
void osiTime::synchronize()
{
}
//
// osiTime::osdGetCurrent ()
//
osiTime osiTime::osdGetCurrent ()
{
int status;
struct timeval tv;
status = gettimeofday (&tv, NULL);
assert (status==0);
return osiTime (osiTime::time_tToInternalSec (tv.tv_sec), tv.tv_usec * nSecPerUSec);
}
-26
View File
@@ -1,26 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "osiSock.h"
#define epicsExportSharedSymbols
#include "epicsAssert.h"
#include "osiSleep.h"
/*
* should work correctly on UNIX and VMS
*/
epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec)
{
int status;
struct timeval tval;
assert (uSec<1000000);
tval.tv_sec = sec;
tval.tv_usec = uSec;
status = select (0, NULL, NULL, NULL, &tval);
if (status<0) {
fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n",
SOCKERRSTR(SOCKERRNO));
}
}
-80
View File
@@ -1,80 +0,0 @@
/*
* install NOOP SIGPIPE handler
*
* escape into C to call signal because of a brain dead
* signal() func proto supplied in signal.h by gcc 2.7.2
*/
#include <signal.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define epicsExportSharedSymbols
#include "sigPipeIgnore.h"
typedef void (*pSigFunc) ();
static pSigFunc pReplacedFunc;
static void localInstallSigPipeIgnore (void);
/*
* ignoreSigPipe ()
*/
static void ignoreSigPipe (int param)
{
if (pReplacedFunc) {
(*pReplacedFunc) (param);
}
/*
* some versios of unix reset to SIG_DFL
* each time that the signal occurs
*/
localInstallSigPipeIgnore ();
}
/*
* installSigPipeIgnore ()
*/
epicsShareFunc void epicsShareAPI installSigPipeIgnore (void)
{
static int init;
if (init) {
return;
}
localInstallSigPipeIgnore();
init = 1;
}
/*
* localInstallSigPipeIgnore ()
*
* dont allow disconnect to terminate process
* when running in UNIX environment
*
* allow error to be returned to sendto()
* instead of handling disconnect at interrupt
*/
static void localInstallSigPipeIgnore (void)
{
pSigFunc sigRet;
sigRet = signal (SIGPIPE, ignoreSigPipe);
if (sigRet==SIG_ERR) {
fprintf (stderr, "%s replace of SIGPIPE failed beacuse %s\n",
__FILE__, strerror(errno));
}
else if (sigRet!=SIG_DFL && sigRet!=SIG_IGN) {
pReplacedFunc = sigRet;
}
/*
* no infinite loops
*/
if (pReplacedFunc==ignoreSigPipe) {
pReplacedFunc = NULL;
}
}