~njh-aelius/maxosx/musicbrainz-tags

« back to all changes in this revision

Viewing changes to Frameworks/taglib/taglib/tests/utils.h

  • Committer: stephen_booth
  • Date: 2008-04-30 01:48:01 UTC
  • Revision ID: svn-v4:6b6cea13-1402-0410-9567-a7afb52bf336:trunk:1371
Fixing the taglib source tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <string>
2
 
#include <stdio.h>
3
 
#include <sys/fcntl.h>
4
 
 
5
 
using namespace std;
6
 
 
7
 
inline string copyFile(const string &filename, const string &ext)
8
 
{
9
 
  string newname = string(tempnam(NULL, NULL)) + ext;
10
 
  string oldname = string("data/") + filename + ext;
11
 
  char buffer[4096];
12
 
  int bytes;
13
 
  int inf = open(oldname.c_str(), O_RDONLY);
14
 
  int outf = open(newname.c_str(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
15
 
  while((bytes = read(inf, buffer, sizeof(buffer))) > 0)
16
 
    write(outf, buffer, bytes);
17
 
  close(outf);
18
 
  close(inf);
19
 
  return newname;
20
 
}
21
 
 
22
 
inline void deleteFile(const string &filename)
23
 
{
24
 
  remove(filename.c_str());
25
 
}