tmpnam
routine in the shared library supplied by
Solaris, libc.so, which is installed in the /usr/lib/sparcv9
directory. The tmpnam
routine generates
a unique filename that can be used safely as a temporary filename.
The temporary filename is typically placed in the /var/tmp
directory.
char * tmpnam(char *s);The attribute table for this prototype would be the following:
routine tmpnam minarg=1 maxarg=1 returns=char255. module=libc; arg 1 char output byaddr format=$cstr255;
x 'if [ ! -L ./libc ] ; then ln -s /usr/lib/sparcv9/libc.so.1 ./libc ; fi' ; x 'setenv LD_LIBRARY_PATH .:/usr/lib/sparcv9:/usr/lib:/lib'; data _null_; length tempname $255 tname $255; retain tempname tname “ “; tname = modulec ('tmpnam', tempname); put tempname = ; put tname = ; run;
/usr/include/limits.h
to be 255 characters, so this
example uses 254 as the length of the generated filename (tempname
) with one character reserved for the null
terminator. The $CSTR255. informat ensures that the null terminator
and all subsequent characters are replaced by trailing blanks when
control returns to the DATA step.
access
routine that is supplied by most UNIX vendors.
This particular access
routine is in
the Hewlett-Packard shared library, libc.sl, which is installed under
the /usr/lib/pa20_64
directory.
access
routine checks the file that is referenced by the accessibility
path according to the bit pattern contained in amode
. You can use the following integer values for amode
that correspond to the type of permission for which you are testing:
4 Read access 2 Write access 1 Execute (search) access 0 Check existence of file
amode
argument is a pass-by-value, this example includes
the BYVALUE specification for arg 2 in the attribute table. If both arguments were a pass-by-value,
one could use the CALLSEQ=BYVALUE attribute in the ROUTINE statement
and it would not be necessary to specify the BYVALUE option in arg 2.
routine access minarg=2 maxarg=2 returns=short module=libc; arg 1 char input byaddr format=$cstr200.; arg 2 num input byvalue format=ib4.;
x 'if [ ! -L ./libc ] ; then ln -s /usr/lib/pa20_64/libc.so ; fi' ; x 'setenv LD_LIBRARY_PATH .:/usr/lib/pa20_64:/usr/lib:/lib' ; data _null_; length path $200.; path='/dev'; /* A non-root user is testing for write permission in the /dev directory */ rc = modulen("*ie",'access',path,2); put rc = ; run;The SAS log output would be the following:
data _null_; length homedir $200.; homedir=sysget('HOME'); /* A user is testing for write permissions in their $HOME directory */ rc = modulen(“*ie”,'access',homedir,2); put rc = ; run;
strcat
routine, which is part of the Red Hat Linux
shared library libc-2.2.3.so. This library is typically installed
in the /lib/i686
directory. This routine
concatenates two strings and returns a pointer to the newly concatenated
string.
routine strcat minarg=2 maxarg=2 returns=ulong module=libc; arg 1 char input format=$cstr200.; arg 2 char input format=$cstr200.;
filenamesascbtbl './sascbtbl.txt'; data _null_; file sascbtbl; put "routine strcat minarg=2 maxarg=2 returns=ulong module=libc;"; put "arg 1 char input format=$cstr200.;"; put "arg 2 char input format=$cstr200.;"; run; data _null_; length string1 string2 newstring $200; length chptr $20; string1='This is string one and'; string2=' this is string two.'; chptr=modulec('strcat', string1, string2); newstring=peekclong(chptr,200); put newstring=; run;
newstring=This is string one and this is string two.
/lib/i686/libc-2.2.3.so
$pwd /lib/i686 $file ./libc-2.2.3.so libc-2.2.3.so: ELF 32-bit LSB shared object, Intel 80386, version 1, not stripped
statvfs
routine that is available under most UNIX operating systems retrieves
file system information. This example uses the statvfs
routine that is in the Solaris libc.so.1 shared library and typically
installed in the /usr/lib/sparcv9
directory.
statvfs
routine will return a 0 if the routine completes successfully and
–1 if there is a failure.
statvfs
structure is defined with the following members: unsigned long f_bsize; /* preferred file system block size */ unsigned long f_frsize; /* fundamental file system block */ unsigned long f_blocks; /* total number of blocks on file system in units */ unsigned long f_bfree; /* total number of free blocks */ unsigned long f_bavail; /* number of free blocks available to non-superuser */ unsigned long f_files; /* total number of file nodes (inodes) */ unsigned long f_ffree; /* total number of free file nodes */ unsigned long f_favail; /* number of inodes available to non-superuser */ unsigned long f_fsid; /* file system id (dev for now) */ char f_basetype[16]; /* target fs type name, null-terminated */ unsigned long f_flag; /* bit mask of flags */ unsigned long g f_namemax; /* maximum filename length */ char f_fstr[32]; /* file system specific string */
routine statvfs minarg=14 maxarg=14 returns=short module=libc; arg 1 char input byaddr format=$char256.; arg 2 num output byaddr fdstart format=pib8.; arg 3 num output format=pib8.; arg 4 num output format=pib8.; arg 5 num output format=pib8.; arg 6 num output format=pib8.; arg 7 num output format=pib8.; arg 8 num output format=pib8.; arg 9 num output format=pib8.; arg 10 num output format=pib8.; arg 11 char output format=$cstr16.; arg 12 num output format=pib8.; arg 13 num output format=pib8.; arg 14 char output format=$cstr32.;
statvfs
routine from within
the DATA step would be the following: x 'if [ ! -L ./libc ]; then ln -s /usr/lib/sparcv9/libc.so.1 ./libc ; fi' ; x 'setenv LD_LIBRARY_PATH .:/usr/lib/sparcv9:/usr/lib:/lib'; data _null_; length f_basetype $16. f_fstr $32.; retain f_bsize f_frsize f_blocks f_bfree f_bavail f_files f_ffree f_favail f_fsid f_flag f_namemax 0; retain f_basetype f_fstr ' '; rc=modulen ('statvfs' , '/tmp', f_bsize, f_frsize, f_blocks, f_bfree, f_bavail, f_files, f_ffree, f_favail, f_fsid, f_basetype, f_flag, f_namemax, f_fstr); put rc = ; put f_bsize = ; put f_frsize = ; put f_blocks = ; put f_bfree = ; put f_bavail = ; put f_files = ; put f_ffree = ; put f_favail = ; put f_fsid = ; put f_basetype = ; put f_flag = ; put f_namemax = ; /* Determining the total bytes available in the file system and then dividing the total number of bytes by the number of bytes in a gigabyte */ gigsfree = ((f_bavail * f_bsize)/1073741824); put 'The total amount of space available in /tmp is 'gigsfree 4.2' Gigabytes.'; run;
changd
routine to add 100x+10y to
each element, where x is the
C row number (0 through 3) and y is the C column number (0 through 4). The first argument to changd
specifies the extra amount to sum. The changdx
routine works just like changd
, except that it expects a transposed matrix. The changi
routine works like changd
except that it
expects a matrix of integers. The changix
routine works like changdx
except that
integers are expected.
routine changd module=trymod returns=long; arg 1 input num format=rb8. byvalue; arg 2 update num format=rb8.; routine changdx module=trymod returns=long transpose=yes; arg 1 input num format=rb8. byvalue; arg 2 update num format=rb8.; routine changi module=trymod returns=long; arg 1 input num format=ib4. byvalue; arg 2 update num format=ib4.; routine changix module=trymod returns=long transpose=yes; arg 1 input num format=ib4. byvalue; arg 2 update num format=ib4.;
proc iml; x1 = J(4,5,0); do i=1 to 4; do j=1 to 5; x1[i,j] = i*10+j+3; end; end; y1= x1; x2 = x1; y2 = y1; rc = modulein('changd',6,x1); rc = modulein('changdx',6,x2); rc = modulein('changi',6,y1); rc = modulein('changix',6,y2); print x1 x2 y1 y2; run;
X1 20 31 42 53 64 130 141 152 163 174 240 251 262 273 284 350 361 372 383 394 X2 20 31 42 53 64 130 141 152 163 174 240 251 262 273 284 350 361 372 383 394 Y1 20 31 42 53 64 130 141 152 163 174 240 251 262 273 284 350 361 372 383 394 Y2 20 31 42 53 64 130 141 152 163 174 240 251 262 273 284 350 361 372 383 394