}
+ FILE*
+ mkstemp(string& path)
+ {
+ char* tmp = strdup(path.c_str());
+
+ int fd = ::mkstemp(tmp);
+ if (fd == -1)
+ return NULL;
+
+ path = tmp;
+ free(tmp);
+
+ return fdopen(fd, "w");
+ }
+
+
static const blocxx::String component = "libsnapper";
list<string> glob(const string& path, int flags);
+ FILE* mkstemp(string& path);
+
int clonefile(const string& dest, const string& src, mode_t mode);
int readlink(const string& path, string& buf);
string output = snapper->snapshotsDir() + "/" + decString(num2) + "/filelist-" +
decString(num1) + ".txt";
- char* tmp_name = (char*) malloc(output.length() + 12);
- strcpy(tmp_name, output.c_str());
- strcat(tmp_name, ".tmp-XXXXXX");
+ string tmp_name = output + ".tmp-XXXXXX";
- int fd = mkstemp(tmp_name);
-
- FILE* file = fdopen(fd, "w");
+ FILE* file = mkstemp(tmp_name);
for (const_iterator it = entries.begin(); it != entries.end(); ++it)
{
fclose(file);
- rename(tmp_name, output.c_str());
-
- free(tmp_name);
+ rename(tmp_name.c_str(), output.c_str());
return true;
}
using namespace std;
-char* tmp_name = NULL;
+string tmp_name;
FILE* file = NULL;
if (file != NULL)
fclose(file);
- if (tmp_name != NULL)
- unlink(tmp_name);
+ if (!tmp_name.empty())
+ unlink(tmp_name.c_str());
exit(EXIT_FAILURE);
}
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
- tmp_name = (char*) malloc(output.length() + 12);
- strcpy(tmp_name, output.c_str());
- strcat(tmp_name, ".tmp-XXXXXX");
+ tmp_name = output + ".tmp-XXXXXX";
- int fd = mkstemp(tmp_name);
-
- file = fdopen(fd, "w");
+ file = mkstemp(tmp_name);
cmpDirs(path1, path2, write_line);
fclose(file);
- rename(tmp_name, output.c_str());
-
- free(tmp_name);
+ rename(tmp_name.c_str(), output.c_str());
exit(EXIT_SUCCESS);
}