home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part2 / openfiles.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.6 KB  |  133 lines

  1. # include       <stdio.h>
  2. # include       "sps.h"
  3. # include       "flags.h"
  4.  
  5. /* Miscellaneous procedures */
  6.  
  7. /* OPENFILE - Opens the named file */
  8. openfile ( name )
  9.  
  10. char                            *name ;
  11.  
  12. {
  13.     register int            fd ;
  14.  
  15.     if ( (fd = open( name, 0 )) >= 0 )
  16.         return ( fd ) ;
  17.     fprintf( stderr, "sps - Can't open %s", name ) ;
  18.     sysperror() ;
  19.     /* NOTREACHED */
  20. }
  21.  
  22. /* MEMSEEK - Seek on a special file */
  23. memseek ( fd, pos )
  24.  
  25. int                             fd ;
  26. long                            pos ;
  27.  
  28. {
  29.     extern int              errno ;
  30.     extern struct flags     Flg ;
  31.     long                    lseek() ;
  32.  
  33.     errno = 0 ;
  34.     if ( Flg.flg_k )
  35.         pos &= 0x7fffffff ;
  36.     (void)lseek( fd, pos, 0 ) ;
  37.     if ( errno )
  38.     {
  39.         fprintf( stderr, "sps - Seek failed" ) ;
  40.         sysperror() ;
  41.     }
  42. }
  43.  
  44. /* SWSEEK - Seek on the swap device */
  45. swseek ( pos )
  46.  
  47. long                            pos ;
  48.  
  49. {
  50.     extern int              Flswap ;
  51.     extern int              errno ;
  52.     long                    lseek() ;
  53.  
  54.     errno = 0 ;
  55.     (void)lseek( Flswap, pos, 0 ) ;
  56.     if ( errno )
  57.     {
  58.         fprintf( stderr, "sps - Seek failed" ) ;
  59.         sysperror() ;
  60.     }
  61. }
  62.  
  63. # ifdef lint
  64. int                             errno ;
  65. int                             sys_nerr ;
  66. char                            *sys_errlist[] ;
  67. # endif
  68.  
  69. /* SYSPERROR - Reports a system defined error msg and then exits gracefully */
  70. sysperror ()
  71. {
  72.     extern int              errno ;
  73.     extern int              sys_nerr ;
  74.     extern char             *sys_errlist[] ;
  75.  
  76.     if ( 0 < errno && errno < sys_nerr )
  77.         fprintf( stderr, " : %s", sys_errlist[errno] ) ;
  78.     (void)fputc( '\n', stderr ) ;
  79.     exit( 1 ) ;
  80. }
  81.  
  82. /* STRSAVE - Store a string in core for later use. */
  83. char    *strsave ( cp )
  84.  
  85. register char                   *cp ;
  86.  
  87. {
  88.     register char           *chp ;
  89.     char                    *getcore(), *strcpy() ;
  90.  
  91.     chp = getcore( strlen( cp ) + 1 ) ;
  92.     (void)strcpy( chp, cp ) ;
  93.     return ( chp ) ;
  94. }
  95.  
  96. /* GETCORE - Allocate and return a pointer to the asked for amount of core */
  97. char    *getcore ( size )
  98.  
  99. register int                    size ;
  100.  
  101. {
  102.     register char           *chp ;
  103.     char                    *malloc() ;
  104.  
  105.     if ( chp = malloc( (unsigned)size ) )
  106.         return ( chp ) ;
  107.     fprintf( stderr, "sps - Out of core" ) ;
  108.     sysperror() ;
  109.     /* NOTREACHED */
  110. }
  111.  
  112. union flaglist  *getflgsp ( argc )
  113.  
  114. register int                    argc ;
  115.  
  116. {
  117.     char                    *getcore() ;
  118.  
  119.     return ( (union flaglist*)getcore( sizeof( union flaglist )*argc ) ) ;
  120. }
  121.  
  122. /* PREXIT - Print an error message and exit */
  123. /* VARARGS1 */
  124. /* ARGSUSED */
  125. prexit ( fmt, args )
  126.  
  127. char                            *fmt ;
  128.  
  129. {
  130.     _doprnt( fmt, &args, stderr ) ;
  131.     exit( 1 ) ;
  132. }
  133.