summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/gooStub.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/gooStub.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/gooStub.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/gooStub.cpp b/noncore/unsupported/qpdf/gooStub.cpp
new file mode 100644
index 0000000..cc29685
--- a/dev/null
+++ b/noncore/unsupported/qpdf/gooStub.cpp
@@ -0,0 +1,60 @@
1
2extern "C" {
3
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7#include <stdio.h>
8#include <dirent.h>
9#include <fcntl.h>
10
11#include <gmem.h>
12}
13
14#include <gfile.h>
15#include <GString.h>
16
17#include <qdir.h>
18
19
20// replacement stubs to simplify (and speed up) operations
21
22void *gmalloc ( int size ) { return malloc ( size ); }
23void *grealloc ( void *p, int size ) { return realloc ( p, size ); }
24void gfree ( void *p ) { free ( p ); }
25char *copyString ( char *str ) { return strdup ( str ); }
26char *getLine(char *buf, int size, FILE *f) { return fgets ( buf, size, f ); }
27GString *getHomeDir ( ) { return new GString ( QDir::home ( ). absPath ( ). local8Bit ( )); }
28GString *appendToPath ( GString *path, char *fileName ) { return new GString ( QDir ( path-> getCString ( )). absFilePath ( fileName ). local8Bit ( )); }
29
30// mostly taken from XPDF, but simplified...
31
32GBool openTempFile ( GString **name, FILE **f, char *mode, char *ext )
33{
34 char *s, *p;
35 int fd;
36
37 if ( !ext )
38 ext = ".tmp";
39
40 if (!( s = tmpnam ( 0 )))
41 return gFalse;
42
43 *name = new GString ( "qpdf_" );
44 (*name)-> append ( s );
45
46 s = (*name)-> getCString ( );
47 if (( p = strrchr ( s, '.' )))
48 (*name)-> del ( p - s, (*name)-> getLength ( ) - ( p - s ));
49
50 (*name)-> append ( ext );
51
52 fd = open ((*name)-> getCString ( ), O_WRONLY | O_CREAT | O_EXCL, 0600 );
53
54 if ( fd < 0 || !( *f = fdopen ( fd, mode ))) {
55 delete *name;
56 return gFalse;
57 }
58
59 return gTrue;
60}