continue;
}
if (str_startswith(argv[i], "-fprofile-dir=")) {
- args_info.profile_dir = from_owned_cstr(x_strdup(argv[i] + 14));
+ args_info.profile_dir.assign(argv[i] + 14);
args_add(common_args, argv[i]);
continue;
}
#endif
}
-std::string
-from_owned_cstr(char* str)
-{
- std::string result;
- if (str) {
- result = str;
- free(str);
- }
- return result;
-}
-
std::string
from_cstr(const char* str)
{
void set_cloexec_flag(int fd);
double time_seconds();
-// Convert an owned char* string `str` to an std::string and free `str`.
-std::string from_owned_cstr(char* str);
-
// Convert a char* string `str` to an std::string, if `str` is NULL return "".
std::string from_cstr(const char* str);
free(cstr1);
}
-TEST(from_owned_cstr)
-{
- char* cstr1 = x_strdup("foo");
- char* cstr2 = x_strdup("bar");
- char* cstr3 = nullptr;
- char* cstr4 = x_strdup("");
-
- std::string str1 = from_owned_cstr(cstr1);
- std::string str2 = from_owned_cstr(cstr2);
- std::string str3 = from_owned_cstr(cstr3);
- std::string str4 = from_owned_cstr(cstr4);
-
- CHECK(str1 == "foo");
- CHECK(str2 == "bar");
- CHECK(str3 == "");
- CHECK(str4 == "");
-}
-
TEST_SUITE_END