Glib Helper Routines

Glib Helper Routines — Miscellaneous helper routines that could conceivably be moved to glib someday.

Synopsis




void        gsk_g_ptr_array_foreach         (GPtrArray *array,
                                             GFunc func,
                                             gpointer data);
gpointer    gsk_g_tree_min                  (GTree *tree);
gpointer    gsk_g_tree_max                  (GTree *tree);
GSList*     gsk_g_tree_key_slist            (GTree *tree);
GSList*     gsk_g_tree_value_slist          (GTree *tree);
GSList*     gsk_g_hash_table_key_slist      (GHashTable *table);
GSList*     gsk_g_hash_table_value_slist    (GHashTable *table);
gint64      gsk_strtoll                     (const char *str,
                                             char **endp,
                                             int base);
guint64     gsk_strtoull                    (const char *str,
                                             char **endp,
                                             int base);
guint       gsk_strnlen                     (const char *ptr,
                                             guint max_len);
gboolean    gsk_fd_set_nonblocking          (int fd);

Description

Provide various simple functions that we have found useful.

Details

gsk_g_ptr_array_foreach ()

void        gsk_g_ptr_array_foreach         (GPtrArray *array,
                                             GFunc func,
                                             gpointer data);

Like g_slist_foreach(), except it iterates over a GPtrArray instead.

array : array to iterate over.
func : function to call on each element of array.
data : second parameter to func.

gsk_g_tree_min ()

gpointer    gsk_g_tree_min                  (GTree *tree);

Find the minimum key in the tree.

tree : tree to examine.
Returns : smallest key in the tree.

gsk_g_tree_max ()

gpointer    gsk_g_tree_max                  (GTree *tree);

Find the maximum key in the tree.

tree : tree to examine.
Returns : largest key in the tree.

gsk_g_tree_key_slist ()

GSList*     gsk_g_tree_key_slist            (GTree *tree);

Get a list of all the keys in the trees, sorted.

tree : the tree to scan.
Returns : the newly allocated list of pointers to the keys.

gsk_g_tree_value_slist ()

GSList*     gsk_g_tree_value_slist          (GTree *tree);

Get a list of all the values in the trees, sorted by key.

tree : the tree to scan.
Returns : the newly allocated list of pointers to the keys.

gsk_g_hash_table_key_slist ()

GSList*     gsk_g_hash_table_key_slist      (GHashTable *table);

Accumulate all the keys in the hash table into a big list. You may not assume anything about the order of the list.

table : the hash table to scan.
Returns : an allocated GSList of all the keys in the hash-table.

gsk_g_hash_table_value_slist ()

GSList*     gsk_g_hash_table_value_slist    (GHashTable *table);

Accumulate all the values in the hash table into a big list. You may not assume anything about the order of the list.

table : the hash table to scan.
Returns : an allocated GSList of all the values in the hash-table.

gsk_strtoll ()

gint64      gsk_strtoll                     (const char *str,
                                             char **endp,
                                             int base);

Like strtol, but for 64-bit integers.

str : the string to parse a longlong integer (gint64) from.
endp : optional place to store the character right past the number in str. If *endp == str, then you may assume an error occurred.
base : the assumed base for the number to parse. eg "2" to parse a binary, "8" for octal, "10" for decimal, "16" for hexidecimal. Also, "0" is autodetects the C-style base.
Returns : the parsed integer.

gsk_strtoull ()

guint64     gsk_strtoull                    (const char *str,
                                             char **endp,
                                             int base);

Like strtol, but for 64-bit unsigned integers.

str : the string to parse a longlong unsigned integer (guint64) from.
endp : optional place to store the character right past the number in str. If *endp == str, then you may assume an error occurred.
base : the assumed base for the number to parse. eg "2" to parse a binary, "8" for octal, "10" for decimal, "16" for hexidecimal. Also, "0" is autodetects the C-style base.
Returns : the parsed unsigned integer.

gsk_strnlen ()

guint       gsk_strnlen                     (const char *ptr,
                                             guint max_len);

Find the length of a string, which is only allocated max_len bytes, and does not need to be NUL-terminated.

ptr : the string to find the length of.
max_len : the maximum length the string could be.
Returns : the length.

gsk_fd_set_nonblocking ()

gboolean    gsk_fd_set_nonblocking          (int fd);

Make a file-descriptor non-blocking. When it is non-blocking, operations that would cause it to block should instead return EAGAIN. (Although you should use gsk_errno_is_ignorable() to test, since windoze uses a different code, EWOULDBLOCK, and you should always ignore EINTR.)

fd : the file-descriptor to make non-blocking.
Returns : whether it was able to set the file descriptor non-blocking.