Chapter Contents

Previous

Next
Systems Programming with the SAS/C Compiler

The SPE Library

SPE is a minimal C environment. Therefore, the SPE library is a subset of the library available in the full C library. Many of the SPE library functions are provided both in source and object code formats. The following functions comprise the SPE library and may be used in an SPE program. Functions that are not included in this list cannot be used in an SPE environment.

Note:    A * after the function name indicates that the function is only supported under USS; a + after the function name indicates that a special SPE version is supplied; and a # after the function name indicates that the function is only usable with SPE. An at sign (@) after the function name indicates that the function will accept near or far pointers if compiled with the armode option.  [cautionend]

ABEND abs accept * accept_and_recv *
_access * acos alarm * alarmd *
slrdrtv# asctime asin atan
atan2 atexit + atof atoi
atol atoll ATTACH bind *
bldexit # bldretry # blkjmp + bsearch
btrace + calloc ceil cfgetispeed *
cfgetospeed * cfsetispeed * cfsetospeed * CHAP
chaudit* chdir * chmod * chown *
chpriority * clearenv + close * _close *
closedir * cmsclose cmsdfind cmsdnext
cmserase cmsopen cmspoint cmspush
cmsqueue cmsread cmsshv cmsstack
cmsstate cmswrite cmsxflpt cmsxflrd
cmsxflst cmsxflwr CMSSTOR_OBT CMSSTOR_REL
connect * cos cosh creat *
DEQ DETACH difftime div
DMSFREE DMSFREE_V DMSFRET DOM
DOM_TOK dspserv # dup * dup2 *
ecbsuspend * endgrent * endpwent * ENQ
erf erfc ESTAE # ESTAE_CANCEL #
execl * execle * execlp * execv *
execve * execvp * exit + _exit *
exp extlink * fabs falloc #
fchaudit * fchmod * fchown * fcntl *
_fcntl * ffree # floor fmax
fmin fmod fork * format
fpathconf * free + freeexit # FREEMAIN
frexp fstat * fsync * _fsync *
ftruncate * getclientpid * getcwd * getegid *
getenv + geteuid * getgid * getgrent *
getgrgid * getgrnam * getgroups * getgroupsbyname *
gethostid * gethostname * getitimer * getlogin *
GETMAIN_C GETMAIN_U getpeername * getpgid *
getpgrp * getpid * getppid * getpriority *
getpwent * getpwnam * getpwuid * getrlimit *
getrusage * getsid * getsockname * getsockopt *
getuid * getwd * givesocket_pid * gmtime
htoncs hypot initgroups * isalnum
isalpha isascii isatty * iscntrl
iscsym iscsymf isdigit isebcdic
isgraph islower isnotconst isnumconst
isprint ispunct isspace isstrconst
isunresolved isupper isxdigitv j0
j1 jn kill * labs
lchown * ldexp _ldexp ldiv
link listen * llabs lldiv
llmaxllmin loadm + localtim log
log10 longjmp + lseek * _lseek *lstat *
malloc + _matherr max mblen
mbstowcs mbtowc memchr memcmp
memcmpp memcpy memcpyp memfil
memscan memscntb memset memupr
memxlt min mkdir * mkfifo *
mknod * mktime mmap * modf
mount * mprotect * msgctl * msgget *
msgrcv * msgsnd * msgxrcv * msync *
munmap * ntohcs oeabntrap # oeattach *
oeattache * oetaskctl * offsetof onjmp
onjmp open * _open * opendir *
osbclose osbdcb osbldl osbopen
osbopenj oscheck osclose osdcb
osdynalloc osfeov osfind osfindc
osflush osget osnote osopen
osopenj ospoint osput osread
osseek osstow ostclose ostell
oswrite palloc __passwd * pathconf *
pause * pdel pdset pdval
pfree pfscttl * pipe * pool
POST pow putenv + qsort
rand RDTERM read * _read *
readextlink * readv * readdir * readlink *
realpath * recv * recvfrom * recvmsg *
rename * _rename * rewinddir * rmdir *
select * selectecb * semctl * semget *
semop * send * sendmsg * sendto *
setegid * setenv + seteuid * setgid *
setgrent * setgroups * setitimer * setjmp +
setpgid * setpriority * setpwent * setregid *
setreuid * setrlimit * setsid * setsockopt *
setuid * SETRP_COMPCOD # SETRP_DUMP # SETRP_REASON #
SETRP_RETRY # shmat * shmctl * shmdt *
shmget * shutdown * sigaction * sigaddset *
sigblkjmp *+ sigdelset * sigemptyset * sigfillset *
sigismember * siglongjmp * sigpending * sigprocmask *
sigsetjmp * sigsuspend * sin sinh
sleep * sleepd * snprintf socket *
socketpair * spawn * spawnp * sprintf
sqrt srand sscanf stat *
STATUS stcpm stcpma STIMER #
STIMERM # STIMER_CANCEL # STIMERM_SET # STIMERM_TEST #
strcat strchr strcmp strcpy
strcspn strerror strlen strftime
strlwr strncat strncmp strncpy
strpbrkstrrchr strrcspn strrspn strsave
strscan strscntb strspn strstr
strtod strtok strt ol strtoll
strttoul strttoull strupr strxlt
symlink * sysconf * takesocket_pid * tan
tanh tcdrain * tcflow * tcflush *
tcgetattr * tcgetpgrp * tcgetsid * tcsendbreak *
tcsetattr * tcsetpgrp * TGET time
times * toebcdic tolower toupper
TPUT TPUT_ASID TPUT_USERID truncate *
TTIMER # ttyname * typlin umask *
umount * uname * unlink * _unlink *
unloadm + utime * va_arg va_end
va_start vformat vsnprintf vsprintf
w_getmntent * w_getpsent * w_ioctl* w_statfs *
wait * WAIT1 WAITM waitpid *
waitrd WAITT wcstombs wctomb
write * _write * writev * WRTERM
WTO WTOR xedpoint xedread
xedstate xedwrite xltable y0
y1 yn

