From cfae54248433fa8a2001ee3f2c9bce32f8807595 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 3 Dec 2017 20:27:08 +1030 Subject: [PATCH 11/13] gfile: remove unused functions --- goo/gfile.cc | 228 ----------------------------------------------------------- goo/gfile.h | 30 -------- 2 files changed, 258 deletions(-) diff --git a/goo/gfile.cc b/goo/gfile.cc index bc7fdb52..d28737cd 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -69,24 +69,6 @@ //------------------------------------------------------------------------ -GooString *getCurrentDir() { - char buf[PATH_MAX+1]; - -#if defined(__EMX__) - if (_getcwd2(buf, sizeof(buf))) -#elif defined(_WIN32) - if (GetCurrentDirectoryA(sizeof(buf), buf)) -#elif defined(ACORN) - if (strcpy(buf, "@")) -#elif defined(MACOS) - if (strcpy(buf, ":")) -#else - if (getcwd(buf, sizeof(buf))) -#endif - return new GooString(buf); - return new GooString(); -} - GooString *appendToPath(GooString *path, const char *fileName) { #if defined(VMS) //---------- VMS ---------- @@ -253,216 +235,6 @@ GooString *appendToPath(GooString *path, const char *fileName) { #endif } -GooString *grabPath(char *fileName) { -#ifdef VMS - //---------- VMS ---------- - char *p; - - if ((p = strrchr(fileName, ']'))) - return new GooString(fileName, p + 1 - fileName); - if ((p = strrchr(fileName, ':'))) - return new GooString(fileName, p + 1 - fileName); - return new GooString(); - -#elif defined(__EMX__) || defined(_WIN32) - //---------- OS/2+EMX and Win32 ---------- - char *p; - - if ((p = strrchr(fileName, '/'))) - return new GooString(fileName, p - fileName); - if ((p = strrchr(fileName, '\\'))) - return new GooString(fileName, p - fileName); - if ((p = strrchr(fileName, ':'))) - return new GooString(fileName, p + 1 - fileName); - return new GooString(); - -#elif defined(ACORN) - //---------- RISCOS ---------- - char *p; - - if ((p = strrchr(fileName, '.'))) - return new GooString(fileName, p - fileName); - return new GooString(); - -#elif defined(MACOS) - //---------- MacOS ---------- - char *p; - - if ((p = strrchr(fileName, ':'))) - return new GooString(fileName, p - fileName); - return new GooString(); - -#else - //---------- Unix ---------- - char *p; - - if ((p = strrchr(fileName, '/'))) - return new GooString(fileName, p - fileName); - return new GooString(); -#endif -} - -GBool isAbsolutePath(char *path) { -#ifdef VMS - //---------- VMS ---------- - return strchr(path, ':') || - (path[0] == '[' && path[1] != '.' && path[1] != '-'); - -#elif defined(__EMX__) || defined(_WIN32) - //---------- OS/2+EMX and Win32 ---------- - return path[0] == '/' || path[0] == '\\' || path[1] == ':'; - -#elif defined(ACORN) - //---------- RISCOS ---------- - return path[0] == '$'; - -#elif defined(MACOS) - //---------- MacOS ---------- - return path[0] != ':'; - -#else - //---------- Unix ---------- - return path[0] == '/'; -#endif -} - -time_t getModTime(char *fileName) { -#ifdef _WIN32 - //~ should implement this, but it's (currently) only used in xpdf - return 0; -#else - struct stat statBuf; - - if (stat(fileName, &statBuf)) { - return 0; - } - return statBuf.st_mtime; -#endif -} - -GBool openTempFile(GooString **name, FILE **f, const char *mode) { -#if defined(_WIN32) - //---------- Win32 ---------- - char *tempDir; - GooString *s, *s2; - FILE *f2; - int t, i; - - // this has the standard race condition problem, but I haven't found - // a better way to generate temp file names with extensions on - // Windows - if ((tempDir = getenv("TEMP"))) { - s = new GooString(tempDir); - s->append('\\'); - } else { - s = new GooString(); - } - s->appendf("x_{0:d}_{1:d}_", - (int)GetCurrentProcessId(), (int)GetCurrentThreadId()); - t = (int)time(NULL); - for (i = 0; i < 1000; ++i) { - s2 = s->copy()->appendf("{0:d}", t + i); - if (!(f2 = fopen(s2->getCString(), "r"))) { - if (!(f2 = fopen(s2->getCString(), mode))) { - delete s2; - delete s; - return gFalse; - } - *name = s2; - *f = f2; - delete s; - return gTrue; - } - fclose(f2); - delete s2; - } - delete s; - return gFalse; -#elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS) - //---------- non-Unix ---------- - char *s; - - // There is a security hole here: an attacker can create a symlink - // with this file name after the tmpnam call and before the fopen - // call. I will happily accept fixes to this function for non-Unix - // OSs. - if (!(s = tmpnam(NULL))) { - return gFalse; - } - *name = new GooString(s); - if (!(*f = fopen((*name)->getCString(), mode))) { - delete (*name); - *name = NULL; - return gFalse; - } - return gTrue; -#else - //---------- Unix ---------- - char *s; - int fd; - -#ifdef HAVE_MKSTEMP - if ((s = getenv("TMPDIR"))) { - *name = new GooString(s); - } else { - *name = new GooString("/tmp"); - } - (*name)->append("/XXXXXX"); - fd = mkstemp((*name)->getCString()); -#else // HAVE_MKSTEMP - if (!(s = tmpnam(NULL))) { - return gFalse; - } - *name = new GooString(s); - fd = open((*name)->getCString(), O_WRONLY | O_CREAT | O_EXCL, 0600); -#endif // HAVE_MKSTEMP - if (fd < 0 || !(*f = fdopen(fd, mode))) { - delete *name; - *name = NULL; - return gFalse; - } - return gTrue; -#endif -} - -#ifdef _WIN32 -GooString *fileNameToUTF8(char *path) { - GooString *s; - char *p; - - s = new GooString(); - for (p = path; *p; ++p) { - if (*p & 0x80) { - s->append((char)(0xc0 | ((*p >> 6) & 0x03))); - s->append((char)(0x80 | (*p & 0x3f))); - } else { - s->append(*p); - } - } - return s; -} - -GooString *fileNameToUTF8(wchar_t *path) { - GooString *s; - wchar_t *p; - - s = new GooString(); - for (p = path; *p; ++p) { - if (*p < 0x80) { - s->append((char)*p); - } else if (*p < 0x800) { - s->append((char)(0xc0 | ((*p >> 6) & 0x1f))); - s->append((char)(0x80 | (*p & 0x3f))); - } else { - s->append((char)(0xe0 | ((*p >> 12) & 0x0f))); - s->append((char)(0x80 | ((*p >> 6) & 0x3f))); - s->append((char)(0x80 | (*p & 0x3f))); - } - } - return s; -} -#endif - FILE *openFile(const char *path, const char *mode) { #ifdef _WIN32 wchar_t *wPath = (wchar_t *)utf8ToUtf16(path); diff --git a/goo/gfile.h b/goo/gfile.h index 769527cb..49a23a14 100644 --- a/goo/gfile.h +++ b/goo/gfile.h @@ -79,40 +79,10 @@ class GooString; //------------------------------------------------------------------------ -// Get current directory. -extern GooString *getCurrentDir(); - // Append a file name to a path string. may be an empty // string, denoting the current directory). Returns . extern GooString *appendToPath(GooString *path, const char *fileName); -// Grab the path from the front of the file name. If there is no -// directory component in , returns an empty string. -extern GooString *grabPath(char *fileName); - -// Is this an absolute path or file name? -extern GBool isAbsolutePath(char *path); - -// Get the modification time for . Returns 0 if there is an -// error. -extern time_t getModTime(char *fileName); - -// Create a temporary file and open it for writing. If is not -// NULL, it will be used as the file name extension. Returns both the -// name and the file pointer. For security reasons, all writing -// should be done to the returned file pointer; the file may be -// reopened later for reading, but not for writing. The string -// should be "w" or "wb". Returns true on success. -extern GBool openTempFile(GooString **name, FILE **f, const char *mode); - -#ifdef _WIN32 -// Convert a file name from Latin-1 to UTF-8. -extern GooString *fileNameToUTF8(char *path); - -// Convert a file name from UCS-2 to UTF-8. -extern GooString *fileNameToUTF8(wchar_t *path); -#endif - // Open a file. On Windows, this converts the path from UTF-8 to // UCS-2 and calls _wfopen (if available). On other OSes, this simply // calls fopen. -- 2.11.0