13
0

YTK: remove unused code

This addresses a missing `readlink` due to missing
`_POSIX_C_SOURCE=200809` define when including unistd.h
This commit is contained in:
Robin Gareus 2024-03-18 22:02:54 +01:00
parent a2bb1a3511
commit da4218c2db
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 1 additions and 439 deletions

View File

@ -339,48 +339,6 @@ check_setugid (void)
return TRUE; return TRUE;
} }
#ifdef G_OS_WIN32
const gchar *
_gtk_get_datadir (void)
{
static char *gtk_datadir = NULL;
if (gtk_datadir == NULL)
{
gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
gtk_datadir = g_build_filename (root, "share", NULL);
g_free (root);
}
return gtk_datadir;
}
const gchar *
_gtk_get_sysconfdir (void)
{
static char *gtk_sysconfdir = NULL;
if (gtk_sysconfdir == NULL)
{
gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
gtk_sysconfdir = g_build_filename (root, "etc", NULL);
g_free (root);
}
return gtk_sysconfdir;
}
const gchar *
_gtk_get_data_prefix (void)
{
static char *gtk_data_prefix = NULL;
if (gtk_data_prefix == NULL)
gtk_data_prefix = g_win32_get_package_installation_directory_of_module (gtk_dll);
return gtk_data_prefix;
}
#endif /* G_OS_WIN32 */
static gboolean do_setlocale = TRUE; static gboolean do_setlocale = TRUE;
/** /**

View File

@ -296,87 +296,3 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
freeWhenDone:NO] freeWhenDone:NO]
forType:type]; forType:type];
} }
#if 0
/*
* Bundle-based functions for various directories. These almost work
* even when the application isn't in a bundle, becuase mainBundle
* paths point to the bin directory in that case. It's a simple matter
* to test for that and remove the last element.
*/
static const gchar *
get_bundle_path (void)
{
static gchar *path = NULL;
if (path == NULL)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
gchar *base;
[pool drain];
base = g_path_get_basename (resource_path);
if (strcmp (base, "bin") == 0)
path = g_path_get_dirname (resource_path);
else
path = strdup (resource_path);
g_free (resource_path);
g_free (base);
}
return path;
}
const gchar *
_gtk_get_datadir (void)
{
static gchar *path = NULL;
if (path == NULL)
path = g_build_filename (get_bundle_path (), "share", NULL);
return path;
}
const gchar *
_gtk_get_libdir (void)
{
static gchar *path = NULL;
if (path == NULL)
path = g_build_filename (get_bundle_path (), "lib", NULL);
return path;
}
const gchar *
_gtk_get_localedir (void)
{
static gchar *path = NULL;
if (path == NULL)
path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
return path;
}
const gchar *
_gtk_get_sysconfdir (void)
{
static gchar *path = NULL;
if (path == NULL)
path = g_build_filename (get_bundle_path (), "etc", NULL);
return path;
}
const gchar *
_gtk_get_data_prefix (void)
{
return get_bundle_path ();
}
#endif

View File

