Merge commit '235f8ed2fb85270a1b9edddbff6a1c5b10f484b9' into PSI-7.0
Conflicts: .ci
This commit is contained in:
@@ -7,12 +7,17 @@
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/*
|
||||
* Fast numeric to string conversions
|
||||
/**
|
||||
* \file cvtFast.h
|
||||
* \author Bob Dalesio, Mark Anderson, Marty Kraimer
|
||||
*
|
||||
* Original Authors:
|
||||
* Bob Dalesio, Mark Anderson and Marty Kraimer
|
||||
* Date: 12 January 1993
|
||||
* \brief Fast numeric to string conversions
|
||||
*
|
||||
* \details
|
||||
* Provides routines for converting various numeric types into an ascii string.
|
||||
* They off a combination of speed and convenience not available with sprintf().
|
||||
*
|
||||
* All functions return the number of characters in the output
|
||||
*/
|
||||
|
||||
#ifndef INCcvtFasth
|
||||
@@ -27,9 +32,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* All functions return the number of characters in the output
|
||||
*/
|
||||
LIBCOM_API int
|
||||
cvtFloatToString(float val, char *pdest, epicsUInt16 prec);
|
||||
LIBCOM_API int
|
||||
|
||||
@@ -7,7 +7,17 @@
|
||||
* EPICS Base is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* Author: Marty Kraimer Date: 04-19-94 */
|
||||
/**
|
||||
* \file freeList.h
|
||||
* \author Marty Kraimer
|
||||
*
|
||||
* \brief Allocate and free fixed size memory elements.
|
||||
*
|
||||
* \details
|
||||
* Describes routines to allocate and free fixed size memory elements.
|
||||
* Free elements are maintained on a free list rather than being returned to the heap via calls to free.
|
||||
* When it is necessary to call malloc(), memory is allocated in multiples of the element size.
|
||||
*/
|
||||
|
||||
#ifndef INCfreeListh
|
||||
#define INCfreeListh
|
||||
@@ -19,7 +29,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
LIBCOM_API void epicsStdCall freeListInitPvt(void **ppvt,int size,int nmalloc);
|
||||
LIBCOM_API void epicsStdCall freeListInitPvt(void **ppvt, int size, int malloc);
|
||||
LIBCOM_API void * epicsStdCall freeListCalloc(void *pvt);
|
||||
LIBCOM_API void * epicsStdCall freeListMalloc(void *pvt);
|
||||
LIBCOM_API void epicsStdCall freeListFree(void *pvt,void*pmem);
|
||||
@@ -31,3 +41,4 @@ LIBCOM_API size_t epicsStdCall freeListItemsAvail(void *pvt);
|
||||
#endif
|
||||
|
||||
#endif /*INCfreeListh*/
|
||||
|
||||
@@ -27,6 +27,30 @@
|
||||
#include "epicsGeneralTime.h"
|
||||
#include "libComRegister.h"
|
||||
|
||||
/* Register the PWD environment variable when the cd IOC shell function is
|
||||
* registered. This variable contains the current directory path.
|
||||
*/
|
||||
static void updatePWD() {
|
||||
static int lasterror;
|
||||
char buf[1024];
|
||||
char *pwd = getcwd(buf, sizeof(buf));
|
||||
if (pwd) {
|
||||
pwd[sizeof(buf) - 1] = '\0';
|
||||
lasterror = 0;
|
||||
epicsEnvSet("PWD", buf);
|
||||
} else {
|
||||
if(lasterror!=errno) {
|
||||
lasterror = errno;
|
||||
if (errno == ERANGE) {
|
||||
fprintf(stderr, "Warning: Current path exceeds %u characters\n",
|
||||
(unsigned)sizeof(buf));
|
||||
} else {
|
||||
perror("getcwd");
|
||||
}
|
||||
fprintf(stderr, "Warning: Unable to update $PWD\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* date */
|
||||
void date(const char *format)
|
||||
@@ -83,6 +107,8 @@ static void chdirCallFunc(const iocshArgBuf *args)
|
||||
if (args[0].sval == NULL ||
|
||||
iocshSetError(chdir(args[0].sval))) {
|
||||
fprintf(stderr, "Invalid directory path, ignored\n");
|
||||
} else {
|
||||
updatePWD();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +117,10 @@ static const iocshFuncDef pwdFuncDef = {"pwd", 0, 0,
|
||||
"Print name of current/working directory\n"};
|
||||
static void pwdCallFunc (const iocshArgBuf *args)
|
||||
{
|
||||
char buf[256];
|
||||
char *pwd = getcwd ( buf, sizeof(buf) - 1 );
|
||||
char buf[1024];
|
||||
char *pwd = getcwd ( buf, sizeof(buf) );
|
||||
if ( pwd ) {
|
||||
buf[sizeof(buf)-1u] = '\0';
|
||||
printf ( "%s\n", pwd );
|
||||
}
|
||||
}
|
||||
@@ -449,6 +476,8 @@ void epicsStdCall libComRegister(void)
|
||||
iocshRegister(&chdirFuncDef, chdirCallFunc);
|
||||
iocshRegister(&pwdFuncDef, pwdCallFunc);
|
||||
|
||||
updatePWD();
|
||||
|
||||
iocshRegister(&epicsEnvSetFuncDef, epicsEnvSetCallFunc);
|
||||
iocshRegister(&epicsEnvUnsetFuncDef, epicsEnvUnsetCallFunc);
|
||||
iocshRegister(&epicsParamShowFuncDef, epicsParamShowCallFunc);
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Saskatchewan
|
||||
* SPDX-License-Identifier: EPICS
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* osdEnv.c */
|
||||
/*
|
||||
* Author: Eric Norum
|
||||
* Date: May 7, 2001
|
||||
*
|
||||
* Routines to modify/display environment variables and EPICS parameters
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* Starting in Mac OS X 10.5 (Leopard) shared libraries and
|
||||
* bundles don't have direct access to environ (man environ).
|
||||
*/
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include "envDefs.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
if (!name) return;
|
||||
iocshEnvClear(name);
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
extern char **environ;
|
||||
char **sp;
|
||||
|
||||
for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
|
||||
printf ("%s\n", *sp);
|
||||
}
|
||||
else {
|
||||
const char *cp = getenv (name);
|
||||
if (cp == NULL)
|
||||
printf ("%s is not an environment variable.\n", name);
|
||||
else
|
||||
printf ("%s=%s\n", name, cp);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Saskatchewan
|
||||
* SPDX-License-Identifier: EPICS
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* osdEnv.c */
|
||||
/*
|
||||
* Author: Eric Norum
|
||||
* Date: May 7, 2001
|
||||
*
|
||||
* Routines to modify/display environment variables and EPICS parameters
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include "envDefs.h"
|
||||
#include "osiUnistd.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
extern char **environ;
|
||||
char **sp;
|
||||
|
||||
for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
|
||||
printf ("%s\n", *sp);
|
||||
}
|
||||
else {
|
||||
const char *cp = getenv (name);
|
||||
if (cp == NULL)
|
||||
printf ("%s is not an environment variable.\n", name);
|
||||
else
|
||||
printf ("%s=%s\n", name, cp);
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,19 @@
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include "errlog.h"
|
||||
#include "cantProceed.h"
|
||||
#include "envDefs.h"
|
||||
#include "osiUnistd.h"
|
||||
#include "epicsFindSymbol.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
static
|
||||
void setEnv(const char *name, const char *value)
|
||||
{
|
||||
errno_t err = _putenv_s(name, value);
|
||||
if(err)
|
||||
errlogPrintf("Can't set environment %s=\"%s\" : %d\n", name, value, (int)err);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
* Leaks memory, but the assumption is that this routine won't be
|
||||
@@ -34,25 +41,8 @@
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
iocshEnvClear(name);
|
||||
|
||||
cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
|
||||
strcpy (cp, name);
|
||||
strcat (cp, "=");
|
||||
strcat (cp, value);
|
||||
if (putenv (cp) < 0) {
|
||||
errPrintf(
|
||||
-1L,
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
"Failed to set environment parameter \"%s\" to \"%s\": %s\n",
|
||||
name,
|
||||
value,
|
||||
strerror (errno));
|
||||
free (cp);
|
||||
}
|
||||
setEnv(name, value);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -63,8 +53,7 @@ LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
if (getenv(name) != NULL)
|
||||
epicsEnvSet((char*)name, "");
|
||||
setEnv(name, "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,13 +20,25 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include "epicsVersion.h"
|
||||
#include "errlog.h"
|
||||
#include "cantProceed.h"
|
||||
#include "envDefs.h"
|
||||
#include "osiUnistd.h"
|
||||
#include "epicsFindSymbol.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
#ifdef __rtems__
|
||||
# include <rtems.h>
|
||||
# define RTEMS_VERSION_INT VERSION_INT(__RTEMS_MAJOR__, __RTEMS_MINOR__, 0, 0)
|
||||
#endif
|
||||
|
||||
#if defined(__RTEMS_MAJOR__) && RTEMS_VERSION_INT<VERSION_INT(4,10,0,0)
|
||||
/* newlib w/ RTEMS <=4.9 returns void */
|
||||
# define unSetEnv(name) ({unsetenv(name); 0;})
|
||||
#else
|
||||
# define unSetEnv(name) unsetenv(name)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
* Leaks memory, but the assumption is that this routine won't be
|
||||
@@ -34,26 +46,9 @@
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
if (!name) return;
|
||||
iocshEnvClear(name);
|
||||
|
||||
cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
|
||||
strcpy (cp, name);
|
||||
strcat (cp, "=");
|
||||
strcat (cp, value);
|
||||
if (putenv (cp) < 0) {
|
||||
errPrintf(
|
||||
-1L,
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
"Failed to set environment parameter \"%s\" to \"%s\": %s\n",
|
||||
name,
|
||||
value,
|
||||
strerror (errno));
|
||||
free (cp);
|
||||
}
|
||||
if(setenv(name, value, 1))
|
||||
errlogPrintf("setenv(\"%s\", \"%s\") -> %d\n", name, value, errno);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -64,8 +59,8 @@ LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
if (getenv(name) != NULL)
|
||||
putenv((char*)name);
|
||||
if(unSetEnv(name))
|
||||
errlogPrintf("unsetenv(\"%s\") -> %d\n", name, errno);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Saskatchewan
|
||||
* SPDX-License-Identifier: EPICS
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
|
||||
/* osdEnv.c */
|
||||
/*
|
||||
* Author: Eric Norum
|
||||
* Date: May 7, 2001
|
||||
*
|
||||
* Routines to modify/display environment variables and EPICS parameters
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include <errlog.h>
|
||||
#include <cantProceed.h>
|
||||
#include <envDefs.h>
|
||||
#include <osiUnistd.h>
|
||||
#include "epicsFindSymbol.h"
|
||||
#include <iocsh.h>
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
if (!name) return;
|
||||
iocshEnvClear(name);
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
extern char **environ;
|
||||
char **sp;
|
||||
|
||||
for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
|
||||
printf ("%s\n", *sp);
|
||||
}
|
||||
else {
|
||||
const char *cp = getenv (name);
|
||||
if (cp == NULL)
|
||||
printf ("%s is not an environment variable.\n", name);
|
||||
else
|
||||
printf ("%s=%s\n", name, cp);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*************************************************************************\
|
||||
* Copyright (c) 2002 The University of Saskatchewan
|
||||
* SPDX-License-Identifier: EPICS
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* osdEnv.c */
|
||||
/*
|
||||
* Author: Eric Norum
|
||||
* Date: May 7, 2001
|
||||
*
|
||||
* Routines to modify/display environment variables and EPICS parameters
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "epicsStdio.h"
|
||||
#include "envDefs.h"
|
||||
#include "osiUnistd.h"
|
||||
#include "iocsh.h"
|
||||
|
||||
/*
|
||||
* Set the value of an environment variable
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
setenv(name, value, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset an environment variable
|
||||
*/
|
||||
|
||||
LIBCOM_API void epicsStdCall epicsEnvUnset (const char *name)
|
||||
{
|
||||
iocshEnvClear(name);
|
||||
unsetenv(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the value of the specified, or all, environment variables
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvShow (const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
extern char **environ;
|
||||
char **sp;
|
||||
|
||||
for (sp = environ ; (sp != NULL) && (*sp != NULL) ; sp++)
|
||||
printf ("%s\n", *sp);
|
||||
}
|
||||
else {
|
||||
const char *cp = getenv (name);
|
||||
if (cp == NULL)
|
||||
printf ("%s is not an environment variable.\n", name);
|
||||
else
|
||||
printf ("%s=%s\n", name, cp);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ctype.h>
|
||||
#include <envLib.h>
|
||||
|
||||
#include "cantProceed.h"
|
||||
#include "epicsFindSymbol.h"
|
||||
#include "epicsStdio.h"
|
||||
#include "errlog.h"
|
||||
@@ -35,25 +34,32 @@
|
||||
*/
|
||||
LIBCOM_API void epicsStdCall epicsEnvSet (const char *name, const char *value)
|
||||
{
|
||||
char *cp;
|
||||
size_t alen = (!name || !value) ? 2u : strlen(name) + strlen(value) + 2u; /* <NAME> '=' <VALUE> '\0' */
|
||||
const int onstack = alen <= 512u; /* use on-stack dynamic array for small strings */
|
||||
char stackarr[ onstack ? alen : 1u]; /* gcc specific dynamic array */
|
||||
char *allocd = onstack ? NULL : malloc(alen);
|
||||
char *cp = onstack ? stackarr : allocd;
|
||||
|
||||
if (!name) {
|
||||
if (!name || !value) {
|
||||
printf ("Usage: epicsEnvSet \"name\", \"value\"\n");
|
||||
return;
|
||||
}
|
||||
|
||||
iocshEnvClear(name);
|
||||
} else if(!cp) {
|
||||
errlogPrintf("epicsEnvSet(\"%s\", \"%s\" insufficient memory\n", name, value);
|
||||
|
||||
cp = mallocMustSucceed (strlen (name) + strlen (value) + 2, "epicsEnvSet");
|
||||
strcpy (cp, name);
|
||||
strcat (cp, "=");
|
||||
strcat (cp, value);
|
||||
if (putenv (cp) < 0) {
|
||||
errPrintf(-1L, __FILE__, __LINE__,
|
||||
"Failed to set environment parameter \"%s\" to \"%s\": %s\n",
|
||||
name, value, strerror (errno));
|
||||
free (cp);
|
||||
} else {
|
||||
int err;
|
||||
|
||||
strcpy (cp, name);
|
||||
strcat (cp, "=");
|
||||
strcat (cp, value);
|
||||
|
||||
iocshEnvClear(name);
|
||||
|
||||
if((err=putenv(cp)) < 0)
|
||||
errlogPrintf("epicsEnvSet(\"%s\", \"%s\" -> %d\n", name, value, err);
|
||||
}
|
||||
/* from at least vxWorks 5.5 putenv() is making a copy, so we can free */
|
||||
free (allocd);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user