The SPE library contains functions in the following four categories:

  1. functions that have no full library equivalent and can be used exclusively in SPE (for example, bldexit )

  2. functions that mimic full library functions but have been designed for SPE applications (for example, malloc and free )

  3. functions that invoke commonly used SVCs or operating system functions (for example, waitrd and FREEMAIN )

  4. functions that can be used in both the full library and in SPE.

Most of the functions that comprise the SPE library belong to category 4 and are also considered part of the full SAS/C library. SPE Library Functions lists the functions in the other three categories. The Implementation (Source) column shows whether the function is implemented as a function or as a macro and the name of the corresponding source file, if any. The functions are divided into groups according to the area of the SPE library to which they belong. The functions in category 3 would not normally be used under CICS.

Following SPE Library Functions are descriptions of the functions in categories 1, 2, and 3. The format function and vformat functions (category 4) are also documented in this section. Although these functions can be used in the full C library, sprintf or vsprintf is usually more useful in that framework.

SPE Library Functions
Function Category Implementation (Source)
Memory Management


aleserv
1 macro (<osdspc.h>)

CMSSTOR_OBT 3 macro ( <cmastor.h> )

CMSSTOR_REL 3 macro ( <cmastor.h> )

DMSFREE 3 macro ( <dmsfree.h> )

DMSFREE_V 3 macro ( <dmsfree.h> )

dspserv
1 macro (<osdspc.h>)

falloc
1 macro (<osdspc.h>)

ffree
1 macro (<osdspc.h>)

free 2 function (L$UHEAP)

GETMAIN_C 3 macro ( <getmain.h> )

GETMAIN_U 3 macro ( <getmain.h> )

GETMAIN_V 3 macro ( <getmain.h> )

FREEMAIN 3 macro ( <getmain.h> )

malloc 2 macro (L$UHEAP)
Program Control


atexit 2 function (L$UATEX)

exit 2 function (L$UMAIN,L$UEXIT)

oeabntrap 1 function (L$UZABN,L$UZEST)
Diagnostic Control


btrace 2 function (L$UBTRC)
Dynamic Loading


loadm 2 function (L$ULDR)

unloadm 2 function (L$ULDR)
Signal Handling


bldexit 1 function (L$UEXLK)

bldretry 1 function (L$URETR)

freeexit 1 function (L$UEXLK)

sigaction 2 function (L$UZOEI, L$UZSIA, L$UZSIR)
Environmental Variables


getenv 2 function

putenv 2 function

setenv 2 function
Terminal I/O


RDTERM 3 macro ( <wrterm.h> )

TPUT 3 macro ( <tput.h> , L$UTPIO)

TPUT_ASID 3 macro ( <tput.h> , L$UTPIO)

TPUT_USERID 3 macro ( <tput.h> , L$UTPIO)

TGET 3 macro ( <tput.h> , L$UTPIO)

typlin 3 macro ( <wrterm.h> )

waitrd 3 macro ( <wrterm.h> )

WAITT 3 macro ( <wrterm.h> )

WRTERM 3 macro ( <wrterm.h> )
Other System Interface


CMS low-level I/O 4 function (L$UCMIO)

OS/390 dynamic allocation 4 function (L$UDYNA)

OS/390 low-level I/O 4 function (L$UOSIO, L$UBSAM, L$UDCB)

OS/390 low-level multitasking 4 function (L$UATTA, L$UAEOT)

POSIX system calls 4 function (L$UUBPX)
General Utility


format 4 function

