taglib/tests/utils.h
Adriaan de Groot 55c788b608 Previous was me being stupid and too-quick on the commit button. Need unistd as well for read, write.
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@810229 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
2008-05-20 09:29:09 +00:00

28 lines
676 B
C++

#include <string>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/fcntl.h>
using namespace std;
inline string copyFile(const string &filename, const string &ext)
{
string newname = string(tempnam(NULL, NULL)) + ext;
string oldname = string("data/") + filename + ext;
char buffer[4096];
int bytes;
int inf = open(oldname.c_str(), O_RDONLY);
int outf = open(newname.c_str(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
while((bytes = read(inf, buffer, sizeof(buffer))) > 0)
write(outf, buffer, bytes);
close(outf);
close(inf);
return newname;
}
inline void deleteFile(const string &filename)
{
remove(filename.c_str());
}