Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/goo/gfile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/goo/gfile.cc')
-rw-r--r--pdf/goo/gfile.cc96
1 files changed, 80 insertions, 16 deletions
diff --git a/pdf/goo/gfile.cc b/pdf/goo/gfile.cc
index 25fa1c9..d6d2363 100644
--- a/pdf/goo/gfile.cc
+++ b/pdf/goo/gfile.cc
@@ -4,15 +4,18 @@
//
// Miscellaneous file and directory name manipulation.
//
-// Copyright 1996 Derek B. Noonburg
+// Copyright 1996-2002 Glyph & Cog, LLC
//
//========================================================================
-extern "C" {
+#include <aconf.h>
+
#ifdef WIN32
+ extern "C" {
# ifndef _MSC_VER
# include <kpathsea/win32lib.h>
# endif
+ }
#else // !WIN32
# if defined(MACOS)
# include <sys/stat.h>
@@ -30,7 +33,6 @@ extern "C" {
# include <unixlib.h>
# endif
#endif // WIN32
-}
#include "GString.h"
#include "gfile.h"
@@ -442,7 +444,26 @@ time_t getModTime(char *fileName) {
}
GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
-#if defined(VMS) || defined(__EMX__) || defined(WIN32) || defined(ACORN) || defined(MACOS)
+#if defined(WIN32)
+ //---------- Win32 ----------
+ char *s;
+ char buf[_MAX_PATH];
+ char *fp;
+
+ if (!(s = _tempnam(getenv("TEMP"), NULL))) {
+ return gFalse;
+ }
+ *name = new GString(s);
+ free(s);
+ if (ext) {
+ (*name)->append(ext);
+ }
+ if (!(*f = fopen((*name)->getCString(), mode))) {
+ delete (*name);
+ return gFalse;
+ }
+ return gTrue;
+#elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
//---------- non-Unix ----------
char *s;
@@ -464,20 +485,26 @@ GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
return gTrue;
#else
//---------- Unix ----------
- char *s, *p;
+ char *s;
int fd;
if (ext) {
+#if HAVE_MKSTEMPS
+ if ((s = getenv("TMPDIR"))) {
+ *name = new GString(s);
+ } else {
+ *name = new GString("/tmp");
+ }
+ (*name)->append("/XXXXXX")->append(ext);
+ fd = mkstemps((*name)->getCString(), strlen(ext));
+#else
if (!(s = tmpnam(NULL))) {
return gFalse;
}
*name = new GString(s);
- s = (*name)->getCString();
- if ((p = strrchr(s, '.'))) {
- (*name)->del(p - s, (*name)->getLength() - (p - s));
- }
(*name)->append(ext);
fd = open((*name)->getCString(), O_WRONLY | O_CREAT | O_EXCL, 0600);
+#endif
} else {
#if HAVE_MKSTEMP
if ((s = getenv("TMPDIR"))) {
@@ -503,11 +530,48 @@ GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
#endif
}
+GBool executeCommand(char *cmd) {
+#ifdef VMS
+ return system(cmd) ? gTrue : gFalse;
+#else
+ return system(cmd) ? gFalse : gTrue;
+#endif
+}
+
+char *getLine(char *buf, int size, FILE *f) {
+ int c, i;
+
+ i = 0;
+ while (i < size - 1) {
+ if ((c = fgetc(f)) == EOF) {
+ break;
+ }
+ buf[i++] = (char)c;
+ if (c == '\x0a') {
+ break;
+ }
+ if (c == '\x0d') {
+ c = fgetc(f);
+ if (c == '\x0a' && i < size - 1) {
+ buf[i++] = (char)c;
+ } else if (c != EOF) {
+ ungetc(c, f);
+ }
+ break;
+ }
+ }
+ buf[i] = '\0';
+ if (i == 0) {
+ return NULL;
+ }
+ return buf;
+}
+
//------------------------------------------------------------------------
// GDir and GDirEntry
//------------------------------------------------------------------------
-GDirEntry::GDirEntry(char *dirPath, char *name1, GBool doStat) {
+GDirEntry::GDirEntry(char *dirPath, char *nameA, GBool doStat) {
#ifdef VMS
char *p;
#elif defined(WIN32)
@@ -519,17 +583,17 @@ GDirEntry::GDirEntry(char *dirPath, char *name1, GBool doStat) {
GString *s;
#endif
- name = new GString(name1);
+ name = new GString(nameA);
dir = gFalse;
if (doStat) {
#ifdef VMS
- if (!strcmp(name1, "-") ||
- ((p = strrchr(name1, '.')) && !strncmp(p, ".DIR;", 5)))
+ if (!strcmp(nameA, "-") ||
+ ((p = strrchr(nameA, '.')) && !strncmp(p, ".DIR;", 5)))
dir = gTrue;
#elif defined(ACORN)
#else
s = new GString(dirPath);
- appendToPath(s, name1);
+ appendToPath(s, nameA);
#ifdef WIN32
fa = GetFileAttributes(s->getCString());
dir = (fa != 0xFFFFFFFF && (fa & FILE_ATTRIBUTE_DIRECTORY));
@@ -546,9 +610,9 @@ GDirEntry::~GDirEntry() {
delete name;
}
-GDir::GDir(char *name, GBool doStat1) {
+GDir::GDir(char *name, GBool doStatA) {
path = new GString(name);
- doStat = doStat1;
+ doStat = doStatA;
#if defined(WIN32)
GString *tmp;