The SPE library functions are described in detail throughout the remainder of this chapter in alphabetical order.


aleserv

Access list management services

SYNOPSIS

#include <osdspc.h>
int aleserv(char *request, ...);


DESCRIPTION

The aleserv function implements the functionality of the OS/390 assembler ALESERV macro. The request argument is a null-terminated string. The request must be one of the following:
"ADD" adds an entry to the access list and return an ALET.
"ADDPASN" adds the primary address space to the DU-AL.
"DELETE" deletes an entry from the DU-AL or PASN-AL.
"EXTRACT" returns the STOKEN associated with a given ALET.
"SEARCH" returns the ALET associated with a given STOKEN.
"EXTRACTH" returns the STOKEN of the HOME address space.

The remainder of the argument list is a list of keywords followed, in most cases, by an argument specifying a value for the keyword. The list is terminated by the _Lend keyword. The supported keywords and their associated data are as follows:

The following parms can be used by authorized programs only:


RETURN VALUE

aleserv returns 0 if the ALESERV macro was successful. If the ALESERV macro fails, it returns the return code from the macro, which will be a positive value. aleserv may also return -1 to indicate an unknown or invalid keyword combination.

IMPLEMENTATION

The aleserv function is implemented by the source module L$UDSPC.

EXAMPLE

For an example of the aleserv function, see the examples under dspserv.

SEE ALSO

dspserv, falloc, ffree


atexit

Register Program Cleanup Function in SPE

SYNOPSIS

#include <stdlib.h>

int atexit(_remote void (*func)());


DESCRIPTION

Refer to Chapter 6, "Function Descriptions," in SAS/C Library Reference, Volume 1 for a description of atexit .

RETURN VALUE

atexit returns 0 if successful or a non-zero value if unsuccessful.

PORTABILITY

atexit is portable.

IMPLEMENTATION

The SPE implementation of atexit is in L$UATEX. This version enforces the ANSI Standard limit of 32 registered functions.

SEE ALSO

exit


bldexit

Build System Exit Linkage in SPE

SYNOPSIS

#include <bldexit.h>

void *bldexit(__remote void (*func)(), unsigned flags);


DESCRIPTION

bldexit builds linkage code enabling a C function to be invoked as a synchronous or asynchronous exit routine. bldexit is supported only when the SPE framework is used; it is not supported with the standard C framework.

The func argument is the address of the C function that is called by the operating system as an exit routine. The flags argument is the sum of zero or more flags indicating attributes of the required exit routine linkage. Note that the exit is expected to be entered with register 14 containing a return address and register 15 serving as a base register.

The following exit attributes can be set:

_ASYNCH
specifies that the exit can be entered asynchronously. This flag should be set if the exit can be entered while a non-C or system routine is running. This flag also should be set if the exit can be entered while a C function without a DSA (a leaf routine) is running or while the C prolog or epilog is running. Failure to specify ASYNCH when appropriate may lead to abends or stack overlays when the exit linkage code is called.

_NOR13
specifies that the exit can be entered with register 13 addressing an area that cannot be used as a save area.

_FLOATSV
specifies that the exit linkage must save and restore floating-point registers. FLOATSV needs to be specified only if the operating system's linkage does not save and restore floating-point registers and if the exit function (or any function it calls) uses the floating-point registers.

_AMODE
specifies that the exit can be entered in a different addressing mode from the interrupted program and that the exit linkage must restore the original mode. This attribute is ignored in a system that does not support 31-bit addressing.

_ACCSV
specifies that the exit linkage must save and restore access registers. _ACCSV needs be specified only if the operating system's linkage does not save and restore access registers, and if the exit function (or any function it calls) is compiled with the armode option or uses the access registers in some other way.

Note:    The old exit attribute names, ASYNCH, NOR13, FLOATSV, and AMODE still work if your program does not include the header file spetask.h as well as bldexit.h.  [cautionend]

The linkage code generated by bldexit is stored in an exit element allocated with GETMAIN or DMSFREE. When the exit is no longer required, you should call the freeexit routine to release this storage.

RETURN VALUE

bldexit returns the address of the exit linkage code. This address should be passed as an argument to the system call that defines the operating system exit.

CAUTIONS

The longjmp and exit functions cannot be called from a routine entered via bldexit linkage code. An attempt to do so results in a user ABEND 1224.

Routines entered via bldexit must be executed as interrupts and cannot execute in parallel with the interrupted code. For example, bldexit cannot be used for code that runs under an SRB because if the code takes a page fault, the interrupted C code can resume execution, causing stack overlays and other disasters.

PORTABILITY

bldexit is not portable.

USAGE NOTES

See Interrupt Handling in SPE for argument specifications for bldexit exit routines.

