pbsh.s: detect if stdin is a regular file using seek
seek doesn't fail on special devices, but it always returns zero
This commit is contained in:
+11
-1
@@ -36,7 +36,17 @@ maxargs=10
|
|||||||
|
|
||||||
lac d1
|
lac d1
|
||||||
sys intrp " make shell uninterruptable
|
sys intrp " make shell uninterruptable
|
||||||
sys getuid
|
|
||||||
|
" see if reading from a special file
|
||||||
|
cla; sys seek; 1; 0 " try seeking stdin forward
|
||||||
|
sna " new offset non-zero?
|
||||||
|
jmp 1f " no: input is a special file (ttyin,keyboard)
|
||||||
|
dzm prompt " yes: regular file, kill prompt
|
||||||
|
cla; sys seek; 0; 0 " seek file back to start
|
||||||
|
jmp newline
|
||||||
|
|
||||||
|
" stdin is a special file, see if superuser
|
||||||
|
1: sys getuid
|
||||||
sma " <0?
|
sma " <0?
|
||||||
jmp newline " no
|
jmp newline " no
|
||||||
lac hash " yes: superuser
|
lac hash " yes: superuser
|
||||||
|
|||||||
Reference in New Issue
Block a user