summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQball Cow <qball@gmpclient.org>2014-05-19 17:54:53 +0200
committerQball Cow <qball@gmpclient.org>2014-05-19 17:54:53 +0200
commitb360cdd13c20fe4725acf1bc67d98ee0b59155ec (patch)
treeacf3af20f04121f76e43af042ec119604f23dc12 /source
parentcb15a57fb701b3a882d1c7d5974f198e2a302d24 (diff)
Change malloc+sprintf to asprintf
Diffstat (limited to 'source')
-rw-r--r--source/xrmoptions.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 148434ae..49f61855 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -24,6 +24,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,6 +51,10 @@ typedef struct
char ** str;
};
} XrmOption;
+/**
+ * Map X resource settings to internal options
+ * Currently supports string and number.
+ */
static XrmOption xrmOptions[] = {
{ xrm_Number, "opacity", { .num = &config.window_opacity } },
{ xrm_Number, "width", { .num = &config.menu_width } },
@@ -74,29 +79,28 @@ static XrmOption xrmOptions[] = {
void parse_xresource_options ( Display *display )
{
char *xRMS;
- // Map Xresource entries to simpleswitcher config options.
+ // Map Xresource entries to rofi config options.
XrmInitialize ();
xRMS = XResourceManagerString ( display );
- if ( xRMS != NULL )
+ if ( xRMS == NULL )
{
- XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
+ return;
+ }
+ XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
- char * xrmType;
- XrmValue xrmValue;
- // TODO: update when we have new name.
- const char * namePrefix = "rofi";
- const char * classPrefix = "Simpleswitcher";
+ char * xrmType;
+ XrmValue xrmValue;
+ // TODO: update when we have new name.
+ const char * namePrefix = "rofi";
+ const char * classPrefix = "Simpleswitcher";
- for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); ++i )
+ for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); ++i )
+ {
+ char *name, *class;
+ if ( asprintf ( &name, "%s.%s", namePrefix, xrmOptions[i].name ) == -1) continue;
+ if ( asprintf ( &class, "%s.%s", classPrefix, xrmOptions[i].name ) > 0)
{
- char *name = ( char * ) malloc ( ( strlen ( namePrefix ) + 1 + strlen ( xrmOptions[i].name ) ) *
- sizeof ( char ) + 1 );
- char *class = ( char * ) malloc ( ( strlen ( classPrefix ) + 1 + strlen ( xrmOptions[i].name ) ) *
- sizeof ( char ) + 1 );
- sprintf ( name, "%s.%s", namePrefix, xrmOptions[i].name );
- sprintf ( class, "%s.%s", classPrefix, xrmOptions[i].name );
-
if ( XrmGetResource ( xDB, name, class, &xrmType, &xrmValue ) )
{
if ( xrmOptions[i].type == xrm_String )
@@ -110,8 +114,8 @@ void parse_xresource_options ( Display *display )
}
}
- free ( name );
free ( class );
}
+ free ( name );
}
}