#include <config.h>
#include <cctype>
+#include <fstream>
+using std::fstream;
+using std::ios;
+
#include <utility>
using std::make_pair;
using std::pair;
#ifdef WITH_WARNINGS
#warning Add proper emx support here!
#endif
- string qname = name;
- while (qname.find("'") != string::npos)
- LSubstring(qname, "'") = "\\'";
- return '\'' + qname + '\'';
+#ifndef __EMX__
+ return '\'' + name + '\'';
+#else
+ return name;
+#endif
}
// -1 error (doesn't exist, no access, anything else)
int IsFileWriteable (string const & path)
{
- FilePtr fp(path, FilePtr::update);
- if (!fp()) {
- if ((errno == EACCES) || (errno == EROFS)) {
- fp.reopen(path, FilePtr::read);
- if (fp()) {
- return 0;
- }
- }
- return -1;
+ fstream fs(path.c_str(), ios::out|ios::ate);
+ if (!fs) {
+ fs.open(path.c_str(), ios::in|ios::ate);
+ if (fs)
+ return 0;
+ else
+ return -1;
}
return 1;
}
_("Could not test if directory is writeable"));
return -1;
} else {
- FilePtr fp(tmpfl, FilePtr::truncate);
- if (!fp()) {
- if (errno == EACCES) {
- return 0;
- } else {
- WriteFSAlert(_("LyX Internal Error!"),
- _("Cannot open directory test file"));
- return -1;
- }
- }
+ FileInfo fi(path);
+ if (fi.writable()) return 1;
+ return 0;
}
- if (remove(tmpfl.c_str())) {
- WriteFSAlert(_("LyX Internal Error!"),
- _("Created test file but cannot remove it?"));
- return -1;
- }
- return 1;
}
// this leaks, but what can we do about it?
// Is doing a getenv() and a free() of the older value
// a good idea? (JMarc)
- int retval = putenv((new string(envstr))->c_str());
+ // Actually we don't have to leak...calling putenv like this
+ // should be enough: ... and this is obviously not enough if putenv
+ // does not make a copy of the string. It is also not very wise to
+ // put a string on the free store. If we have to leak we should do it
+ // like this:
+ /*
+ char * leaker = new char[envstr.length() + 1];
+ envstr.copy(leaker, envstr.length());
+ leaker[envstr.length()] = '\0';
+ int retval = putenv(const_cast<PUTENV_TYPE_ARG>(leaker));
+ */
+
+ // If putenv does not make a copy of the char const * this
+ // is very dangerous. OTOH if it does take a copy this is the
+ // best solution.
+ int retval = putenv(const_cast<PUTENV_TYPE_ARG>(envstr.c_str()));
#else
#ifdef HAVE_SETENV
string varname;
// create our own popen based on fork, exec, pipe
// of course the best would be to have a
// pstream (process stream), with the
- // variants ipstream, opstream and
+ // variants ipstream, opstream
FILE * inf = popen(cmd.c_str(), "r");
string ret;
int c = fgetc(inf);
string kpsecmd = "kpsewhich --format= " + format + " " + OnlyFilename(fil);
cmdret c = do_popen(kpsecmd);
- lyxerr << "kpse status = " << c.first << "\n"
- << "kpse result = `" << strip(c.second, '\n') << "'" << endl;
+ lyxerr[Debug::LATEX] << "kpse status = " << c.first << "\n"
+ << "kpse result = `" << strip(c.second, '\n')
+ << "'" << endl;
return c.first != -1 ? strip(c.second, '\n') : string();
}