## gskutils

gskutils

## Synopsis

    gboolean            gsk_mkdir_p                         (const char *dir,
                                                             guint permissions,
                                                             GError **error);
    gboolean            gsk_rm_rf                           (const char *dir_or_file,
                                                             GError **error);
    char *              gsk_escape_memory                   (gconstpointer data,
                                                             guint len);
    gpointer            gsk_unescape_memory                 (const char *quoted,
                                                             gboolean has_quote_marks,
                                                             const char **end,
                                                             guint *length_out,
                                                             GError **error);
    char *              gsk_escape_memory_hex               (gconstpointer data,
                                                             guint len);
    guint8 *            gsk_unescape_memory_hex             (const char *str,
                                                             gssize len,
                                                             gsize *length_out,
                                                             GError **error);
    void                gsk_fd_set_close_on_exec            (int fd,
                                                             gboolean close_on_exec);
    gboolean            gsk_fd_clear_nonblocking            (int fd);
    gboolean            gsk_fd_is_nonblocking               (int fd);
    gssize              gsk_readn                           (guint fd,
                                                             void *buf,
                                                             gsize len);
    gssize              gsk_writen                          (guint fd,
                                                             const void *buf,
                                                             gsize len);

## Description

## Details

### gsk_mkdir_p ()

    gboolean            gsk_mkdir_p                         (const char *dir,
                                                             guint permissions,
                                                             GError **error);

Make a directory and any nonexistant parent directories.

This parallels the unix command 'mkdir -p DIR'.

`dir` : | the directory to make.
`permissions` : | file creation mode for the directory and its subdirectories.
`error` : | where to put an error, if one occurs.
Returns : | whether the directory now exists. Note that this function returns TRUE if the directory existed on startup.

### gsk_rm_rf ()

    gboolean            gsk_rm_rf                           (const char *dir_or_file,
                                                             GError **error);

Recursively remove a directory or file, similar to 'rm -rf DIR_OR_FILE' on the unix command-line.

`dir_or_file` : | the directory or file to delete.
`error` : | optional error return location.
Returns : | whether the removal was successful. This routine fails if there is a permission or i/o problem. (It returns TRUE if the file does not exist.) If it fails, and error is non-NULL, *error will hold a GError object.

### gsk_escape_memory ()

    char *              gsk_escape_memory                   (gconstpointer data,
                                                             guint len);

Convert a bunch of memory to something suitable for addition into a C string.

`data` : | raw data to C-escape.
`len` : | length of raw data in bytes
Returns : | a newly allocated string of escaped data.

### gsk_unescape_memory ()

    gpointer            gsk_unescape_memory                 (const char *quoted,
                                                             gboolean has_quote_marks,
                                                             const char **end,
                                                             guint *length_out,
                                                             GError **error);

Take a C double-quoted string and make it into a suitable for addition into a C string.

`quoted` : | C-string to unquote.
`has_quote_marks` : | whether to strip off double-quotes.
`end` : | where to store the end of the quoted string (right past the last double-quote.
`length_out` : | where to store the length of the unquoted memory.
`error` : | optional error return location.
Returns : | a newly allocated string of raw data, which an extra NUL postpended, so that it can be used as a string.

### gsk_escape_memory_hex ()

    char *              gsk_escape_memory_hex               (gconstpointer data,
                                                             guint len);

Convert a bunch of memory to its hex dump.

`data` : | raw data to dump as hex
`len` : | length of raw data in bytes
Returns : | a newly allocated string of hex digits.

### gsk_unescape_memory_hex ()

    guint8 *            gsk_unescape_memory_hex             (const char *str,
                                                             gssize len,
                                                             gsize *length_out,
                                                             GError **error);

Converts an even-number of hex digits into a binary set of bytes, and returns the bytes. Even if the data is length 0, you must free the return value.

If NULL is returned, it means an error occurred.

`str` : | the memory dump as a string.
`len` : | the maximum length of the string, or -1 to use NUL-termination.
`length_out` : | length of the returned memory.
`error` : | where to put an error, if one occurs.
Returns : | the binary data.

### gsk_fd_set_close_on_exec ()

    void                gsk_fd_set_close_on_exec            (int fd,
                                                             gboolean close_on_exec);

This function sets the value of the close-on-exec flag for a file-descriprtor.

Most files will be closed on the exec system call, but normally 0,1,2 (standard input, output and error) are set not to close-on-exec, which is why they are always inherited.

`fd` : | the file-descriptor to affect.
`close_on_exec` : | whether the close the file-descriptor on exec(2).

### gsk_fd_clear_nonblocking ()

    gboolean            gsk_fd_clear_nonblocking            (int fd);

`fd` : |
Returns : |

### gsk_fd_is_nonblocking ()

    gboolean            gsk_fd_is_nonblocking               (int fd);

`fd` : |
Returns : |

### gsk_readn ()

    gssize              gsk_readn                           (guint fd,
                                                             void *buf,
                                                             gsize len);

Read data from fd, retrying the read if not enough data is found. This is only for blocking reads.

`fd` : | the file-descriptor to read from.
`buf` : | the buffer to fill.
`len` : | number of bytes to read from fd.
Returns : | the number of bytes read or -1 if an error occurs.

### gsk_writen ()

    gssize              gsk_writen                          (guint fd,
                                                             const void *buf,
                                                             gsize len);

Write data to fd, retrying the write if not enough data is sent. This is only for blocking writes.

`fd` : | the file-descriptor to write to.
`buf` : | the buffer to read from.
`len` : | number of bytes to write to fd.
Returns : | the number of bytes written or -1 if an error occurs.