Source for bldexit is supplied in L$UEXLK. You can modify this source to define attribute bits to support exits with unusual linkages not already supported.

EXAMPLE

This example shows use of bldexit with the SPIE SVC to define a C function to be called if a protection or addressing exception occurs. The C function writes a backtrace using the btrace function and executes a retry in order to terminate the program's execution with a failure return code.

#include <osmain.h>
#include <setjmp.h>
#include <bldexit.h>
#include <svc.h>
struct PICA {  /* Map the Program Interrupt Control Area. */
   char *exit;
   unsigned short bits;
};
#define SPIE(pica, addr, mask) \
        (pica.bits = mask, pica.exit = addr, \
        *(char *) &pica = 0x0f,_ldregs(R1, &pica), \
        _ossvc(14), _stregs(R1))
int oldpica;       /* previous program's PICA */
jmp_buf retrybuf;
static void pgmchk();
extern void msgwtr();  /* unshown message writer routine */
osmain()
   {
      struct PICA my_PICA;
      void *exitloc;
      int rc = 0;     /* success or failure code */
      if (setjmp(retrybuf)) goto pgm_check;
      exitloc = bldexit(&pgmchk, _ASYNCH+_NOR13);
      oldpica = SPIE(my_PICA, exitloc, 0x0c00);
         /* Intercept 0C4 and 0C5, */
         /* then do some real work. */
      goto quit;
pgm_check:
      rc = 16;       /* Set program failure code. */
quit:
      _ldregs(R1, oldpica);
      _ossvc(14);    /* restore old SPIE */
      freeexit(exitloc);
      return rc;
   }
static void pgmchk(sa, poi)
   void **sa;
   char **poi;
   {
      struct {       /* the Program Interrupt Element */
         struct PICA *pica;
         short misc1;
         short int_code;    /* interrupt code              */
         char *addr;        /* location of interrupt/retry */
         char *regs[5];     /* saved registers             */
      } *PIE;
      char msgbuf[40];
      PIE = sa[3];          /* R1 addresses PIE on entry     */
      *poi = PIE->addr;     /* store program check location  */
                            /* for btrace                    */
      format(msgbuf, "Program check %d!", PIE->int_code);
      msgwtr(msgbuf);
      btrace(msgwtr);
      PIE->addr = bldretry(retrybuf, 1);
      return;
   }


SEE ALSO

freeexit , bldretry , signal


bldretry

Build System Retry Linkage via longjmp in SPE

SYNOPSIS

#include <bldexit.h>

void * bldretry(jmp_buf env, int code);


DESCRIPTION

bldretry is called to build linkage code enabling a program location defined with setjmp to be used as a retry routine. The env argument is a jmp_buf , which has been initialized by an earlier call to setjmp . (The jmp_buf type is defined in the header file <setjmp.h> . See "Program Control Functions" in Chapter 2 of the SAS/C Library Reference, Volume 1 for further information.) The code argument is an integer value to be returned by the resumed call to setjmp . If the value of code is 0, 1 is returned.

RETURN VALUE

bldretry returns the address of retry linkage code constructed by bldretry . This address should be supplied to the operating system as the address at which retry is to take place.

On completion of a successful retry, the effect is the same as the effect of a longjmp(env,code) .

CAUTIONS

The values in registers on entry to the retry routine are ignored. If you need to pass information from an exit routine to a retry routine, you should use other mechanisms, such as extern storage, for this purpose.

The retry linkage code is freed immediately before the longjmp to the location defined by env is performed. You must call bldretry again to perform another retry.

EXAMPLE

See the example for bldexit .

SEE ALSO

bldexit , setjmp


btrace

Generate Traceback in SPE

SYNOPSIS

void btrace(__remote void(*func)());


DESCRIPTION

Refer to Chapter 6, "Function Descriptions" in SAS/C Library Reference, Volume 1 for more details. Note that SPE does not support a 0 func address.

When btrace is called directly or indirectly from a bldexit exit function, the traceback will be incomplete unless the exit has stored the point of interrupt. See the description of bldexit for more information.

RETURN VALUE

btrace returns void .

PORTABILITY

btrace is not portable.

IMPLEMENTATION

The SPE implementation of btrace is in L$UBTRC.


dspserv

Dataspace services

SYNOPSIS

#include <osdspc.h>
int dspserv(char *request, ...);


DESCRIPTION

The dspserv function implements the functionality of the OS/390 assembler DSPSERV macro. The request argument is a null-terminated string. The request must be one of the following:
"CREATE" creates a new dataspace.
"RELEASE" returns system resources used to contain user's data.
"DELETE" deletes a dataspace.
"EXTEND" increases the size of a dataspace.
"LOAD" loads some area of a dataspace into central storage.
"OUT" tells system that it can page some areas of a dataspace out of central storage.

