Compare commits
	
		
			6 Commits
		
	
	
		
			1a76b2032e
			...
			e029aae1d3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						e029aae1d3
	
				 | 
					
					
						|||
| 
						
						
							
						
						b9457c321f
	
				 | 
					
					
						|||
| 
						
						
							
						
						2201becca4
	
				 | 
					
					
						|||
| 
						
						
							
						
						7023c51347
	
				 | 
					
					
						|||
| 
						
						
							
						
						d21f8466b5
	
				 | 
					
					
						|||
| 
						
						
							
						
						7f919025ee
	
				 | 
					
					
						
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
Copyright (c) 2014 - 2018, Přemysl Eric Janouch <p@janouch.name>
 | 
					Copyright (c) 2014 - 2020, Přemysl Eric Janouch <p@janouch.name>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Permission to use, copy, modify, and/or distribute this software for any
 | 
					Permission to use, copy, modify, and/or distribute this software for any
 | 
				
			||||||
purpose with or without fee is hereby granted.
 | 
					purpose with or without fee is hereby granted.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,17 @@
 | 
				
			|||||||
# Public Domain
 | 
					# Public Domain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_package (PkgConfig REQUIRED)
 | 
					find_package (PkgConfig REQUIRED)
 | 
				
			||||||
pkg_check_modules (NCURSESW QUIET ncursesw)
 | 
					pkg_check_modules (Ncursesw QUIET ncursesw)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# OpenBSD doesn't provide a pkg-config file
 | 
					# OpenBSD doesn't provide a pkg-config file
 | 
				
			||||||
set (required_vars NCURSESW_LIBRARIES)
 | 
					set (required_vars Ncursesw_LIBRARIES)
 | 
				
			||||||
if (NOT NCURSESW_FOUND)
 | 
					if (NOT Ncursesw_FOUND)
 | 
				
			||||||
	find_library (NCURSESW_LIBRARIES NAMES ncursesw)
 | 
						find_library (Ncursesw_LIBRARIES NAMES ncursesw)
 | 
				
			||||||
	find_path (NCURSESW_INCLUDE_DIRS ncurses.h)
 | 
						find_path (Ncursesw_INCLUDE_DIRS ncurses.h)
 | 
				
			||||||
	list (APPEND required_vars NCURSESW_INCLUDE_DIRS)
 | 
						list (APPEND required_vars Ncursesw_INCLUDE_DIRS)
 | 
				
			||||||
endif (NOT NCURSESW_FOUND)
 | 
					endif (NOT Ncursesw_FOUND)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include (FindPackageHandleStandardArgs)
 | 
					include (FindPackageHandleStandardArgs)
 | 
				
			||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (NCURSESW DEFAULT_MSG ${required_vars})
 | 
					FIND_PACKAGE_HANDLE_STANDARD_ARGS (Ncursesw DEFAULT_MSG ${required_vars})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mark_as_advanced (NCURSESW_LIBRARIES NCURSESW_INCLUDE_DIRS)
 | 
					mark_as_advanced (Ncursesw_LIBRARIES Ncursesw_INCLUDE_DIRS)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,10 @@
 | 
				
			|||||||
# Public Domain
 | 
					# Public Domain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_path (UNISTRING_INCLUDE_DIRS unistr.h)
 | 
					find_path (Unistring_INCLUDE_DIRS unistr.h)
 | 
				
			||||||
find_library (UNISTRING_LIBRARIES NAMES unistring libunistring)
 | 
					find_library (Unistring_LIBRARIES NAMES unistring libunistring)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include (FindPackageHandleStandardArgs)
 | 
					include (FindPackageHandleStandardArgs)
 | 
				
			||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS (UNISTRING DEFAULT_MSG
 | 
					FIND_PACKAGE_HANDLE_STANDARD_ARGS (Unistring DEFAULT_MSG
 | 
				
			||||||
	UNISTRING_INCLUDE_DIRS UNISTRING_LIBRARIES)
 | 
						Unistring_INCLUDE_DIRS Unistring_LIBRARIES)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mark_as_advanced (UNISTRING_LIBRARIES UNISTRING_INCLUDE_DIRS)
 | 
					mark_as_advanced (Unistring_LIBRARIES Unistring_INCLUDE_DIRS)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										81
									
								
								liberty.c
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								liberty.c
									
									
									
									
									
								
							@@ -1,7 +1,7 @@
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * liberty.c: the ultimate C unlibrary
 | 
					 * liberty.c: the ultimate C unlibrary
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Copyright (c) 2014 - 2018, Přemysl Eric Janouch <p@janouch.name>
 | 
					 * Copyright (c) 2014 - 2020, Přemysl Eric Janouch <p@janouch.name>
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Permission to use, copy, modify, and/or distribute this software for any
 | 
					 * Permission to use, copy, modify, and/or distribute this software for any
 | 
				
			||||||
 * purpose with or without fee is hereby granted.
 | 
					 * purpose with or without fee is hereby granted.
 | 
				
			||||||
@@ -731,6 +731,21 @@ set_blocking (int fd, bool blocking)
 | 
				
			|||||||
	return prev;
 | 
						return prev;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool
 | 
				
			||||||
 | 
					xwrite (int fd, const char *data, size_t len, struct error **e)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						size_t written = 0;
 | 
				
			||||||
 | 
						while (written < len)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							ssize_t res = write (fd, data + written, len - written);
 | 
				
			||||||
 | 
							if (res >= 0)
 | 
				
			||||||
 | 
								written += res;
 | 
				
			||||||
 | 
							else if (errno != EINTR)
 | 
				
			||||||
 | 
								return error_set (e, "%s", strerror (errno));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
xclose (int fd)
 | 
					xclose (int fd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -1357,6 +1372,7 @@ struct poller_idle
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
					// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The heap could definitely be made faster but we'll prefer simplicity
 | 
				
			||||||
struct poller_timers
 | 
					struct poller_timers
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct poller_timer **heap;         ///< Min-heap of timers
 | 
						struct poller_timer **heap;         ///< Min-heap of timers
 | 
				
			||||||
@@ -2672,6 +2688,12 @@ strncasecmp_ascii (const char *a, const char *b, size_t n)
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool
 | 
				
			||||||
 | 
					iscntrl_ascii (int c)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return (c >= 0 && c < 32) || c == 0x7f;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool
 | 
					static bool
 | 
				
			||||||
isalpha_ascii (int c)
 | 
					isalpha_ascii (int c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -2917,6 +2939,13 @@ base64_encode (const void *data, size_t len, struct str *output)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// --- Utilities ---------------------------------------------------------------
 | 
					// --- Utilities ---------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					cstr_set (char **s, char *new)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						free (*s);
 | 
				
			||||||
 | 
						*s = new;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
cstr_split (const char *s, const char *delimiters, bool ignore_empty,
 | 
					cstr_split (const char *s, const char *delimiters, bool ignore_empty,
 | 
				
			||||||
	struct strv *out)
 | 
						struct strv *out)
 | 
				
			||||||
@@ -2946,10 +2975,10 @@ cstr_strip_in_place (char *s, const char *stripped_chars)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
cstr_transform (char *s, int (*tolower) (int c))
 | 
					cstr_transform (char *s, int (*xform) (int c))
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (; *s; s++)
 | 
						for (; *s; s++)
 | 
				
			||||||
		*s = tolower (*s);
 | 
							*s = xform (*s);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *
 | 
					static char *
 | 
				
			||||||
@@ -2996,6 +3025,7 @@ iconv_xstrdup (iconv_t conv, char *in, size_t in_len, size_t *out_len)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	char *in_ptr = in;
 | 
						char *in_ptr = in;
 | 
				
			||||||
	if (in_len == (size_t) -1)
 | 
						if (in_len == (size_t) -1)
 | 
				
			||||||
 | 
							// XXX: out_len will be one character longer than the string!
 | 
				
			||||||
		in_len = strlen (in) + 1;
 | 
							in_len = strlen (in) + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (iconv (conv, (char **) &in_ptr, &in_len,
 | 
						while (iconv (conv, (char **) &in_ptr, &in_len,
 | 
				
			||||||
@@ -3255,16 +3285,8 @@ resolve_relative_data_filename (const char *filename)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *
 | 
					static char *
 | 
				
			||||||
resolve_relative_runtime_filename (const char *filename)
 | 
					resolve_relative_runtime_filename_finish (struct str path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct str path = str_make ();
 | 
					 | 
				
			||||||
	const char *runtime_dir = getenv ("XDG_RUNTIME_DIR");
 | 
					 | 
				
			||||||
	if (runtime_dir && *runtime_dir == '/')
 | 
					 | 
				
			||||||
		str_append (&path, runtime_dir);
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share");
 | 
					 | 
				
			||||||
	str_append_printf (&path, "/%s/%s", PROGRAM_NAME, filename);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Try to create the file's ancestors;
 | 
						// Try to create the file's ancestors;
 | 
				
			||||||
	// typically the user will want to immediately create a file in there
 | 
						// typically the user will want to immediately create a file in there
 | 
				
			||||||
	const char *last_slash = strrchr (path.str, '/');
 | 
						const char *last_slash = strrchr (path.str, '/');
 | 
				
			||||||
@@ -3277,6 +3299,41 @@ resolve_relative_runtime_filename (const char *filename)
 | 
				
			|||||||
	return str_steal (&path);
 | 
						return str_steal (&path);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static char *
 | 
				
			||||||
 | 
					resolve_relative_runtime_filename (const char *filename)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct str path = str_make ();
 | 
				
			||||||
 | 
						const char *runtime_dir = getenv ("XDG_RUNTIME_DIR");
 | 
				
			||||||
 | 
						if (runtime_dir && *runtime_dir == '/')
 | 
				
			||||||
 | 
							str_append (&path, runtime_dir);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							get_xdg_home_dir (&path, "XDG_DATA_HOME", ".local/share");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						str_append_printf (&path, "/%s/%s", PROGRAM_NAME, filename);
 | 
				
			||||||
 | 
						return resolve_relative_runtime_filename_finish (path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// This differs from resolve_relative_runtime_filename() in that we expect
 | 
				
			||||||
 | 
					/// the filename to be something like a pattern for mkstemp(), so the resulting
 | 
				
			||||||
 | 
					/// path can reside in a system-wide directory with no risk of a conflict.
 | 
				
			||||||
 | 
					/// However, we have to take care about permissions.  Do we even need this?
 | 
				
			||||||
 | 
					static char *
 | 
				
			||||||
 | 
					resolve_relative_runtime_template (const char *template)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct str path = str_make ();
 | 
				
			||||||
 | 
						const char *runtime_dir = getenv ("XDG_RUNTIME_DIR");
 | 
				
			||||||
 | 
						const char *tmpdir = getenv ("TMPDIR");
 | 
				
			||||||
 | 
						if (runtime_dir && *runtime_dir == '/')
 | 
				
			||||||
 | 
							str_append_printf (&path, "%s/%s", runtime_dir, PROGRAM_NAME);
 | 
				
			||||||
 | 
						else if (tmpdir && *tmpdir == '/')
 | 
				
			||||||
 | 
							str_append_printf (&path, "%s/%s.%d", tmpdir, PROGRAM_NAME, geteuid ());
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							str_append_printf (&path, "/tmp/%s.%d", PROGRAM_NAME, geteuid ());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						str_append_printf (&path, "/%s", template);
 | 
				
			||||||
 | 
						return resolve_relative_runtime_filename_finish (path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static char *
 | 
					static char *
 | 
				
			||||||
try_expand_tilde (const char *filename)
 | 
					try_expand_tilde (const char *filename)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user