Utilities and error handling functions
gchar *g_strdup( const gchar *str ); |
Replace the strdup function. Copy the original string content to the new storage block and return a pointer to it.
gchar *g_strerror( gint errnum ); |
I recommend using this function to handle all error messages. It is better and more portable than perror () and other similar functions. The output of this function is usually in the following format:
program name:function that failed:file or further description:strerror |
Here is an example of calling this function in our hello_world program:
g_print("hello_world:open:%s:%s/n", filename, g_strerror(errno)); |
void g_error( gchar *format, ... ); |
Print the error message. The format is the same as that of printf, but "** error **" is added before the error message and the program is exited. It is used only for fatal errors.
void g_warning( gchar *format, ... ); |
Similar to the previous function, the error message is "** warning **" and does not exit the program.
void g_message( gchar *format, ... ); |
Print "message:" Before the passed string :"
void g_print( gchar *format, ... ); |
Replace the printf () function.
The last function in this chapter:
gchar *g_strsignal( gint signum ); |
Print the corresponding signal name for the given signal number. It is useful in common signal processing functions.
All of the above function bodies are more or less obtained from glib. H. If anyone is interested in the documentation of a function, just send me an email.
<Previous |
Home |
Next >>> |
String processing |
Up |
RC file of GTK |