for (unsigned int i = 0; i < strlen(buffer); i++)
buffer[i] = tolower(buffer[i]);
- return pakfire_strdup(buffer);
+ return strdup(buffer);
}
static const char* __pakfire_arch_native = NULL;
if (uname(&buf) < 0)
return NULL;
- __pakfire_arch_native = pakfire_strdup(buf.machine);
+ __pakfire_arch_native = strdup(buf.machine);
}
return __pakfire_arch_native;
archive_checksum_t* c = calloc(1, sizeof(*c));
if (c) {
c->pakfire = pakfire_ref(pakfire);
- c->filename = pakfire_strdup(filename);
+ c->filename = strdup(filename);
c->algo = algo;
int r = read_hexdigest(c->digest, sizeof(c->digest), s);
if (signature) {
signature->pakfire = pakfire_ref(archive->pakfire);
signature->nrefs = 1;
- signature->sigdata = pakfire_strdup(sigdata);
+ signature->sigdata = strdup(sigdata);
DEBUG(signature->pakfire, "Allocated archive signature at %p\n%s\n",
signature, signature->sigdata);
PAKFIRE_EXPORT PakfireArchive pakfire_archive_open(Pakfire pakfire, const char* path) {
PakfireArchive archive = pakfire_archive_create(pakfire);
- archive->path = pakfire_strdup(path);
+ archive->path = strdup(path);
// Stat the file and store the result
int r = stat(archive->path, &archive->stat);
#warning TODO SUID bits, etc...
- return pakfire_strdup(buffer);
+ return strdup(buffer);
}
static char* pakfire_file_format_mtime(PakfireFile file) {
char buffer[STRING_SIZE];
strftime(buffer, sizeof(buffer), "%d %b %Y %T", timer);
- return pakfire_strdup(buffer);
+ return strdup(buffer);
}
PAKFIRE_EXPORT void pakfire_file_sprintf(PakfireFile file, char* str, size_t len) {
free(file->name);
if (*name == '/') {
- file->name = pakfire_strdup(name);
+ file->name = strdup(name);
} else {
asprintf(&file->name, "/%s", name);
}
}
PAKFIRE_EXPORT void pakfire_file_set_user(PakfireFile file, const char* user) {
- file->user = pakfire_strdup(user);
+ file->user = strdup(user);
}
PAKFIRE_EXPORT const char* pakfire_file_get_group(PakfireFile file) {
}
PAKFIRE_EXPORT void pakfire_file_set_group(PakfireFile file, const char* group) {
- file->group = pakfire_strdup(group);
+ file->group = strdup(group);
}
PAKFIRE_EXPORT mode_t pakfire_file_get_mode(PakfireFile file) {
}
PAKFIRE_EXPORT void pakfire_file_set_chksum(PakfireFile file, const char* chksum) {
- file->chksum = pakfire_strdup(chksum);
+ file->chksum = strdup(chksum);
}
#include <pakfire/types.h>
-void pakfire_oom(size_t num, size_t len);
-
-char* pakfire_strdup(const char* s);
int pakfire_string_startswith(const char* s, const char* prefix);
char* pakfire_format_size(double size);
mem[length] = '\0';
// Copy to our own string buffer
- char* buffer = pakfire_strdup(mem);
+ char* buffer = strdup(mem);
// Release the exported key
gpgme_free(mem);
const char* nevra = pool_solvable2str(pool, s);
- return pakfire_strdup(nevra);
+ return strdup(nevra);
}
PAKFIRE_EXPORT const char* pakfire_package_get_name(PakfirePackage pkg) {
char *e, *v, *r;
split_evr(pool, pakfire_package_get_evr(pkg), &e, &v, &r);
- return pakfire_strdup(v);
+ return strdup(v);
}
PAKFIRE_EXPORT const char* pakfire_package_get_release(PakfirePackage pkg) {
char *e, *v, *r;
split_evr(pool, pakfire_package_get_evr(pkg), &e, &v, &r);
- return pakfire_strdup(r);
+ return strdup(r);
}
PAKFIRE_EXPORT const char* pakfire_package_get_arch(PakfirePackage pkg) {
Solvable* s = get_solvable(pkg);
const char* location = solvable_get_location(s, NULL);
- return pakfire_strdup(location);
+ return strdup(location);
}
static void pakfire_package_dump_add_line(char** str, const char* key, const char* val) {
p->nrefs = 1;
- p->path = pakfire_strdup(path);
+ p->path = strdup(path);
// Set architecture
- p->arch = pakfire_strdup(arch);
+ p->arch = strdup(arch);
// Setup logging
p->log_function = pakfire_log_syslog;
if (pakfire->cache_path)
free(pakfire->cache_path);
- pakfire->cache_path = pakfire_strdup(path);
+ pakfire->cache_path = strdup(path);
DEBUG(pakfire, "Set cache path to %s\n", pakfire->cache_path);
}
# #
#############################################################################*/
+#include <errno.h>
#include <regex.h>
#include <stdlib.h>
#include <string.h>
if (namespace)
asprintf(&buffer, "%s.%s", parent->namespace, namespace);
else
- buffer = pakfire_strdup(parent->namespace);
+ buffer = strdup(parent->namespace);
} else {
if (namespace)
- buffer = pakfire_strdup(namespace);
+ buffer = strdup(namespace);
}
return buffer;
if (r < 0)
return NULL;
} else {
- buffer = pakfire_strdup(name);
+ buffer = strdup(name);
}
return buffer;
static int pakfire_parser_set_declaration(PakfireParser parser,
const char* name, const char* value) {
+ if (!name)
+ return -EINVAL;
+
// Handle when name already exists
struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(parser, name);
if (d) {
// Replace value
if (d->value)
free(d->value);
- d->value = pakfire_strdup(value);
+
+ if (value)
+ d->value = strdup(value);
DEBUG(parser->pakfire, "Updated declaration: %s = %s\n",
d->name, d->value);
return -1;
// Import name & value
- d->name = pakfire_strdup(name);
- d->value = pakfire_strdup(value);
+ d->name = strdup(name);
+ if (value)
+ d->value = strdup(value);
DEBUG(parser->pakfire, "New declaration: %s = %s\n", d->name, d->value);
static struct pakfire_parser_declaration* pakfire_parser_find_declaration(
PakfireParser parser, const char* name) {
+ char* n = NULL;
+
// Create a working copy of the namespace
- char* n = pakfire_strdup(parser->namespace);
+ if (parser->namespace)
+ n = strdup(parser->namespace);
size_t length = ((n) ? strlen(n) : 0) + strlen(name) + 1;
char* buffer = malloc(length + 1);
char* pos = strchr(value, '%');
if (!pos)
- return pakfire_strdup(value);
+ return strdup(value);
// Compile the regular expression
regex_t preg;
}
// Create a working copy of the string we are expanding
- char* buffer = pakfire_strdup(value);
+ char* buffer = strdup(value);
const size_t max_groups = 2;
regmatch_t groups[max_groups];
}
- return pakfire_strdup(s);
+ return strdup(s);
}
PAKFIRE_EXPORT PakfireProblem pakfire_problem_create(PakfireRequest request, Id id) {
const char* str = pool_dep2str(pool, relation->id);
- return pakfire_strdup(str);
+ return strdup(str);
}
PAKFIRE_EXPORT int pakfire_relation2queue(const PakfireRelation relation, Queue* queue, int solver_action) {
}
PAKFIRE_EXPORT void pakfire_repo_set_name(PakfireRepo repo, const char* name) {
- repo->repo->name = pakfire_strdup(name);
+ repo->repo->name = strdup(name);
}
PAKFIRE_EXPORT const char* pakfire_repo_get_description(PakfireRepo repo) {
free(repo->appdata->description);
if (description)
- repo->appdata->description = pakfire_strdup(description);
+ repo->appdata->description = strdup(description);
else
repo->appdata->description = NULL;
free(repo->appdata->baseurl);
if (baseurl)
- repo->appdata->baseurl = pakfire_strdup(baseurl);
+ repo->appdata->baseurl = strdup(baseurl);
else
repo->appdata->baseurl = NULL;
free(repo->appdata->keyfile);
if (keyfile)
- repo->appdata->keyfile = pakfire_strdup(keyfile);
+ repo->appdata->keyfile = strdup(keyfile);
else
repo->appdata->keyfile = NULL;
free(repo->appdata->mirrorlist);
if (mirrorlist)
- repo->appdata->mirrorlist = pakfire_strdup(mirrorlist);
+ repo->appdata->mirrorlist = strdup(mirrorlist);
else
repo->appdata->mirrorlist = NULL;
// Priority
p += sprintf(p, "priority = %d\n", pakfire_repo_get_priority(repo));
- return pakfire_strdup(buffer);
+ return strdup(buffer);
}
PAKFIRE_EXPORT int pakfire_repo_is_installed_repo(PakfireRepo repo) {
f->keyname = keyname;
f->cmp_type = cmp_type;
- f->match = pakfire_strdup(match);
+ f->match = strdup(match);
*filter = f;
}
snprintf(line, STRING_SIZE - 1, _("bad solution element"));
// Save line in elements array
- *elements++ = pakfire_strdup(line);
+ *elements++ = strdup(line);
}
// Terminate array
// the last character
assert((s + length) == p);
- return pakfire_strdup(s);
+ return strdup(s);
}
#include <pakfire/private.h>
#include <pakfire/types.h>
-void pakfire_oom(size_t num, size_t len) {
- if (num)
- fprintf(stderr, "Out of memory allocating %zu*%zu bytes!\n", num, len);
- else
- fprintf(stderr, "Out of memory allocating %zu bytes!\n", len);
-
- abort();
- exit(1);
-}
-
-char* pakfire_strdup(const char* s) {
- if (!s)
- return 0;
-
- char* r = strdup(s);
- if (!r)
- pakfire_oom(0, strlen(s));
-
- return r;
-}
-
PAKFIRE_EXPORT int pakfire_string_startswith(const char* s, const char* prefix) {
return !strncmp(s, prefix, strlen(prefix));
}
snprintf(string, STRING_SIZE, "%.0f%s", round(size), *unit);
- return pakfire_strdup(string);
+ return strdup(string);
}
#pragma GCC diagnostic push
strftime(string, sizeof(string), format, tm);
- return pakfire_strdup(string);
+ return strdup(string);
}
#pragma GCC diagnostic pop
char* buffer;
if (!first)
- return pakfire_strdup(second);
+ return strdup(second);
if (!second)
- return pakfire_strdup(first);
+ return strdup(first);
if (*second == '/')
- return pakfire_strdup(second);
+ return strdup(second);
asprintf(&buffer, "%s/%s", first, second);
}
PAKFIRE_EXPORT char* pakfire_basename(const char* path) {
- char* name = pakfire_strdup(path);
+ char* name = strdup(path);
char* r = basename(name);
if (r)
- r = pakfire_strdup(r);
+ r = strdup(r);
free(name);
}
PAKFIRE_EXPORT char* pakfire_dirname(const char* path) {
- char* parent = pakfire_strdup(path);
+ char* parent = strdup(path);
char* r = dirname(parent);
if (r)
- r = pakfire_strdup(r);
+ r = strdup(r);
free(parent);
unsigned int i = 0;
char* p = buffer;
while (*p) {
- ret[i++] = pakfire_strdup(p);
+ ret[i++] = strdup(p);
// Move pointer to the next string
p += strlen(p) + 1;
*s1 = malloc(l);
snprintf(*s1, l, "%s", s);
- *s2 = pakfire_strdup(p + strlen(delim));
+ *s2 = strdup(p + strlen(delim));
}