/ return name of current tty

.globl	lnxx, _lnxx, lnff

_lnxx:
	mov	r5,-(sp)
	mov	sp,r5
	mov	4(r5),r0
	jsr	pc,lnff
	mov	(sp)+,r5
	rts	pc

lnxx:
	clr	r0
lnff:
	mov	$"xx,name
	tst	-(sp)
	sys	fstat; buf
	bes	er2
	mov	buf+2,(sp)
	sys	stat; dev; buf+2
	cmp	buf,buf+2
	bne	er2
	sys	open; dev; 0
	bes	er2
	mov	r0,r1
1:
	mov	r1,r0
	sys	read; buf; 16.
	bes	er1
	cmp	r0,$16.
	bne	er1
	mov	$buf,r0
	cmp	(r0)+,(sp)
	bne	1b
	cmp	(r0)+,$"ln
	bne	1b
	tstb	(r0)
	beq	1b
	movb	(r0)+,name
	cmpb	(r0),$0
	beq	er
	movb	(r0)+,name+1
	cmpb	(r0),$0
	beq	er1
	br	1b

er:
	movb	$0,name+1
er1:
	mov	r1,r0
	sys	close

er2:
	tst	(sp)+
	mov	name,r0
	rts	pc

.data
dev:	</dev\0>
.even
.bss
buf:	.=.+42.
name:	.=.+2
