Re: g_scanner and third party seeks



On Mon, 9 Nov 1998, Robert Wilhelm wrote:

> 
> 
> I do I tell g_scanner, that I have lseek'd the fd?
> 
> g_scanner_sync_file_offset() does not help, because it just seeks
> the readahead back.
> g_scanner_input_file() does not help, because it calls g_scanner_sync_file_offset().
> 
> maybe you could add something like following function:
> 
> void
> g_scanner_seek_file(GScanner *scanner, gint offset )
> {
>   g_return_if_fail (scanner != NULL);
> 
>   if (scanner->input_fd >= 0)
>     {
>       if (lseek (scanner->input_fd, offset, SEEK_SET) >= 0)
> 	{
> 	  /* we succeeded, blow our buffer's contents now */
> 	  scanner->text = NULL;
> 	  scanner->text_end = NULL;
> 	}
>       else
> 	errno = 0;
>     }
> }

hi robert,
thanx for your input on this matter.
i'm a bit hasitated to include this function into the normal
GScanner API, because i don't like the idea of exposing
filedescriptor specific calls to the GScanner API, when we know
that this is not really supposed to work with every filedescriptor
implementation, e.g. pipes (they are not lseekable).
g_scanner_sync_file_offset() is a little bit of a hack because of
this, and should probably include specific tests whether the fd is
actually seekable.
this will hopefully change, as soon as an IO abstraction for GLib is
implemented which can be used as an input to GScanner.
as a workaround, you could currently:

g_scanner_input_text (s, NULL, 0);
lseek (your_fd, offset, SEEK_SET);
g_scanner_input_file (s, your_fd);

> 	
> -- 
> Robert Wilhelm
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]