Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gooStub.cpp

Go to the documentation of this file.
00001 
00002 extern "C" {
00003 
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <unistd.h>
00007 #include <stdio.h>
00008 #include <dirent.h>
00009 #include <fcntl.h>
00010 
00011 #include <gmem.h>
00012 }
00013 
00014 #include <gfile.h>
00015 #include <GString.h>
00016 
00017 #include <qdir.h>
00018 
00019 
00020 // replacement stubs to simplify (and speed up) operations
00021 
00022 void *gmalloc ( int size )                   { return malloc ( size ); }
00023 void *grealloc ( void *p, int size )         { return realloc ( p, size ); }
00024 void gfree ( void *p )                       { free ( p ); }
00025 char *copyString ( char *str )               { return strdup ( str ); }
00026 char *getLine(char *buf, int size, FILE *f)  { return fgets ( buf, size, f ); }
00027 GString *getHomeDir ( )                      { return new GString ( QDir::home ( ). absPath ( ). local8Bit ( )); }
00028 GString *appendToPath ( GString *path, char *fileName )   { return new GString ( QDir ( path-> getCString ( )). absFilePath ( fileName ). local8Bit ( )); }
00029 
00030 // mostly taken from XPDF, but simplified...
00031 
00032 GBool openTempFile ( GString **name, FILE **f, char *mode, char *ext )
00033 {
00034         char *s, *p;
00035         int fd;
00036         
00037         if ( !ext ) 
00038                 ext = ".tmp";
00039         
00040         if (!( s = tmpnam ( 0 ))) 
00041                 return gFalse;
00042                         
00043         *name = new GString ( s );
00044 
00045         s = (*name)-> getCString ( );
00046         if (( p = strrchr ( s, '.' ))) 
00047                 (*name)-> del ( p - s, (*name)-> getLength ( ) - ( p - s ));
00048         
00049         (*name)-> append ( "_qpdf" );
00050         (*name)-> append ( ext );
00051         
00052         fd = open ((*name)-> getCString ( ), O_WRONLY | O_CREAT | O_EXCL, 0600 );
00053         
00054         if ( fd < 0 || !( *f = fdopen ( fd, mode ))) {
00055                 delete *name;
00056                 return gFalse;
00057         }
00058         
00059         return gTrue;   
00060 }

Generated on Sat Nov 5 16:18:12 2005 for OPIE by  doxygen 1.4.2