2003-06-18 09:56:10 +00:00
|
|
|
|
/**
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
* \file tempname.cpp
|
2003-06-18 09:56:10 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
2003-07-28 22:37:28 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-18 09:56:10 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
#include "support/filetools.h"
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
|
#include "support/Package.h"
|
2004-11-07 13:22:51 +00:00
|
|
|
|
|
2000-11-08 09:39:46 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
#include <boost/scoped_array.hpp>
|
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
|
#include <cstdlib>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2005-01-19 15:26:41 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2005-01-20 15:38:14 +00:00
|
|
|
|
# include <unistd.h>
|
2005-01-19 15:26:41 +00:00
|
|
|
|
#endif
|
2004-11-07 13:22:51 +00:00
|
|
|
|
|
2004-12-15 21:08:24 +00:00
|
|
|
|
#if !defined(HAVE_MKSTEMP) && defined(HAVE_MKTEMP)
|
|
|
|
|
# include <fcntl.h>
|
2005-04-26 10:30:24 +00:00
|
|
|
|
# ifdef HAVE_SYS_STAT_H
|
|
|
|
|
# include <sys/stat.h>
|
|
|
|
|
# endif
|
2005-05-03 20:32:55 +00:00
|
|
|
|
# ifdef HAVE_IO_H
|
|
|
|
|
# include <io.h>
|
|
|
|
|
# endif
|
|
|
|
|
# ifdef HAVE_PROCESS_H
|
|
|
|
|
# include <process.h>
|
|
|
|
|
# endif
|
2004-12-15 21:08:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
using boost::scoped_array;
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-11-08 15:19:55 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
2006-10-21 07:55:42 +00:00
|
|
|
|
namespace lyx {
|
2006-12-27 10:56:11 +00:00
|
|
|
|
namespace support {
|
2006-10-21 07:55:42 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
inline
|
2002-03-21 17:09:55 +00:00
|
|
|
|
int make_tempfile(char * templ)
|
2000-11-15 03:22:08 +00:00
|
|
|
|
{
|
2002-04-15 11:01:19 +00:00
|
|
|
|
#if defined(HAVE_MKSTEMP)
|
2000-11-15 03:22:08 +00:00
|
|
|
|
return ::mkstemp(templ);
|
2002-04-15 11:01:19 +00:00
|
|
|
|
#elif defined(HAVE_MKTEMP)
|
2000-11-15 03:22:08 +00:00
|
|
|
|
// This probably just barely works...
|
2006-10-21 08:30:58 +00:00
|
|
|
|
::mktemp(templ);
|
2005-05-03 20:32:55 +00:00
|
|
|
|
# if defined (HAVE_OPEN)
|
2006-05-29 14:56:08 +00:00
|
|
|
|
# if (!defined S_IRUSR)
|
|
|
|
|
# define S_IRUSR S_IREAD
|
|
|
|
|
# define S_IWUSR S_IWRITE
|
|
|
|
|
# endif
|
2001-05-17 15:11:01 +00:00
|
|
|
|
return ::open(templ, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
2005-05-03 20:32:55 +00:00
|
|
|
|
# elif defined (HAVE__OPEN)
|
2006-10-21 08:30:58 +00:00
|
|
|
|
return ::_open(templ,
|
2006-04-05 23:39:11 +00:00
|
|
|
|
_O_RDWR | _O_CREAT | _O_EXCL,
|
|
|
|
|
_S_IREAD | _S_IWRITE);
|
2005-05-03 20:32:55 +00:00
|
|
|
|
# else
|
|
|
|
|
# error No open() function.
|
|
|
|
|
# endif
|
2000-11-15 03:22:08 +00:00
|
|
|
|
#else
|
2002-04-15 11:01:19 +00:00
|
|
|
|
#error FIX FIX FIX
|
2001-04-17 00:19:49 +00:00
|
|
|
|
#endif
|
2000-11-15 03:22:08 +00:00
|
|
|
|
}
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
FileName const tempName(FileName const & dir, string const & mask)
|
2000-11-08 09:39:46 +00:00
|
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
|
string const tmpdir(dir.empty() ?
|
|
|
|
|
package().temp_dir().toFilesystemEncoding() :
|
|
|
|
|
dir.toFilesystemEncoding());
|
2006-04-08 22:31:11 +00:00
|
|
|
|
string tmpfl(addName(tmpdir, mask));
|
2005-05-03 20:32:55 +00:00
|
|
|
|
#if defined (HAVE_GETPID)
|
2005-01-06 15:40:49 +00:00
|
|
|
|
tmpfl += convert<string>(getpid());
|
2005-05-03 20:32:55 +00:00
|
|
|
|
#elif defined (HAVE__GETPID)
|
|
|
|
|
tmpfl += convert<string>(_getpid());
|
|
|
|
|
#else
|
|
|
|
|
# error No getpid() function
|
|
|
|
|
#endif
|
2000-11-14 02:01:57 +00:00
|
|
|
|
tmpfl += "XXXXXX";
|
|
|
|
|
|
|
|
|
|
// The supposedly safe mkstemp version
|
2003-11-03 17:47:28 +00:00
|
|
|
|
scoped_array<char> tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0'
|
|
|
|
|
tmpfl.copy(tmpl.get(), string::npos);
|
2000-11-14 02:01:57 +00:00
|
|
|
|
tmpl[tmpfl.length()] = '\0'; // terminator
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
int const tmpf = make_tempfile(tmpl.get());
|
2000-11-08 09:39:46 +00:00
|
|
|
|
if (tmpf != -1) {
|
2007-04-06 17:38:11 +00:00
|
|
|
|
string const t(to_utf8(from_filesystem8bit(tmpl.get())));
|
2005-05-03 20:32:55 +00:00
|
|
|
|
#if defined (HAVE_CLOSE)
|
2006-10-21 08:30:58 +00:00
|
|
|
|
::close(tmpf);
|
2005-05-03 20:32:55 +00:00
|
|
|
|
#elif defined (HAVE__CLOSE)
|
|
|
|
|
::_close(tmpf);
|
|
|
|
|
#else
|
2006-10-21 08:30:58 +00:00
|
|
|
|
# error No x() function.
|
2005-05-03 20:32:55 +00:00
|
|
|
|
#endif
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::FILES) << "Temporary file `" << t
|
2000-11-14 02:01:57 +00:00
|
|
|
|
<< "' created." << endl;
|
2006-12-27 10:56:11 +00:00
|
|
|
|
return FileName(t);
|
2000-11-08 09:39:46 +00:00
|
|
|
|
} else {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::FILES)
|
2000-11-14 02:01:57 +00:00
|
|
|
|
<< "LyX Error: Unable to create temporary file."
|
|
|
|
|
<< endl;
|
2006-12-27 10:56:11 +00:00
|
|
|
|
return FileName();
|
2000-11-08 09:39:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2006-12-27 10:56:11 +00:00
|
|
|
|
} // namespace support
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|