The remainder of the argument list is a list of keywords followed, in most cases, by an argument specifying a value for the keyword. The list is terminated by the _Dend keyword. The supported keywords and their associated data are as follows:

The following parms can be used by authorized programs only:


RETURN VALUE

dspserv returns 0 if the DSPSERV macro was successful. If the DSPSERV macro fails, it returns the return code from the macro, which will be a positive value. dspserv may also return -1 to indicate an unknown or invalid keyword combination.

IMPLEMENTATION

The dspserv function is implemented by the source module L$UDSPC.

EXAMPLES

Example 1
This example creates a dataspace and initializes some data using mostly system defaults.
#include <osdspc.h>
#include <string.h>
char stoken[8];
void _ _far * pFar;
int rc;
int alet;
void *origin;

rc = dspserv("CREATE",          
             _Dstoken,  stoken,
             _Dname,    "LSC",  
             _Dorigin,  &origin,
             _Dend);            
if (rc != 0)                    
   abend(1);                    
rc = aleserv("ADD",             
             _Lstoken, stoken,  
             _Lalet,   &alet,   
             _Lend);            
if (rc != 0)                    
   abend(2);


memcpy(&pfar, &alet, 4);               
memcpy(((char *) &pfar)+4, &origin, 4);
strcpy(pFar, "DATASPACE STORAGE");

Example 2
This example extends a dataspace by 300 blocks.
#include <osdspc.h>
char stoken[8];           
int rc;                   
int numblks;
int reason;       


rc = dspserv("EXTEND",                   
             _Dstoken,  stoken,   
             _Dreason,  &reason,         
             _Dblksize, 300,          
             _Dnumblks, &numblks, 
             _Dend);
if (rc != 0)                    
   abend(1);

Example 3
This example deletes a dataspace.
#include <osdspc.h>
char stoken[8];           
int rc;                   

rc = dspserv("DELETE",                   
             _Dstoken,  stoken,   
             _Dend);
if (rc != 0)                    
   abend(1);


SEE ALSO

aleserv, falloc, ffree


exit

Terminate Execution in SPE

SYNOPSIS

#include <stdlib.h>

void exit(int code);


DESCRIPTION

exit terminates the program and returns control to its caller. The integer argument code is returned in register 15. The meaning or value of the exit code is subject to alteration by a start-up routine.

RETURN VALUE

Control does not return from exit .

PORTABILITY

exit is portable.

IMPLEMENTATION

The SPE implementation of exit is in L$UMAIN and L$UEXIT. If blkjmp is used, exit is implemented as a call to longjmp . However, exit does not call longjmp if the longjmp routine is not linked into the load module. In a multiple load module application, it may be desirable to modify L$UEXIT so that longjmp is always called.

SEE ALSO

atexit


falloc

Create a dataspace, or allocate storage from an existing dataspace

SYNOPSIS

#include <osdspc.h>
void __far * falloc(struct _DSPC ** dspc, size_t size);


DESCRIPTION

falloc allocates memory from a dataspace, optionally creating a new dataspace. dspc must be the address of a pointer. On first use, this pointer must be initialized to 0. On return, the pointer will contain the address of a _DSPC struct and a new dataspace will be created. The far pointer returned will address the first byte of this dataspace and the offset portion of this pointer will contain either 0 or 4096 depending on hardware. Subsequent calls to falloc that pass the address of a pointer addressing this _DSPC struct will allocate additional storage from the same dataspace. Each call will return an offset that is a multiple of the blocksize of the dataspace (4096). The length requested in size can be any value up to 2G, but should be a multiple of 4K to make the best use of the dataspace.

RETURN VALUE

falloc returns a far pointer that addresses the first byte of the new block of memory aligned on a 4K boundry. If falloc fails, the returned pointer will contain all zeros. Note that a valid far pointer may have zeros in the offset half of the far pointer.

IMPLEMENTATION

The falloc function is implemented by the source module L$UFALC.

EXAMPLE

#include <osdspc.h>
#include <string.h>
void __far * fptr;
pDSPC pdspc = 0;

fptr = falloc(&pdspc, 4096);

if (fptr)
   memcpy(fptr, "New dataspace");


SEE ALSO

dspserv, aleserv, ffree


ffree

Release dataspace resources

SYNOPSIS

#include <osdspc.h>
void ffree(void __far * fptr);


DESCRIPTION

ffree releases system resources associated with blocks of memory residing in a dataspace. The fptr far pointer must have been set by a previous call to falloc. If all allocations from a dataspace are released, then the DU-AL will be updated to remove the ALET for the dataspace, and the dataspace will be deleted.

RETURN VALUE

none

IMPLEMENTATION

The ffree function is implemented by the source module L$UFALC.

EXAMPLE

