summaryrefslogtreecommitdiff
path: root/backend/utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'backend/utils.cc')
-rw-r--r--backend/utils.cc68
1 files changed, 37 insertions, 31 deletions
diff --git a/backend/utils.cc b/backend/utils.cc
index 78778d0..30e257a 100644
--- a/backend/utils.cc
+++ b/backend/utils.cc
@@ -1,3 +1,9 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+#include <cstdint>
#include <sqlite3.h>
#include <string.h>
#include "utils.h"
@@ -16,14 +22,14 @@ namespace slack {
* Returns: CURLE_OK (zero) on success, non-zero otherwise.
**/
CURLcode
-get_file (CURL **curl, gchar *source_url, gchar *dest)
+get_file (CURL **curl, char *source_url, char *dest)
{
- gchar *dest_dir_name;
- FILE *fout = NULL;
+ char *dest_dir_name;
+ FILE *fout = nullptr;
CURLcode ret;
glong response_code;
- if ((*curl == NULL) && (!(*curl = curl_easy_init())))
+ if ((*curl == nullptr) && (!(*curl = curl_easy_init())))
{
return CURLE_BAD_FUNCTION_ARGUMENT;
}
@@ -31,7 +37,7 @@ get_file (CURL **curl, gchar *source_url, gchar *dest)
curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(*curl, CURLOPT_URL, source_url);
- if (dest == NULL)
+ if (dest == nullptr)
{
curl_easy_setopt(*curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(*curl, CURLOPT_HEADER, 1L);
@@ -48,10 +54,10 @@ get_file (CURL **curl, gchar *source_url, gchar *dest)
if (g_file_test(dest, G_FILE_TEST_IS_DIR))
{
dest_dir_name = dest;
- dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), NULL);
+ dest = g_strconcat(dest_dir_name, g_strrstr(source_url, "/"), nullptr);
g_free(dest_dir_name);
}
- if ((fout = fopen(dest, "ab")) == NULL)
+ if ((fout = fopen(dest, "ab")) == nullptr)
{
return CURLE_WRITE_ERROR;
}
@@ -59,7 +65,7 @@ get_file (CURL **curl, gchar *source_url, gchar *dest)
ret = curl_easy_perform(*curl);
}
curl_easy_reset(*curl);
- if (fout != NULL)
+ if (fout != nullptr)
{
fclose(fout);
}
@@ -70,23 +76,23 @@ get_file (CURL **curl, gchar *source_url, gchar *dest)
* slack::split_package_name:
* Got the name of a package, without version-arch-release data.
**/
-gchar **
-split_package_name (const gchar *pkg_filename)
+char **
+split_package_name (const char *pkg_filename)
{
- gchar *pkg_full_name;
- gchar **pkg_tokens;
+ char *pkg_full_name;
+ char **pkg_tokens;
- g_return_val_if_fail(pkg_filename != NULL, NULL);
+ g_return_val_if_fail(pkg_filename != nullptr, nullptr);
- gint len = strlen(pkg_filename);
+ int len = strlen(pkg_filename);
if (len < 4)
{
- return NULL;
+ return nullptr;
}
if (pkg_filename[len - 4] == '.')
{
- pkg_tokens = static_cast<gchar **> (g_malloc_n (6, sizeof (gchar *)));
+ pkg_tokens = static_cast<char **> (g_malloc_n (6, sizeof (char *)));
/* Full name without extension */
len -= 4;
@@ -95,18 +101,18 @@ split_package_name (const gchar *pkg_filename)
/* The last 3 characters should be the file extension */
pkg_tokens[4] = g_strdup (pkg_filename + len + 1);
- pkg_tokens[5] = NULL;
+ pkg_tokens[5] = nullptr;
}
else
{
- pkg_tokens = static_cast<gchar **> (g_malloc_n (4, sizeof (gchar *)));
+ pkg_tokens = static_cast<char **> (g_malloc_n (4, sizeof (char *)));
pkg_full_name = g_strdup (pkg_filename);
- pkg_tokens[3] = NULL;
+ pkg_tokens[3] = nullptr;
}
/* Reverse all of the bytes in the package filename to get the name, version and the architecture */
g_strreverse (pkg_full_name);
- gchar **reversed_tokens = g_strsplit (pkg_full_name, "-", 4);
+ char **reversed_tokens = g_strsplit (pkg_full_name, "-", 4);
pkg_tokens[0] = g_strreverse (reversed_tokens[3]); /* Name */
pkg_tokens[1] = g_strreverse (reversed_tokens[2]); /* Version */
pkg_tokens[2] = g_strreverse (reversed_tokens[1]); /* Architecture */
@@ -130,17 +136,17 @@ split_package_name (const gchar *pkg_filename)
* installed, PK_INFO_ENUM_UNKNOWN if pkg_fullname is malformed.
**/
PkInfoEnum
-is_installed (const gchar *pkg_fullname)
+is_installed (const char *pkg_fullname)
{
GFileEnumerator *pkg_metadata_enumerator;
GFileInfo *pkg_metadata_file_info;
GFile *pkg_metadata_dir;
PkInfoEnum ret = PK_INFO_ENUM_INSTALLING;
- const gchar *it;
- guint8 dashes = 0;
+ const char *it;
+ std::uint8_t dashes = 0;
ptrdiff_t pkg_name;
- g_return_val_if_fail(pkg_fullname != NULL, PK_INFO_ENUM_UNKNOWN);
+ g_return_val_if_fail(pkg_fullname != nullptr, PK_INFO_ENUM_UNKNOWN);
// We want to find the package name without version for the package we're
// looking for.
@@ -169,16 +175,16 @@ is_installed (const gchar *pkg_fullname)
if (!(pkg_metadata_enumerator = g_file_enumerate_children(pkg_metadata_dir,
"standard::name",
G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL)))
+ nullptr,
+ nullptr)))
{
g_object_unref(pkg_metadata_dir);
return PK_INFO_ENUM_UNKNOWN;
}
- while ((pkg_metadata_file_info = g_file_enumerator_next_file(pkg_metadata_enumerator, NULL, NULL)))
+ while ((pkg_metadata_file_info = g_file_enumerator_next_file(pkg_metadata_enumerator, nullptr, nullptr)))
{
- const gchar *dir = g_file_info_get_name(pkg_metadata_file_info);
+ const char *dir = g_file_info_get_name(pkg_metadata_file_info);
dashes = 0;
if (strcmp(dir, pkg_fullname) == 0)
@@ -220,12 +226,12 @@ is_installed (const gchar *pkg_fullname)
/**
* slack::cmp_repo:
**/
-gint
-cmp_repo (gconstpointer a, gconstpointer b)
+int
+cmp_repo (const void *a, const void *b)
{
auto repo = static_cast<const Pkgtools *> (a);
- return g_strcmp0 (repo->get_name (), (gchar *) b);
+ return g_strcmp0 (repo->get_name (), (char *) b);
}
}