[gs-devel] Problems with stdin and return code -101

Russell Lang gsview at ghostgum.com.au
Fri Feb 6 02:28:00 PST 2009


Sheri,

Your code used
    fh = pJobProcessor->GetGSConverter()->GetFileHandle();
    nRead = _read( fh, buf, len ) ;

Note that there are two types of file handles.  There is the Windows file handle 
(type HANDLE) and the C RTL file handle (type int).

The C function _read requires the C file handle.  If you give it the Windows file 
handle it will almost certainly fail in the way you describe.  That is, _read will 
return -1 for error, which will cause ghostscript to exit.

If you want to associate a Windows file handle with a C file handle, then you use 
something like
fd = _open_osfhandle((long)hfile, 0);
if (fd == -1)
    return_error(gs_fopen_errno_to_code(EBADF));

I tried to find a way to set the code page on a per process or per thread basis, 
but it looks Windows can't do this.  My thought was that if you could force GS to 
use the UTF-8 code page, then you could easily write a wrapper to map a 
Unicode command line into UTF-8.

Russell



On 6 Feb 2009 at 8:47, Ken Sharp wrote:

> Hi Sheri,
> 
> At 12:14 05/02/2009 -0500, Sheri Steeves wrote:
> 
> 
> >Thanks for quick response.
> 
> I see you've been talking to Russell too ;-)
> 
> 
> >to a log file, and that's where I got the error message "failed to open
> >the file", and the lRet from gs_init_with_args returned -101. Stupid of
> >me to assume, I should have checked the error codes.
> 
> Not a problem, but I needed to clear up my own confusion :-)
> 
> 
> >I had traced my stdin callback, I did have a valid handle and I was
> >reading data. I did this before posting to the list! I also get a valid
> >output file for ps and PDF (which was weird... - just lucky?).
> 
> No, this sounds correct. It seems like you fed the PostScript file to GS 
> and it created output files, then when you ceased sending bytes it closed 
> GS using the quit operator (which is normal) and returned the -101 error 
> code so that you know why it terminated.
> 
> The puzzle is the 'failed to open file' error message. I've had a scan 
> through the source code and I can't find an error message which matches 
> that. Could you try again and post the full text please ?
> 
> 
> >IF gs_init_args returns -101 (exit) for error or end of file, I can put
> >some sanity code in my stdin so that when I read less bytes than
> >requested, I know I'm at the EOF and the -101 is not "really" and error.
> 
> Well -101 means the quit operator was executed, this is documented 
> somewhere.. Ah, in /doc/API.htm, section 3.11 Return Codes:
> 
> e_Quit      "quit" has been executed. This is not an error. gsapi_exit() 
> must be called next.
> .
> .
> < 0         Error
> <= -100         Fatal error. gsapi_exit() must be called next.
> 
> 
> PostScript errors lie between -1 and (nominally) -99 though actually only 
> about 39 are used. -100 is a fatal error, and includes use of the quit 
> operator in the context of a real PostScript error.
> 
> So you can special case error return -101 as an end of input safely.
> 
> 
>                          Ken
> 
> _______________________________________________
> gs-devel mailing list
> gs-devel at ghostscript.com
> http://www.ghostscript.com/mailman/listinfo/gs-devel


Russell Lang                   gsview at ghostgum.com.au
Ghostgum Software Pty Ltd      http://www.ghostgum.com.au/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ghostscript.com/pipermail/gs-devel/attachments/20090206/f6d6c669/attachment.htm


More information about the gs-devel mailing list