#include <osdspc.h>
#include <string.h>
void __far * fptr;
pDSPC pdspc = 0;

fptr = falloc(&pdspc, 4096);

memcpy(fptr, "New dataspace");

ffree(fptr);


SEE ALSO

dspserv, aleserv, falloc


format

Write Formatted Output to a String

SYNOPSIS

#include <lclib.h>

int format(char *s, const char * form , ...);


DESCRIPTION

format is similar to the sprintf function except that it does not support the floating-point conversions ( e , E , f , g , G ). Refer to Chapter 6, "Function Descriptions" in SAS/C Library Reference, Volume 1 for more information.

RETURN VALUE

format returns the number of characters written to the location addressed by s .

DIAGNOSTICS

If there is an error during output, format returns a negative number. The absolute value of this number equals the number of characters written up to the point of error or 1, if none are written.

PORTABILITY

format is not portable.

IMPLEMENTATION

format is implemented as a faster, smaller version of sprintf .

SEE ALSO

sprintf


free

Free a Block of Memory in SPE

SYNOPSIS

#include <stdlib.h>

void free(char *block);


DESCRIPTION

free frees a block of memory previously allocated by the malloc function. block is a pointer to the memory block.

ERRORS

See the IMPLEMENTATION section for the malloc function.

PORTABILITY

free is highly portable.

IMPLEMENTATION

Any malloc memory that has not been freed at program termination will be automatically freed.

See the IMPLEMENTATION section for the malloc function for more details about the implementation of free .

SEE ALSO

malloc , DMSFRET , FREEMAIN


freeexit

Free Exit Linkage Code in SPE

SYNOPSIS

#include <bldexit.h>

void freeexit(void *area);


DESCRIPTION

freeexit frees the memory associated with a bldexit exit routine. The argument to freeexit is the address returned by the previous call to bldexit .

RETURN VALUE

None.

CAUTION

Do not call freeexit for an exit routine that is defined to the operating system.

PORTABILITY

freeexit is not portable.

EXAMPLE

See the example for bldexit .

SEE ALSO

bldexit


getenv

Get Value of Environment Variable in SPE

SYNOPSIS

#include <stdlib.h>

char *getenv(const char *name);


DESCRIPTION

The getenv function searches an environment variable list for a variable name that matches the string pointed to by the name argument. See the description of the putenv function for a discussion on altering and creating environment variables.

RETURN VALUE

The getenv function returns a pointer to the string value associated with the matched name in the environment variable list. If a matching name is not found, getenv returns the value NULL .

CAUTIONS

A subsequent call to getenv overwrites the array pointed to by the first call.

Note that, in the SPE implementation, the names as well as the values of environment variables are case sensitive.

PORTABILITY

The getenv function is defined in accordance with the ANSI Standard for C and POSIX.1.

IMPLEMENTATION

The only environment variables accessible to the SPE getenv are those added by a previous call to putenv or setenv . Note that if you have a program called with exec -linkage that uses the oemain start-up routine, the environment variables passed by the caller of exec are added to the environment using putenv before control is passed to the initial function.

SEE ALSO

putenv , setenv


loadm

Dynamically Load a Load Module in SPE

SYNOPSIS

#include <dynam.h>

void loadm(char *name, __remote /* type */ **fpp());


DESCRIPTION

loadm loads the module named by the first argument string name and stores a C function pointer referencing the initial function of the module.

RETURN VALUE

loadm provides an indirect return value in the form of a function pointer that addresses the entry point of the loaded module. If the module is in the C language, calling the returned function always transfers control to the _dynamn function of the module.

If the module to be loaded cannot be found, a NULL pointer is stored in the location addressed by fpp .

ERRORS

Errors are implementation defined.

CAUTIONS

The second argument must be a pointer to an object declared as pointer to function returning (some C data type).

Subordinate load modules must be linked with the SPE version of the #DYNAMN (for reentrant load modules) or #DYNAMNR (for non-reentrant load module) code. This code is in L$UDYNM and L$UDYNR, respectively. The SPE implementation of loadm cannot load modules linked with the full library version of #DYNAMN or #DYNAMNR. Similarly, the full library implementation of loadm cannot load modules linked with the SPE version of #DYNAMN or #DYNAMNR.

PORTABILITY

loadm is nonportable.

IMPLEMENTATION

The SPE implementation of loadm is in L$ULDR. Under OS/390, loadm is implemented via SVC 8; under CMS, it is implemented via the NUCXLOAD command; and under CICS, it is implemented via the EXEC CICS LOAD command. Note that the SPE loadm is substantially less functional than that of the full library; therefore, this version should be considered as a prototype only. Any serious use of loadm in SPE will require L$ULDR to be extended or rewritten.


malloc

Allocate Memory in SPE

SYNOPSIS

