src/chardev.c
/************************************************************************/
/*                                                                      */
/*                        C H A R _ o p e n f i l e                     */
/*                                                                      */
/*      Given the arg vector                                            */
/*              args[0] Lisp string full Unix file-name to open                 */
/*              args[1] Access to open it for (INPUT, OUTPUT, BOTH)     */
/*              args[2] a FIXP cell to hold any Unix error number       */
/*                                                                      */
/*      Open the file named, and return the SMALLP descriptor.  If      */
/*      the open fails, return NIL, and put the Unix error number       */
/*      into the FIXP cell provided, for Lisp to look at.               */
/*                                                                      */
/************************************************************************/
C H A R _ o p e n f i l e

Given the arg vector
args[0] Lisp string full Unix file-name to open
args[1] Access to open it for (INPUT, OUTPUT, BOTH)
args[2] a FIXP cell to hold any Unix error number

Open the file named, and return the SMALLP descriptor.  If
the open fails, return NIL, and put the Unix error number
into the FIXP cell provided, for Lisp to look at.
C H A R _ o p e n f i l e Given the arg vector args [ 0 ] Lisp string full Unix file - name to open args [ 1 ] Access to open it for ( INPUT OUTPUT BOTH ) args [ 2 ] a FIXP cell to hold any Unix error number Open the file named and return the SMALLP descriptor . If the open fails return NIL and put the Unix error number into the FIXP cell provided for Lisp to look at .
LispPTR CHAR_openfile(LispPTR *args)
{
#ifndef DOS
  register int fd;    
  register int flags; 
  char pathname[MAXPATHLEN];
  Lisp_errno = (int *)(Addr68k_from_LADDR(args[2]));
  LispStringToCString(args[0], pathname, MAXPATHLEN);
  flags = O_NONBLOCK;
  ERRSETJMP(NIL);
  switch (args[1]) {
    case ACCESS_INPUT: flags |= O_RDONLY; break;
    case ACCESS_OUTPUT: flags |= (O_WRONLY | O_CREAT); break;
    case ACCESS_APPEND: flags |= (O_APPEND | O_RDWR | O_CREAT); break;
    case ACCESS_BOTH: flags |= (O_RDWR | O_CREAT); break;
    default: return (NIL);
  }
  TIMEOUT(fd = open(pathname, flags));
  if (fd == -1) {
    err_mess("open", errno);
    *Lisp_errno = errno;
    return (NIL);
  }
  fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
  return (GetSmallp(fd));
#endif 
}
LispPTR CHAR_openfile ( LispPTR * args ) { #ifndef DOS register int fd ; register int flags ; char pathname [ MAXPATHLEN ] ; Lisp_errno = ( int * ) ( Addr68k_from_LADDR ( args [ 2 ] ) ) ; LispStringToCString ( args [ 0 ] , pathname , MAXPATHLEN ) ; flags = O_NONBLOCK ; ERRSETJMP ( NIL ) ; switch ( args [ 1 ] ) { case ACCESS_INPUT : flags |= O_RDONLY ; break ; case ACCESS_OUTPUT : flags |= ( O_WRONLY | O_CREAT ) ; break ; case ACCESS_APPEND : flags |= ( O_APPEND | O_RDWR | O_CREAT ) ; break ; case ACCESS_BOTH : flags |= ( O_RDWR | O_CREAT ) ; break ; default : return ( NIL ) ; } TIMEOUT ( fd = open ( pathname , flags ) ) ; if ( fd == -1 ) { err_mess ( " " , errno ) ; * Lisp_errno = errno ; return ( NIL ) ; } fcntl ( fd , F_SETFL , fcntl ( fd , F_GETFL , 0 ) | O_NONBLOCK ) ; return ( GetSmallp ( fd ) ) ; #endif }
C H A R _ o p e n f i l e
C H A R _ o p e n f i l e
/* args[0]            fullname */ /* args[1]            access */ /* args[2]            errno */ /* return value  of open system call. */ /* open system call's argument */ /* struct stat statbuf; */ /*    TIMEOUT( rval=stat(pathname, &statbuf) );
      if(rval == 0){      } */ /* Prevent I/O requests from blocking -- make them error */ /* if no char is available, or there's no room in pipe.  */ /* DOS */