ANSI C standard library

Joe Huffman joe at proto.com
Thu May 2 05:19:56 AEST 1991


gwyn at smoke.brl.mil (Doug Gwyn) writes:

>In article <307 at nazgul.UUCP> bright at nazgul.UUCP (Walter Bright) writes:
>-In article <681 at taumet.com> steve at taumet.com (Stephen Clamage) writes:
>-/Can you name any other functions in the standard C library which
>-/cannot reasonably be written in strictly-conforming C.
[...list deleted...]

>With the possible exception of the startup code, all the above can
>be reasonably written in strictly-conforming C in most environments.

Huh?  You have me a bit confused.  I did the port of Zortech to SCO UNIX.
How could have I written the following in 'C'?

_time   proc    near
        mov     eax,0dh         ;Get time from OS, result in EAX
       	db 9ah			; call far 0x7:0
	dd 0
	dw 07h

        mov     ecx,4[esp]      ;arg passed to time
        jecxz   short time_done ;== NULL?
        mov     [ecx],eax
time_done:
        ret
_time   endp


_lseek  proc    near
        mov     eax,19
       	db 9ah			; call far 0x7:0
	dd 0
	dw 07h
        jc      short cerror	; Carry set on error.
        ret
cerror:
        mov     _errno,eax      ; errno = value returned by kernel
        sbb     eax,eax         ; return value = -1
        ret

_lseek  endp

Note that values must be put in a specific register (EAX) before doing a 
"far" call.  ANSI doesn't recognize a 'far' or 'near' call and in this
implementation of UNIX all 'normal' functions calls are near calls.  Yet to
'talk' to the OS you must go through a 'far' call.  Note also that the 
'Carry' flag is set on error.  Also note that in the case of lseek (required
to implement fseek()) arguments are passed on the stack frame of the caller.
lseek() cannot have it's own stack frame.

So... just one of the many questions that could be asked having gone through
this exercise...  How do I get the carry flag status on return from a 
function call that I can't make, having passed parameters in registers I 
can't access from an ANSI conforming program?

Surely I have missed an assumption you made someplace... this doesn't qualify
as 'most enviroments'?  Yet all other environments that I am familar with 
differ only in the details.
-- 
joe at proto.com



More information about the Comp.std.c mailing list