From: P. F. Chimento Date: Sat, 18 Jun 2011 19:18:46 +0000 (+0200) Subject: Avoid const string allocation/free X-Git-Tag: v0.9~73^2~1^2~3 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;ds=sidebyside;h=23e5517a7005693faf3a6789309f41f61d945fed;p=projects%2Fchimara%2Fchimara.git Avoid const string allocation/free --- diff --git a/libchimara/stream.c b/libchimara/stream.c index b9d56cd..0113b98 100644 --- a/libchimara/stream.c +++ b/libchimara/stream.c @@ -342,7 +342,7 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode) { VALID_FILEREF(fileref, return NULL); - gchar *modestr; + const gchar *modestr; /* Binary mode is 0x000, text mode 0x100 */ gboolean binary = !(fileref->usage & fileusage_TextMode); switch(fmode) @@ -352,10 +352,10 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode) ILLEGAL_PARAM("Tried to open a nonexistent file, '%s', in read mode", fileref->filename); return NULL; } - modestr = g_strdup(binary? "rb" : "r"); + modestr = binary? "rb" : "r"; break; case filemode_Write: - modestr = g_strdup(binary? "wb" : "w"); + modestr = binary? "wb" : "w"; break; case filemode_WriteAppend: case filemode_ReadWrite: @@ -367,7 +367,7 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode) IO_WARNING( "Error opening file", fileref->filename, g_strerror(errno) ); return NULL; } - modestr = g_strdup(binary? "r+b" : "r+"); + modestr = binary? "r+b" : "r+"; } break; default: @@ -376,7 +376,6 @@ file_stream_new(frefid_t fileref, glui32 fmode, glui32 rock, gboolean unicode) } FILE *fp = g_fopen(fileref->filename, modestr); - g_free(modestr); if(fp == NULL) { IO_WARNING( "Error opening file", fileref->filename, g_strerror(errno) ); return NULL;