home *** CD-ROM | disk | FTP | other *** search
- # ifndef lint
- static char SccsId[] = "@(#)openfiles.c 1.1\t10/1/88" ;
- # endif
-
- # include <stdio.h>
- # include "sps.h"
- # include "flags.h"
- # include <varargs.h>
- # ifdef KVM
- # include <kvm.h>
- # endif
-
- /* Miscellaneous procedures */
-
- /* OPENFILE - Opens the named file */
- openfile ( name )
-
- char *name ;
-
- {
- register int fd ;
-
- if ( (fd = open( name, 0 )) >= 0 )
- return ( fd ) ;
- fprintf( stderr, "sps - Can't open %s", name ) ;
- sysperror() ;
- /* NOTREACHED */
- }
-
- # ifdef KVM
-
- getkmem ( addr, buf, bufsize )
-
- long addr ;
- char *buf ;
- int bufsize ;
- {
- extern kvm_t *Flkvm ;
-
- return( kvm_read( Flkvm, (long)addr, buf, bufsize ) ) ;
- }
-
- # else
-
- getkmem ( addr, buf, bufsize )
-
- long addr ;
- char *buf ;
- int bufsize ;
- {
- extern int Flkmem ;
-
- memseek( Flkmem, (long)addr ) ;
- return( read( Flkmem, buf, bufsize ) ) ;
- }
-
- /* MEMSEEK - Seek on a special file */
- memseek ( fd, pos )
-
- int fd ;
- long pos ;
-
- {
- extern int errno ;
- extern struct flags Flg ;
- long lseek() ;
-
- errno = 0 ;
- if ( Flg.flg_k )
- # ifdef SUN
- pos &= KERNELBASE - 1 ;
- # else
- pos &= 0x7fffffff ;
- # endif
- (void)lseek( fd, pos, 0 ) ;
- if ( errno )
- {
- fprintf( stderr, "sps - Seek failed" ) ;
- sysperror() ;
- }
- }
-
- /* SWSEEK - Seek on the swap device */
- swseek ( pos )
-
- long pos ;
-
- {
- extern int Flswap ;
- extern int errno ;
- long lseek() ;
-
- errno = 0 ;
- (void)lseek( Flswap, pos, 0 ) ;
- if ( errno )
- {
- fprintf( stderr, "sps - Seek failed" ) ;
- sysperror() ;
- }
- }
-
- # endif
-
- # ifdef lint
- int errno ;
- int sys_nerr ;
- char *sys_errlist[] ;
- # endif
-
- /* SYSPERROR - Reports a system defined error msg and then exits gracefully */
- sysperror ()
- {
- extern int errno ;
- extern int sys_nerr ;
- extern char *sys_errlist[] ;
-
- if ( 0 < errno && errno < sys_nerr )
- fprintf( stderr, " : %s", sys_errlist[errno] ) ;
- (void)fputc( '\n', stderr ) ;
- exit( 1 ) ;
- }
-
- /* STRSAVE - Store a string in core for later use. */
- char *strsave ( cp )
-
- register char *cp ;
-
- {
- register char *chp ;
- char *getcore(), *strcpy() ;
-
- chp = getcore( strlen( cp ) + 1 ) ;
- (void)strcpy( chp, cp ) ;
- return ( chp ) ;
- }
-
- /* GETCORE - Allocate and return a pointer to the asked for amount of core */
- char *getcore ( size )
-
- register int size ;
-
- {
- register char *chp ;
- char *malloc() ;
-
- if ( chp = malloc( (unsigned)size ) )
- return ( chp ) ;
- fprintf( stderr, "sps - Out of core" ) ;
- sysperror() ;
- /* NOTREACHED */
- }
-
- union flaglist *getflgsp ( argc )
-
- register int argc ;
-
- {
- char *getcore() ;
-
- return ( (union flaglist*)getcore( sizeof( union flaglist )*argc ) ) ;
- }
-
- /* PREXIT - Print an error message and exit */
- /* VARARGS */
- /* ARGSUSED */
- prexit ( va_alist )
-
- va_dcl
-
- {
- char *fmt ;
- va_list args ;
-
- va_start( args ) ;
- fmt = va_arg( args, char * ) ;
-
- vfprintf( stderr, fmt, args ) ;
- exit( 1 ) ;
- }
-
- # ifndef VPRINTF
-
- int vfprintf ( filep, fmt, args )
-
- FILE *filep ;
- char *fmt ;
- va_list args ;
-
- {
- _doprnt( fmt, args, filep ) ;
- return( ferror( filep ) ? EOF : 0 ) ;
- }
-
- # endif
-