#include <stdlib.h>

char *malloc(size_t size);


DESCRIPTION

malloc allocates a block of dynamic memory of the size requested by size .

RETURN VALUE

malloc returns the address of the first character of the new block of memory. The allocated block is suitably aligned for storage of any type of data.

ERRORS AND DIAGNOSTICS

Errors are implementation defined. See IMPLEMENTATION below.

If adequate memory is not available or if 0 bytes were requested, a NULL (0) pointer is returned.

CAUTIONS

The contents of a block of memory on allocation are random.

The realloc function is not supported, and the full-library realloc function does not work with L$UHEAP. You may implement this function as a simple extension to the existing implementation.

PORTABILITY

malloc is highly portable.

IMPLEMENTATION

The SPE version of malloc is supplied in source as L$UHEAP. The following description of the function is based on this implementation.

The external variable _heap can be used to define the total amount of storage to be reserved for malloc allocation. By default, the amount reserved is determined by the start-up routine. Unlike the full-library malloc , this version does not attempt to allocate more storage if the initial amount is insufficient.

The memory management routines are simpler than those used in the full library and most suited to applications with simple memory management demands. If the application requires more complex memory management, modify L$UHEAP appropriately or consider using the operating system memory management directly with the DMSFREE or GETMAIN macros, or via EXEC CICS GETMAIN commands.

The malloc implementation in L$UHEAP respects two macros, CHECKING and SYNCH. If CHECKING is defined, code that checks for overlays of allocated memory is generated. If an overlay is detected, user ABEND 1206 is issued. If the free function detects an invalid argument, user ABEND 1208 is issued.

If SYNCH is defined, code is generated that allows malloc to be used in asynchronous exits. The supplied object code is compiled with SYNCH defined and CHECKING undefined.

Note that the calloc and the pool allocation functions are compatible with L$UHEAP. Refer to "Memory Allocation Functions" in Chapter 2 of SAS/C Library Reference, Volume 1 for more information.

SEE ALSO

free , DMSFREE , GETMAIN


oeabntrap

Trap ABENDs as USS Signals

SYNOPSIS

#include <oespe.h>

int oeabntrap(int code);


DESCRIPTION

oeabntrap is used to intercept OS/390 ABENDs and transform them into an appropriate USS signal. If the program is being debugged with dbx (or any other similar debugger), the debugger is informed of the ABEND and is allowed to recover it. oeabntrap is supported only in SPE programs; similar functionality is defined automatically when the standard C framework is used.

The code argument is a symbolic value indicating the particular function wanted, one of TRAP_ON , TRAP_OFF , or TRAP_AUTO . When code is TRAP_ON , the ABEND trapping functionality is enabled. When code is TRAP_OFF , ABEND trapping functionality is disabled. When code is TRAP_AUTO , ABEND trapping functionality is enabled, and an atexit routine is defined to disable ABEND trapping at the end of program execution.

If an ABEND occurs while ABEND trapping is enabled, the following events take place:

  1. The ptrace system call is issued to inform any debugger of the event. If the debugger requests that the ABEND be recovered, an appropriate ESTAE retry is issued.

  2. If the ABEND is not recoverable or was issued by the library, or if the signal from a previous ABEND is still pending, the ABEND is allowed to complete.

  3. An ESTAE retry is issued.

  4. The retry routine sends the ABENDing process a signal using the kill system call. If a debugger requested the signal, the signal is chosen by the debugger. If not, an appropriate signal is selected by the retry routine (SIGILL, SIGSEGV, or SIGFPE for program check ABENDs, SIGABRT for user ABENDs, SIGABND for system ABENDs).

  5. If the signal is unable to be delivered, the process is terminated with a user ABEND 1225.


RETURN VALUE

oeabntrap returns 0 if its function was successful. It returns a positive value if the call had no effect (for instance, specifying TRAP_OFF before any trap was established). It returns a negative value if any other error occurred.

CAUTIONS

If you issue your own ESTAE macros in addition to using oeabntrap , it is your responsibility to make sure that your exits do not interfere with the operation of oeabntrap .

Note that you should not block any signal that might be generated by the ABEND trap. The effects of this are unpredictable and are likely to cause recursive ABENDs.

PORTABILITY

oeabntrap is not portable.

USAGE NOTES

Source for oeabntrap is supplied in SPE source modules L$UZABN and L$UZEST.

EXAMPLE

This example uses oeabntrap to catch ABENDs and defines a SIGSEGV handler to call the btrace function to show the location of the error.

#include <oespe.h>
#include <unistd.h>
#include <lclib.h>
#include <string.h>
#include <setjmp.h>
#include <signal.h>

jmp_buf ABEND_escape;
    /* where to run to after an ABEND */

static int ABEND_trapped;

