[lug] C(++) library to detect file type (a la 'file')

rm at fabula.de rm at fabula.de
Fri Nov 1 06:10:17 MST 2002


On Thu, Oct 31, 2002 at 09:24:29PM -0700, Scott A. Herod wrote:
> rm at fabula.de wrote:
> > 
> > What do you mean by 'system call' ? I know of no kernel routine that
> > does file type guessing. Or are you refering to perl's
> > 'system("file $myfile")' function? That's not really an option since
> > it spawns a shell which then spawns the 'file(1)'application ...
> > nothing one would want to do when indexing a largish set of documents ;-)
> > (currently ~ 100 000 docs).
> 
> Yes, like the perl system call (you would probably want 'popen' which
> creates a return pipe for you).  But, as you note, that would be fine
> for one file but not 100k.  Actually, doing 100k file opens is going to
> be painful enough as it is.  

Well, that's one of the reasons i was looking for a library. I need to
stat and open the files anyway (for indexing) and it would be quite con-
venient if i could pass an filehandle to a library call. Anyway, indexing
large document sets is always heavy disk IO ;-)

> Since the file command can take multiple
> files and even read from standard in, it might not be such a bad
> solution, i.e. let the file command deal with opening all of the files.
> 

That could be a short-term solution. Even better a small patch to 'file'
and it won't stop after reading the first filename from STDIN if started
like 'file -' ...

 Thanks

    Ralf
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug



More information about the LUG mailing list