A dynamic string data structure helper implementation.

October 21, 2014 Leave a comment

In this article I will present to you a dynamic string data structure helper implementation. In C, a string is just an array of characters terminated with the null character (NUL in ASCII). Also, some times we handle a string by using a pointer to a buffer containing sequential characters terminated also with the null character. The C standard liibrary provides various functions for string manipulation but it seems that whenever we want to extend a string by using pointers we have to perform all the time memory reallocation which leads to a bad evolution of replicated code. In a recent project, I needed to create a string and append to it any number of new strings in order to extend it without using strcat, strcpy, strlen and realloc functions all the time. So, I created a simple dynamic string data structure which solved my specific problem and I would like to share it with you people.

Read more…

A useful function for getting the host name and service of a socket.

October 20, 2014 Leave a comment

In this article I will present to you a useful function for getting the host name and service of a socket.

Read more…

Helper functions for handling the PID file of a background daemon.

October 19, 2014 Leave a comment

In this article I will present to you some useful functions for handling the PID file of a background daemon. Most of the background daemons maintain a PID file usually in a well-known path such as the “/var/run”. For example, the GNOME Display Manager which runs as a background daemon (gdm3) maintains the following file “/var/run/gdm3.pid”. A PID file contains the PID number of the daemon process currently running. This information is useful either for validation or for sending various signals to the daemon process. Also, if a background daemon must have a single running instance this can be accomplished by checking if the PID number of the PID file really exists in the system.

Read more…

Useful functions for enabling and disabling the non-blocking I/O mode of file descriptors.

October 18, 2014 Leave a comment

In this article I will present to you two useful functions that can be used whenever you want to enable or disable the non-blocking I/O mode of a file descriptor. By using the enable_io_blocking_for_file_descriptor and disable_io_blocking_for_file_descriptor functions you can enable and disable the I/O blocking of a file descriptor.

Read more…

A safe wrapper implemented in C for freeing dynamic allocated memory.

October 18, 2014 Leave a comment

In this article I will present to you a safe wrapper for freeing memory allocated with *alloc family functions. The standard function “void free (void * pointer)” from stdlib library does not check the given pointer to see whether it is NULL and does not NULL terminate the pointer before it returns either. So, setting a pointer to NULL after freeing is considered a good practice, and can reduce the chances of unpredictable¬†behavior if the memory is later accessed; segmentation faults when the memory is no longer accessible and potential security risks.

Read more…

Macro definitions for handling interruptible POSIX system calls.

October 16, 2014 Leave a comment

In this article I will present to you some macro definitions for handling interruptible system calls.

Read more…

Implementation of functions in C for software signal management in POSIX operating systems – Version 2.

October 14, 2014 Leave a comment

In this article I will present to you a mechanism written in C for handling efficiently software signals in POSIX operating systems. The first thing you have to do is to create the configuration of the signals you want to support. After you decide the appropriate configuration you have to setup the signals support and register the configuration. Later on, when the various software signals occur a generic signal dispatcher will handle the signals according to the specified configuration.

Read more…

Follow

Get every new post delivered to your Inbox.

Join 25 other followers