Added ctermid, istty, & ttyname -- we are now 100% Posix.

This commit is contained in:
shivers 1996-09-12 20:17:10 +00:00
parent 391365171f
commit 241fe9c520
4 changed files with 69 additions and 0 deletions

View File

@ -17,6 +17,7 @@
extern int errno;
#define errno_or_false(x) (((x) == -1) ? ENTER_FIXNUM(errno) : SCHFALSE)
#define errno_on_zero_or_false(x) ((x) ? SCHFALSE : ENTER_FIXNUM(errno))
scheme_value df_scheme_tcgetattr(long nargs, scheme_value *args)
{
extern int scheme_tcgetattr(int , char *, int *, int *, int *, int *, int *, int *, int *, int *, int *, int *);
@ -147,3 +148,41 @@ scheme_value df_open_ctty(long nargs, scheme_value *args)
return ret1;
}
scheme_value df_isatty(long nargs, scheme_value *args)
{
extern int isatty(int );
scheme_value ret1;
int r1;
cig_check_nargs(1, nargs, "isatty");
r1 = isatty(EXTRACT_FIXNUM(args[0]));
ret1 = ENTER_BOOLEAN(r1);
return ret1;
}
scheme_value df_ttyname(long nargs, scheme_value *args)
{
extern char *ttyname(int );
scheme_value ret1;
char *r1;
cig_check_nargs(2, nargs, "ttyname");
r1 = ttyname(EXTRACT_FIXNUM(args[1]));
ret1 = errno_on_zero_or_false(r1);
{AlienVal(CAR(VECTOR_REF(*args,0))) = (long) r1; CDR(VECTOR_REF(*args,0)) = strlen_or_false(r1);}
return ret1;
}
scheme_value df_scm_ctermid(long nargs, scheme_value *args)
{
extern char *scm_ctermid(void);
scheme_value ret1;
char *r1;
cig_check_nargs(1, nargs, "scm_ctermid");
r1 = scm_ctermid();
ret1 = errno_on_zero_or_false(r1);
{AlienVal(CAR(VECTOR_REF(*args,0))) = (long) r1; CDR(VECTOR_REF(*args,0)) = strlen_or_false(r1);}
return ret1;
}

View File

@ -25,6 +25,7 @@
"extern int errno;"
""
"#define errno_or_false(x) (((x) == -1) ? ENTER_FIXNUM(errno) : SCHFALSE)"
"#define errno_on_zero_or_false(x) ((x) ? SCHFALSE : ENTER_FIXNUM(errno))"
"" )
@ -362,3 +363,27 @@
(multi-rep (to-scheme integer errno_or_false)
integer))
;;; Random bits & pieces: isatty ttyname ctermid
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (tty? fd/port) -> boolean
;;; (tty-file-name fd/port) -> string
;;; (control-tty-file-name) -> string
(define-foreign %tty? (isatty (integer fd)) bool)
(define (tty? fd/port) (sleazy-call/fdes fd/port %tty?))
(define-foreign %tty-file-name/errno (ttyname (integer fd))
(multi-rep (to-scheme static-string errno_on_zero_or_false)
static-string))
(define-errno-syscall (%tty-file-name fd) %tty-file-name/errno
tty-name)
(define (tty-file-name fd/port) (sleazy-call/fdes fd/port %tty-file-name))
(define-foreign %ctermid/errno (scm_ctermid)
(multi-rep (to-scheme static-string errno_on_zero_or_false)
static-string))
(define-errno-syscall (control-tty-file-name) %ctermid/errno term-name)

View File

@ -12,6 +12,7 @@
*/
#include <unistd.h>
#include <stdio.h> /* ctermid decl */
#include <termios.h>
#include <string.h>
#include <sys/types.h>
@ -115,3 +116,5 @@ int open_ctty(const char *ttyname, int flags)
#endif
return fd;
}
char *scm_ctermid() { return ctermid(0); }

View File

@ -17,3 +17,5 @@ int scheme_tcsetattr(int fd, int option,
int min, int time);
int open_ctty(const char *ttyname, int flags);
char *scm_ctermid(void);