@ -1,303 +0,0 @@
/* gtklinuxrelocation: functions used to provide relocation on Linux
*
* Copyright (C) 2013 Whomsoever
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "gtkalias.h"
#ifdef G_OS_WIN32
/* include relevant code here */
#elif defined (__APPLE__)
#include <Foundation/Foundation.h>
static const gchar *
get_bundle_path (void)
{
static gchar *path = NULL;
if (path == NULL)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
gchar *base;
[pool drain];
base = g_path_get_basename (resource_path);
if (strcmp (base, "bin") == 0)
path = g_path_get_dirname (resource_path);
else
path = strdup (resource_path);
g_free (resource_path);
g_free (base);
}
return path;
}
#else /* linux */
#include <limits.h>
#ifndef PATH_MAX
# define PATH_MAX 2048
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX LONG_MAX
#endif
/*
* Find the canonical filename of the executable. Returns the filename
* (which must be freed) or NULL on error. If the parameter 'error' is
* not NULL, the error code will be stored there, if an error occured.
*/
static char *
_br_find_exe (gint *error)
{
char *path, *path2, *line, *result;
size_t buf_size;
ssize_t size;
struct stat stat_buf;
FILE *f;
/* Read from /proc/self/exe (symlink) */
if (sizeof (path) > SSIZE_MAX)
buf_size = SSIZE_MAX - 1;
else
buf_size = PATH_MAX - 1;
path = g_try_new (char, buf_size);
if (path == NULL) {
/* Cannot allocate memory. */
if (error)
*error = ENOMEM;
return NULL;
}
path2 = g_try_new (char, buf_size);
if (path2 == NULL) {
/* Cannot allocate memory. */
if (error)
*error = ENOMEM;
g_free (path);
return NULL;
}
strncpy (path2, "/proc/self/exe", buf_size - 1);
while (1) {
int i;
size = readlink (path2, path, buf_size - 1);
if (size == -1) {
/* Error. */
g_free (path2);
break;
}
/* readlink() success. */
path[size] = '\0';
/* Check whether the symlink's target is also a symlink.
* We want to get the final target. */
i = stat (path, &stat_buf);
if (i == -1) {
/* Error. */
g_free (path2);
break;
}
/* stat() success. */
if (!S_ISLNK (stat_buf.st_mode)) {
/* path is not a symlink. Done. */
g_free (path2);
return path;
}
/* path is a symlink. Continue loop and resolve this. */
strncpy (path, path2, buf_size - 1);
}
/* readlink() or stat() failed; this can happen when the program is
* running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
buf_size = PATH_MAX + 128;
line = (char *) g_try_realloc (path, buf_size);
if (line == NULL) {
/* Cannot allocate memory. */
g_free (path);
if (error)
*error = ENOMEM;
return NULL;
}
f = g_fopen ("/proc/self/maps", "r");
if (f == NULL) {
g_free (line);
if (error)
*error = ENOENT;
return NULL;
}
/* The first entry should be the executable name. */
result = fgets (line, (int) buf_size, f);
if (result == NULL) {
fclose (f);
g_free (line);
if (error)
*error = EIO;
return NULL;
}
/* Get rid of newline character. */
buf_size = strlen (line);
if (buf_size <= 0) {
/* Huh? An empty string? */
fclose (f);
g_free (line);
if (error)
*error = ENOENT;
return NULL;
}
if (line[buf_size - 1] == 10)
line[buf_size - 1] = 0;
/* Extract the filename; it is always an absolute path. */
path = strchr (line, '/');
/* Sanity check. */
if (strstr (line, " r-xp ") == NULL || path == NULL) {
fclose (f);
g_free (line);
if (error)
*error = EIO;
return NULL;
}
path = g_strdup (path);
g_free (line);
fclose (f);
return path;
}
static const gchar *
get_bundle_path (void)
{
static gchar *path = NULL;
if (path == NULL)
path = (gchar*) g_getenv ("GTK_BUNDLEDIR");
if (path == NULL)
{
int err;
path = _br_find_exe (&err);
if (path)
{
char* opath = path;
char* dir = g_path_get_dirname (path);
path = g_path_get_dirname (dir);
g_free (opath);
if (dir[0] == '.' && dir[1] == '\0')
g_free (dir);
}
}
return path;
}
#endif
const gchar *
_gtk_get_datadir (void)
{
static const gchar *path = NULL;
if (path == NULL)
path = g_getenv ("GTK_DATADIR");
if (path == NULL)
path = g_build_filename (get_bundle_path (), "share", NULL);
return path;
}
const gchar *
_gtk_get_libdir (void)
{
static const gchar *path = NULL;
if (path == NULL)
path = g_getenv ("GTK_LIBDIR");
if (path == NULL)
path = g_build_filename (get_bundle_path (), "lib", NULL);
return path;
}
const gchar *
_gtk_get_localedir (void)
{
static const gchar *path = NULL;
if (path == NULL)
path = g_getenv ("GTK_LOCALEDIR");
if (path == NULL)
path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
return path;
}
const gchar *
_gtk_get_sysconfdir (void)
{
static const gchar *path = NULL;
if (path == NULL)
path = g_getenv ("GTK_SYSCONFDIR");
if (path == NULL)
path = g_build_filename (get_bundle_path (), "etc", NULL);
return path;
}
const gchar *
_gtk_get_data_prefix (void)
{
return get_bundle_path ();
}

View File

@ -230,7 +230,6 @@ libytk_x11_sources = [
'gtkdnd.c', 'gtkdnd.c',
'gtkmountoperation-x11.c', 'gtkmountoperation-x11.c',
'gtkplug-x11.c', 'gtkplug-x11.c',
'gtkrelocation.c',
'gtksocket-x11.c', 'gtksocket-x11.c',
'gtkxembed.c', 'gtkxembed.c',
] ]
@ -241,7 +240,6 @@ libytk_quartz_sources = [
'gtkmountoperation-stub.c', 'gtkmountoperation-stub.c',
'gtkplug-stub.c', 'gtkplug-stub.c',
'gtkquartz.c', 'gtkquartz.c',
'gtkrelocation.c',
'gtksearchenginequartz.c', 'gtksearchenginequartz.c',
'gtksocket-stub.c', 'gtksocket-stub.c',
] ]

View File

@ -74,8 +74,7 @@ typedef enum
#define GTK_PRIVATE_SET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) |= (PRIVATE_ ## flag)); }G_STMT_END #define GTK_PRIVATE_SET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) |= (PRIVATE_ ## flag)); }G_STMT_END
#define GTK_PRIVATE_UNSET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) &= ~(PRIVATE_ ## flag)); }G_STMT_END #define GTK_PRIVATE_UNSET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) &= ~(PRIVATE_ ## flag)); }G_STMT_END
#if defined G_OS_WIN32 \ #if defined G_OS_WIN32
|| (defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
const gchar *_gtk_get_datadir (); const gchar *_gtk_get_datadir ();
const gchar *_gtk_get_libdir (); const gchar *_gtk_get_libdir ();
@ -83,16 +82,10 @@ const gchar *_gtk_get_sysconfdir ();
const gchar *_gtk_get_localedir (); const gchar *_gtk_get_localedir ();
const gchar *_gtk_get_data_prefix (); const gchar *_gtk_get_data_prefix ();
#undef GTK_DATADIR
#define GTK_DATADIR _gtk_get_datadir ()
#undef GTK_LIBDIR #undef GTK_LIBDIR
#define GTK_LIBDIR _gtk_get_libdir () #define GTK_LIBDIR _gtk_get_libdir ()
#undef GTK_LOCALEDIR #undef GTK_LOCALEDIR
#define GTK_LOCALEDIR _gtk_get_localedir () #define GTK_LOCALEDIR _gtk_get_localedir ()
#undef GTK_SYSCONFDIR
#define GTK_SYSCONFDIR _gtk_get_sysconfdir ()
#undef GTK_DATA_PREFIX
#define GTK_DATA_PREFIX _gtk_get_data_prefix ()
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */