src/util.c File Reference

#include <sys/wait.h>
#include <stdarg.h>
#include <iconv.h>
#include <fcntl.h>
#include <pwd.h>
#include <yajl/yajl_version.h>
#include <libgen.h>
#include "all.h"
Include dependency graph for util.c:

Go to the source code of this file.

Defines

#define y(x,...)   yajl_gen_ ## x (gen, ##__VA_ARGS__)
#define ystr(str)   yajl_gen_string(gen, (unsigned char*)str, strlen(str))

Functions

int min (int a, int b)
int max (int a, int b)
bool rect_contains (Rect rect, uint32_t x, uint32_t y)
Rect rect_add (Rect a, Rect b)
bool update_if_necessary (uint32_t *destination, const uint32_t new_value)
 Updates *destination with new_value and returns true if it was changed or false if it was the same.
void * smalloc (size_t size)
 Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory available).
void * scalloc (size_t size)
 Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory available).
void * srealloc (void *ptr, size_t size)
 Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory available).
char * sstrdup (const char *str)
 Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory available).
void start_application (const char *command)
 Starts the given application by passing it through a shell.
void exec_i3_utility (char *name, char *argv[])
 exec()s an i3 utility, for example the config file migration script or i3-nagbar.
void check_error (xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message)
 Checks a generic cookie for errors and quits with the given message if there was an error.
char * convert_utf8_to_ucs2 (char *input, int *real_strlen)
 Converts the given string to UCS-2 big endian for use with xcb_image_text_16().
char * resolve_tilde (const char *path)
 This function resolves ~ in pathnames.
bool path_exists (const char *path)
 Checks if the given path exists by calling stat().
static char ** append_argument (char **original, char *argument)
char * get_process_filename (const char *prefix)
 Returns the name of a temporary file with the specified prefix.
char * store_restart_layout ()
void i3_restart (bool forget_layout)
 Restart i3 in-place appends -a to argument list to disable autostart.

Variables

static iconv_t conversion_descriptor = 0

Define Documentation

#define y ( x,
...   )     yajl_gen_ ## x (gen, ##__VA_ARGS__)

Definition at line 328 of file util.c.

#define ystr ( str   )     yajl_gen_string(gen, (unsigned char*)str, strlen(str))

Definition at line 329 of file util.c.


Function Documentation

static char** append_argument ( char **  original,
char *  argument 
) [static]

Definition at line 274 of file util.c.

References DLOG, and smalloc().

Referenced by i3_restart().

Here is the call graph for this function:

void check_error ( xcb_connection_t *  conn,
xcb_void_cookie_t  cookie,
char *  err_message 
)

Checks a generic cookie for errors and quits with the given message if there was an error.

Definition at line 174 of file util.c.

Referenced by main(), and TAILQ_HEAD().

char* convert_utf8_to_ucs2 ( char *  input,
int *  real_strlen 
)

Converts the given string to UCS-2 big endian for use with xcb_image_text_16().

The amount of real glyphs is stored in real_strlen, a buffer containing the UCS-2 encoded string (16 bit per glyph) is returned. It has to be freed when done.

Definition at line 190 of file util.c.

References conversion_descriptor, and smalloc().

Referenced by handle_signal(), sig_draw_window(), and window_update_name().

Here is the call graph for this function:

void exec_i3_utility ( char *  name,
char *  argv[] 
)

exec()s an i3 utility, for example the config file migration script or i3-nagbar.

This function first searches $PATH for the given utility named, then falls back to the dirname() of the i3 executable path and then falls back to the dirname() of the target of /proc/self/exe (on linux).

This function should be called after fork()ing.

The first argument of the given argv vector will be overwritten with the executable name, so pass NULL.

If the utility cannot be found in any of these locations, it exits with return code 2.

Definition at line 137 of file util.c.

References start_argv.

Referenced by migrate_config(), and start_configerror_nagbar().

char* get_process_filename ( const char *  prefix  ) 

Returns the name of a temporary file with the specified prefix.

Definition at line 295 of file util.c.

References path_exists().

Referenced by init_logging(), main(), and store_restart_layout().

Here is the call graph for this function:

void i3_restart ( bool  forget_layout  ) 

Restart i3 in-place appends -a to argument list to disable autostart.

Definition at line 406 of file util.c.

References append_argument(), ipc_shutdown(), kill_configerror_nagbar(), LOG, restore_geometry(), scalloc(), start_argv, and store_restart_layout().

Referenced by sig_handle_key_press(), and yyparse().

Here is the call graph for this function:

int max ( int  a,
int  b 
)

Definition at line 32 of file util.c.

Referenced by con_minimum_size(), DRAGGING_CB(), and floating_enable().

int min ( int  a,
int  b 
)

Definition at line 28 of file util.c.

Referenced by con_minimum_size(), query_screens(), and randr_query_outputs().

bool path_exists ( const char *  path  ) 

Checks if the given path exists by calling stat().

Definition at line 263 of file util.c.

Referenced by get_config_path(), get_process_filename(), ipc_create_socket(), and tree_restore().

Rect rect_add ( Rect  a,
Rect  b 
)

Definition at line 43 of file util.c.

References Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by render_con().

bool rect_contains ( Rect  rect,
uint32_t  x,
uint32_t  y 
)

Definition at line 36 of file util.c.

References Rect::height, Rect::width, Rect::x, and Rect::y.

Referenced by handle_button_press(), handle_enter_notify(), and handle_motion_notify().

char* resolve_tilde ( const char *  path  ) 

This function resolves ~ in pathnames.

It may resolve wildcards in the first part of the path, but if no match or multiple matches are found, it just returns a copy of path as given.

Definition at line 233 of file util.c.

References die, scalloc(), and sstrdup().

Referenced by get_config_path(), ipc_create_socket(), store_restart_layout(), and tree_restore().

Here is the call graph for this function:

void* scalloc ( size_t  size  ) 
void* smalloc ( size_t  size  ) 

Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory available).

Definition at line 66 of file util.c.

References exit_if_null.

Referenced by append_argument(), con_get_fullscreen_con(), convert_utf8_to_ucs2(), ewmh_update_workarea(), json_start_map(), manage_existing_windows(), parse_file(), SLIST_HEAD(), start_configerror_nagbar(), translate_keysyms(), and yyparse().

void* srealloc ( void *  ptr,
size_t  size 
)

Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory available).

Definition at line 78 of file util.c.

References exit_if_null.

Referenced by run_assignments().

char* sstrdup ( const char *  str  ) 

Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory available).

Definition at line 84 of file util.c.

References exit_if_null.

Referenced by get_config_path(), ipc_create_socket(), load_configuration(), main(), output_init_con(), parse_file(), resolve_tilde(), TAILQ_HEAD(), window_update_class(), window_update_name_legacy(), workspace_get(), x_set_name(), and yyparse().

void start_application ( const char *  command  ) 

Starts the given application by passing it through a shell.

We use double fork to avoid zombie processes. As the started application’s parent exits (immediately), the application is reparented to init (process-id 1), which correctly handles childs, so we don’t have to do it :-).

The shell is determined by looking for the SHELL environment variable. If it does not exist, /bin/sh is used.

Definition at line 100 of file util.c.

References LOG.

Referenced by main(), and yyparse().

char* store_restart_layout (  ) 

Definition at line 331 of file util.c.

References config, croot, dump_node(), get_process_filename(), resolve_tilde(), Config::restart_state_path, and y.

Referenced by i3_restart().

Here is the call graph for this function:

bool update_if_necessary ( uint32_t *  destination,
const uint32_t  new_value 
)

Updates *destination with new_value and returns true if it was changed or false if it was the same.

Definition at line 55 of file util.c.

Referenced by handle_output(), and randr_query_outputs().


Variable Documentation

iconv_t conversion_descriptor = 0 [static]

Definition at line 26 of file util.c.

Referenced by convert_utf8_to_ucs2().


Generated on 7 Feb 2013 for i3 by  doxygen 1.6.1