void trace_out(char *line) {
    /* this function writes a btrace output line to file
       descriptor 2 */
    write(2, line, strlen(line));
    write(2, "\n", 1);
}

void ABEND_handler(int signum) {
    char buf[60];
    sprintf(buf, "Interrupted by signal %d!\n", signum);
    write(2, buf, strlen(buf));
    btrace(&trace_out);
    longjmp(ABEND_escape, 1);
}

int ptrvalid(int *ptr) {
    /* return whether storage addressed by ptr can be read */
    sigaction segv_action, prev_action;
    int ok;
    volatile int value;

    if (ABEND_trapped = 0) {
        oeabntrap(TRAP_AUTO);
          /* possibility of error ignored */
        ABEND_trapped = 1;
   }

    if (setjmp(ABEND_escape) != 0) goto failed;
          /* set up retry from handler */
    segv_action.sa_handler = &ABEND_handler;
    sigemptyset(segv_action.sa_mask);
    segv_action.sa_flags = 0;
    struct sigaction(SIGSEGV, &segv_action, &prev_action);
          /* we'll try to access the storage even if
             sigaction fails... */
    value = *ptr;    /* force reference to *ptr */
    ok = 1;          /* it must be valid */
    goto complete;
failed:
    ok = 0;          /* the pointer is no good */
complete:
    sigaction(SIGSEGV, &prev_action, 0);
                     /* restore previous SIGSEGV handling */
    return ok;
}


SEE ALSO

ESTAE, sigaction


putenv

Update Environment Variable in SPE

SYNOPSIS

#include <lclib.h>

int putenv(const char *string);


DESCRIPTION

The putenv function alters an environment variable's value or creates an environment variable with a name and value corresponding to the string pointed to by the string argument. The format of the string argument is

variable-name=value

variable-name
specifies the name of the variable to be created or updated.

=value
specifies a string assigned to the variable. It defaults to a null string "" if it is not specified. All blanks are significant in the string.


RETURN VALUE

The putenv function returns 0 if successful.

PORTABILITY

The putenv function is not portable. It is a complementary extension to getenv .

SEE ALSO

getenv , setenv


setenv

Modify Environment Variables in SPE

SYNOPSIS

#include <stdlib.h>

int setenv(const char *name, const char *value)


DESCRIPTION

setenv adds or replaces environment variables. name is the name of the environment variable. value is the new value to be assigned to the environment variable.

RETURN VALUE

setenv returns 0 if it is successful. setenv returns -1 if it is not successful.

CAUTION

If name includes an equal sign (=), setenv will fail.

PORTABILITY

setenv is defined in accordance with POSIX.1a.

SEE ALSO

getenv , putenv


unloadm

Dynamically Unload a Load Module in SPE

SYNOPSIS

#include <dynam.h>

void unloadm(__remote /* type */ (*fp)());


DESCRIPTION

unloadm unloads the executable module containing the function addressed by fp . If the module is no longer in use, unloadm deletes it from memory.

RETURN VALUE

unloadm does not have a return value.

ERRORS

Errors are implementation defined.

CAUTIONS

Attempting to call a function in an unloaded module is not recommended.

No provision is made for unloading modules at program termination automatically. However, this sort of functionality can be implemented in a function that is registered with atexit .

PORTABILITY

unloadm is nonportable.

IMPLEMENTATION

Refer to the IMPLEMENTATION section for loadm .

SEE ALSO

loadm , atexit


vformat

Write Formatted Output to a String

SYNOPSIS

#include <lclib.h>

int vformat(char *s, const char *form, va_list arg);


DESCRIPTION

vformat is equivalent to format with the variable argument list replaced by arg . The arg parameter has been initialized by a type va_start macro and possibly by va_arg calls. vformat does not change the va_arg list pointers; for example, it does not use the va_start , va_arg , or va_end macros to process the variable argument list.

RETURN VALUE

vformat returns the number of characters written to the location addressed by s .

ERRORS AND DIAGNOSTICS

If there is an error during output, vformat returns a negative number. The absolute value of this number equals the number of characters written up to the point of the error.

PORTABILITY

vformat is not portable.

IMPLEMENTATION

vformat is implemented as a faster, smaller version of vsprintf .

EXAMPLE

#include <lclib.h>
#include <stdarg.h>

   /* Format an error message buffer via format  */
   /* Format the remaining buffer with vformat   */
void error (char *msg_buf, char *fname, *format, ...)
   va_list args;
   int msg_len;
   va_start(args, format);
   msg_len = format(msg_buf,"ERROR in %s: ", fname);
   if (msg_len > 0) msg_buf += msg_len;
   else msg_buf -= msg_len;
   vformat(msg_buf, format, args);
   va_end(args);
}


SEE ALSO

format , sprintf , vsprintf


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.