Merge branch master in bacardi55

This commit is contained in:
Raphael Khaiat 2010-11-19 23:41:56 +01:00
parent f928497e70
commit bc31510d64
27 changed files with 266 additions and 188 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ wmfs
#* #*
\#* \#*
Makefile Makefile
wmfs.1.gz
tags
*.patch

View File

@ -19,8 +19,8 @@ src/launcher.c \
src/layout.c \ src/layout.c \
src/menu.c \ src/menu.c \
src/mouse.c \ src/mouse.c \
src/parse/api.c \ src/parse_api.c \
src/parse/parse.c \ src/parse.c \
src/screen.c \ src/screen.c \
src/status.c \ src/status.c \
src/systray.c \ src/systray.c \
@ -38,7 +38,7 @@ OBJS= ${SRCS:.c=.o}
all: ${PROG} ${MAN}.gz all: ${PROG} ${MAN}.gz
${PROG}: ${OBJS} src/structs.h src/wmfs.h src/parse/parse.h ${PROG}: ${OBJS} src/structs.h src/wmfs.h src/parse.h
${CC} -o $@ ${OBJS} ${LDFLAGS} ${CC} -o $@ ${OBJS} ${LDFLAGS}
${MAN}.gz: ${MAN} ${MAN}.gz: ${MAN}
@ -60,9 +60,9 @@ install: all
@echo installing xsession file to ${DESTDIR}${PREFIX}/share/xsessions @echo installing xsession file to ${DESTDIR}${PREFIX}/share/xsessions
mkdir -p ${DESTDIR}${PREFIX}/share/xsessions mkdir -p ${DESTDIR}${PREFIX}/share/xsessions
install -m 644 wmfs.desktop ${DESTDIR}${PREFIX}/share/xsessions/ install -m 644 wmfs.desktop ${DESTDIR}${PREFIX}/share/xsessions/
@echo installing default config file to ${DESTDIR}${XDG_CONFIG_DIR} @echo installing default config file to ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/
mkdir -p ${DESTDIR}${XDG_CONFIG_DIR} mkdir -p ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/
install -m 444 wmfsrc ${DESTDIR}${XDG_CONFIG_DIR} install -m 444 wmfsrc ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/
uninstall: uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin @echo removing executable file from ${DESTDIR}${PREFIX}/bin
@ -71,8 +71,9 @@ uninstall:
rm -f ${DESTDIR}${MANPREFIX}/man1/wmfs.1.gz rm -f ${DESTDIR}${MANPREFIX}/man1/wmfs.1.gz
@echo removing xsession file from ${DESTDIR}${PREFIX}/share/xsessions @echo removing xsession file from ${DESTDIR}${PREFIX}/share/xsessions
rm -f ${DESTDIR}${PREFIX}/share/xsessions/wmfs.desktop rm -f ${DESTDIR}${PREFIX}/share/xsessions/wmfs.desktop
@echo removing config file from ${DESTDIR}${XDG_CONFIG_DIR} @echo removing config file from ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/
rm -f ${DESTDIR}${XDG_CONFIG_DIR}/wmfsrc rm -f ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/wmfsrc
rmdir ${DESTDIR}${XDG_CONFIG_DIR}/wmfs/

2
configure vendored
View File

@ -7,7 +7,7 @@ USE_IMLIB2="imlib2"
OS=`uname -s` OS=`uname -s`
PREFIX=/usr/local PREFIX=/usr/local
MANPREFIX="$PREFIX/man" MANPREFIX="$PREFIX/man"
XDG_CONFIG_DIR="$PREFIX/etc/xdg/wmfs" XDG_CONFIG_DIR="$PREFIX/etc/xdg"
while true; do while true; do
case "$1" in case "$1" in

View File

@ -58,7 +58,7 @@ barwin_create(Window parent,
BarWindow *bw; BarWindow *bw;
/* Allocate memory */ /* Allocate memory */
bw = emalloc(1, sizeof(BarWindow)); bw = zcalloc(sizeof(*bw));
/* Barwin attributes */ /* Barwin attributes */
at.override_redirect = True; at.override_redirect = True;
@ -116,7 +116,7 @@ barwin_draw_text(BarWindow *bw, int x, int y, char *text)
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg); draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */ /* Draw text */
draw_text(bw->dr, x, y, bw->fg, 0, text); draw_text(bw->dr, x, y, bw->fg, text);
barwin_refresh(bw); barwin_refresh(bw);
@ -136,7 +136,7 @@ barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_imag
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg); draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */ /* Draw text */
draw_image_ofset_text(bw->dr, x, y, bw->fg, 0, text, x_image_ofset, y_image_ofset); draw_image_ofset_text(bw->dr, x, y, bw->fg, text, x_image_ofset, y_image_ofset);
barwin_refresh(bw); barwin_refresh(bw);

View File

@ -536,7 +536,7 @@ client_get_name(Client *c)
XFetchName(dpy, c->win, &(c->title)); XFetchName(dpy, c->win, &(c->title));
if(!c->title) if(!c->title)
c->title = _strdup("WMFS"); c->title = xstrdup("WMFS");
} }
frame_update(c); frame_update(c);
@ -676,7 +676,7 @@ client_manage(Window w, XWindowAttributes *wa, Bool ar)
screen_get_sel(); screen_get_sel();
c = emalloc(1, sizeof(Client)); c = zmalloc(sizeof(Client));
c->win = w; c->win = w;
c->screen = selscreen; c->screen = selscreen;
c->flags = 0; c->flags = 0;
@ -1023,7 +1023,7 @@ client_set_rules(Client *c)
if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False, if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False,
XA_STRING, &rf, &f, &n, &il, &data) == Success && data) XA_STRING, &rf, &f, &n, &il, &data) == Success && data)
{ {
strcpy(wwrole, (char*)data); strncpy(wwrole, (char*)data, sizeof(wwrole));
XFree(data); XFree(data);
} }

View File

@ -95,7 +95,8 @@ const func_name_list_t func_list[] =
{"check_layout", uicb_checklayout }, {"check_layout", uicb_checklayout },
{"clientlist", uicb_clientlist }, {"clientlist", uicb_clientlist },
{"check_clist", uicb_checkclist }, {"check_clist", uicb_checkclist },
{"toggle_tagautohide", uicb_toggle_tagautohide } {"toggle_tagautohide", uicb_toggle_tagautohide },
{NULL, NULL}
}; };
key_name_list_t key_list[] = key_name_list_t key_list[] =
@ -197,7 +198,7 @@ conf_bar_section(void)
if ((conf.bars.nmouse = fetch_section_count(mouse)) > 0) if ((conf.bars.nmouse = fetch_section_count(mouse)) > 0)
{ {
conf.bars.mouse = emalloc(conf.bars.nmouse, sizeof(MouseBinding)); conf.bars.mouse = xcalloc(conf.bars.nmouse, sizeof(MouseBinding));
mouse_section(conf.bars.mouse, mouse); mouse_section(conf.bars.mouse, mouse);
} }
@ -228,7 +229,7 @@ conf_bar_section(void)
if ((conf.selbar.nmouse = fetch_section_count(mouse))) if ((conf.selbar.nmouse = fetch_section_count(mouse)))
{ {
conf.selbar.mouse = emalloc(conf.selbar.nmouse, sizeof(MouseBinding)); conf.selbar.mouse = xcalloc(conf.selbar.nmouse, sizeof(MouseBinding));
mouse_section(conf.selbar.mouse, mouse); mouse_section(conf.selbar.mouse, mouse);
} }
@ -250,7 +251,7 @@ conf_root_section(void)
if ((conf.root.nmouse = fetch_section_count(mouse)) > 0) if ((conf.root.nmouse = fetch_section_count(mouse)) > 0)
{ {
conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding)); conf.root.mouse = xcalloc(conf.root.nmouse, sizeof(MouseBinding));
mouse_section(conf.root.mouse, mouse); mouse_section(conf.root.mouse, mouse);
} }
@ -290,7 +291,7 @@ conf_client_section(void)
if((conf.client.nmouse = fetch_section_count(mouse)) > 0) if((conf.client.nmouse = fetch_section_count(mouse)) > 0)
{ {
conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding)); conf.client.mouse = xcalloc(conf.client.nmouse, sizeof(MouseBinding));
mouse_section(conf.client.mouse, mouse); mouse_section(conf.client.mouse, mouse);
} }
@ -318,7 +319,7 @@ conf_client_section(void)
if((conf.titlebar.nmouse = fetch_section_count(mouse)) > 0) if((conf.titlebar.nmouse = fetch_section_count(mouse)) > 0)
{ {
conf.titlebar.mouse = emalloc(conf.titlebar.nmouse, sizeof(MouseBinding)); conf.titlebar.mouse = xcalloc(conf.titlebar.nmouse, sizeof(MouseBinding));
mouse_section(conf.titlebar.mouse, mouse); mouse_section(conf.titlebar.mouse, mouse);
} }
@ -329,7 +330,7 @@ conf_client_section(void)
if((conf.titlebar.nbutton = fetch_section_count(button)) > 0) if((conf.titlebar.nbutton = fetch_section_count(button)) > 0)
{ {
conf.titlebar.button = emalloc(conf.titlebar.nbutton, sizeof(Button)); conf.titlebar.button = xcalloc(conf.titlebar.nbutton, sizeof(Button));
for(i = 0; i < conf.titlebar.nbutton; ++i) for(i = 0; i < conf.titlebar.nbutton; ++i)
{ {
flags = fetch_opt_first(button[i], "none", "flags").str; flags = fetch_opt_first(button[i], "none", "flags").str;
@ -347,7 +348,7 @@ conf_client_section(void)
if((conf.titlebar.button[i].nmouse = fetch_section_count(mouse)) > 0) if((conf.titlebar.button[i].nmouse = fetch_section_count(mouse)) > 0)
{ {
conf.titlebar.button[i].mouse = emalloc(conf.titlebar.button[i].nmouse, sizeof(MouseBinding)); conf.titlebar.button[i].mouse = xcalloc(conf.titlebar.button[i].nmouse, sizeof(MouseBinding));
mouse_section(conf.titlebar.button[i].mouse, mouse); mouse_section(conf.titlebar.button[i].mouse, mouse);
} }
@ -358,7 +359,7 @@ conf_client_section(void)
if((conf.titlebar.button[i].nlines = fetch_section_count(line)) > 0) if((conf.titlebar.button[i].nlines = fetch_section_count(line)) > 0)
{ {
conf.titlebar.button[i].linecoord = emalloc(conf.titlebar.button[i].nlines, sizeof(XSegment)); conf.titlebar.button[i].linecoord = xcalloc(conf.titlebar.button[i].nlines, sizeof(XSegment));
for(j = 0; j < conf.titlebar.button[i].nlines; ++j) for(j = 0; j < conf.titlebar.button[i].nlines; ++j)
{ {
@ -415,7 +416,7 @@ conf_layout_section(void)
{ {
warnx("configuration : Too many or no layouts (%d).", conf.nlayout); warnx("configuration : Too many or no layouts (%d).", conf.nlayout);
conf.nlayout = 1; conf.nlayout = 1;
conf.layout[0].symbol = _strdup("TILE"); conf.layout[0].symbol = xstrdup("TILE");
conf.layout[0].func = tile; conf.layout[0].func = tile;
} }
@ -520,10 +521,10 @@ conf_tag_section(void)
sc = screen_count(); sc = screen_count();
/* Alloc all */ /* Alloc all */
conf.ntag = emalloc(sc, sizeof(int)); conf.ntag = xcalloc(sc, sizeof(*conf.ntag));
tags = emalloc(sc, sizeof(Tag*)); tags = xcalloc(sc, sizeof(*tags));
seltag = emalloc(sc, sizeof(int)); seltag = xcalloc(sc, sizeof(*seltag));
prevseltag = emalloc(sc, sizeof(int)); prevseltag = xcalloc(sc, sizeof(*prevseltag));
for(i = 0; i < sc; ++i) for(i = 0; i < sc; ++i)
seltag[i] = 1; seltag[i] = 1;
@ -533,7 +534,7 @@ conf_tag_section(void)
n = fetch_section_count(tag); n = fetch_section_count(tag);
for(i = 0; i < sc; ++i) for(i = 0; i < sc; ++i)
tags[i] = emalloc(n + 2, sizeof(Tag)); tags[i] = xcalloc(n + 2, sizeof(Tag));
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
{ {
@ -574,7 +575,7 @@ conf_tag_section(void)
if ((count = fetch_opt_count(opt))) if ((count = fetch_opt_count(opt)))
{ {
tags[k][conf.ntag[k]].nclients = count; tags[k][conf.ntag[k]].nclients = count;
tags[k][conf.ntag[k]].clients = emalloc(count, sizeof(char *)); tags[k][conf.ntag[k]].clients = xcalloc(count, sizeof(char *));
for(m = 0; m < count; ++m) for(m = 0; m < count; ++m)
tags[k][conf.ntag[k]].clients[m] = opt[m].str; tags[k][conf.ntag[k]].clients[m] = opt[m].str;
} }
@ -586,7 +587,7 @@ conf_tag_section(void)
if((tags[k][conf.ntag[k]].nmouse = fetch_section_count(mouse))) if((tags[k][conf.ntag[k]].nmouse = fetch_section_count(mouse)))
{ {
tags[k][conf.ntag[k]].mouse = emalloc(tags[k][conf.ntag[k]].nmouse, sizeof(MouseBinding)); tags[k][conf.ntag[k]].mouse = xcalloc(tags[k][conf.ntag[k]].nmouse, sizeof(MouseBinding));
mouse_section(tags[k][conf.ntag[k]].mouse, mouse); mouse_section(tags[k][conf.ntag[k]].mouse, mouse);
} }
@ -620,7 +621,7 @@ conf_rule_section(void)
CHECK((conf.nrule = fetch_section_count(rule))); CHECK((conf.nrule = fetch_section_count(rule)));
conf.rule = emalloc(conf.nrule, sizeof(Rule)); conf.rule = xcalloc(conf.nrule, sizeof(Rule));
for(i = 0; i < conf.nrule; ++i) for(i = 0; i < conf.nrule; ++i)
{ {
@ -651,7 +652,7 @@ conf_menu_section(void)
CHECK((conf.nmenu = fetch_section_count(set_menu))); CHECK((conf.nmenu = fetch_section_count(set_menu)));
conf.menu = emalloc(conf.nmenu, sizeof(Menu)); conf.menu = xcalloc(conf.nmenu, sizeof(Menu));
for(i = 0; i < conf.nmenu; ++i) for(i = 0; i < conf.nmenu; ++i)
{ {
@ -682,7 +683,7 @@ conf_menu_section(void)
if((conf.menu[i].nitem = fetch_section_count(item))) if((conf.menu[i].nitem = fetch_section_count(item)))
{ {
conf.menu[i].item = emalloc(conf.menu[i].nitem, sizeof(MenuItem)); conf.menu[i].item = xcalloc(conf.menu[i].nitem, sizeof(MenuItem));
for(j = 0; j < conf.menu[i].nitem; ++j) for(j = 0; j < conf.menu[i].nitem; ++j)
{ {
conf.menu[i].item[j].name = fetch_opt_first(item[j], "item_wname", "name").str; conf.menu[i].item[j].name = fetch_opt_first(item[j], "item_wname", "name").str;
@ -710,7 +711,7 @@ conf_launcher_section(void)
CHECK((conf.nlauncher = fetch_section_count(set_launcher))); CHECK((conf.nlauncher = fetch_section_count(set_launcher)));
conf.launcher = emalloc(conf.nlauncher, sizeof(Launcher)); conf.launcher = xcalloc(conf.nlauncher, sizeof(Launcher));
for(i = 0; i < conf.nlauncher; ++i) for(i = 0; i < conf.nlauncher; ++i)
{ {
@ -736,7 +737,7 @@ conf_keybind_section(void)
ks = fetch_section(sec, "key"); ks = fetch_section(sec, "key");
conf.nkeybind = fetch_section_count(ks); conf.nkeybind = fetch_section_count(ks);
keys = emalloc(conf.nkeybind, sizeof(Key)); keys = xcalloc(conf.nkeybind, sizeof(Key));
for(i = 0; i < conf.nkeybind; ++i) for(i = 0; i < conf.nkeybind; ++i)
{ {

View File

@ -33,9 +33,9 @@
#include "wmfs.h" #include "wmfs.h"
void void
draw_text(Drawable d, int x, int y, char* fg, int pad, char *str) draw_text(Drawable d, int x, int y, char* fg, char *str)
{ {
draw_image_ofset_text(d, x, y, fg, pad, str, 0, 0); draw_image_ofset_text(d, x, y, fg, str, 0, 0);
} }
/** Draw a string in a Drawable /** Draw a string in a Drawable
@ -47,22 +47,28 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
* \param str String that will be draw * \param str String that will be draw
*/ */
void void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset) draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
{ {
XftColor xftcolor; XftColor xftcolor;
XftDraw *xftd; XftDraw *xftd;
(void)pad; #ifdef HAVE_IMLIB
char *ostr = NULL;
int i, ni, sw = 0;
ImageAttr im[128];
size_t textlen;
#else
(void)x_image_ofset;
(void)y_image_ofset;
#endif /* HAVE_IMLIB */
if(!str) if(!str)
return; return;
/* To draw image everywhere we can draw text */ /* To draw image everywhere we can draw text */
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
char *ostr = NULL;
int i, ni, sw = 0;
ImageAttr im[128];
ostr = _strdup(str); ostr = xstrdup(str);
textlen = strlen(ostr);
if(strstr(str, "i[")) if(strstr(str, "i["))
{ {
@ -92,7 +98,7 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, in
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(strstr(ostr, "i["))
strcpy(str, ostr); strncpy(str, ostr, textlen);
IFREE(ostr); IFREE(ostr);
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */
@ -195,16 +201,20 @@ ushort
textw(char *text) textw(char *text)
{ {
XGlyphInfo gl; XGlyphInfo gl;
#ifdef HAVE_IMLIB
char *ostr = NULL;
ImageAttr im[128];
size_t textlen;
#endif /* HAVE_IMLIB */
if(!text) if(!text)
return 0; return 0;
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
char *ostr = NULL;
ImageAttr im[128]; ostr = xstrdup(text);
textlen = strlen(ostr);
ostr = _strdup(text);
if(strstr(text, "i[")) if(strstr(text, "i["))
parse_image_block(im, text); parse_image_block(im, text);
@ -214,7 +224,7 @@ textw(char *text)
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(strstr(ostr, "i["))
strcpy(text, ostr); strncpy(text, ostr, textlen);
IFREE(ostr); IFREE(ostr);
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */

View File

@ -370,7 +370,6 @@ void
enternotify(XCrossingEvent *ev) enternotify(XCrossingEvent *ev)
{ {
Client *c; Client *c;
Systray *s;
int n; int n;
if((ev->mode != NotifyNormal if((ev->mode != NotifyNormal
@ -379,7 +378,7 @@ enternotify(XCrossingEvent *ev)
return; return;
/* Don't handle EnterNotify event if it's about systray */ /* Don't handle EnterNotify event if it's about systray */
if((s = systray_find(ev->window)) || ev->window == traywin) if(systray_find(ev->window) || ev->window == traywin)
return; return;
if(conf.focus_fmouse) if(conf.focus_fmouse)
@ -525,7 +524,6 @@ void
maprequest(XMapRequestEvent *ev) maprequest(XMapRequestEvent *ev)
{ {
XWindowAttributes at; XWindowAttributes at;
Client *c;
Systray *s; Systray *s;
CHECK(XGetWindowAttributes(dpy, ev->window, &at)); CHECK(XGetWindowAttributes(dpy, ev->window, &at));
@ -536,7 +534,7 @@ maprequest(XMapRequestEvent *ev)
ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, 0, 0); ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, 0, 0);
systray_update(); systray_update();
} }
else if(!(c = client_gb_win(ev->window))) else if(!client_gb_win(ev->window))
client_manage(ev->window, &at, True); client_manage(ev->window, &at, True);
return; return;

View File

@ -50,7 +50,7 @@ ewmh_init_hints(void)
s = screen_count(); s = screen_count();
net_atom = emalloc(net_last + s, sizeof(Atom)); net_atom = xcalloc(net_last + s, sizeof(Atom));
/* EWMH hints */ /* EWMH hints */
net_atom[net_supported] = ATOM("_NET_SUPPORTED"); net_atom[net_supported] = ATOM("_NET_SUPPORTED");
@ -252,7 +252,7 @@ ewmh_get_client_list(void)
int win_n; int win_n;
for(win_n = 0, c = clients; c; c = c->next, ++win_n); for(win_n = 0, c = clients; c; c = c->next, ++win_n);
list = emalloc(win_n, sizeof(Window)); list = xcalloc(win_n, sizeof(Window));
for(win_n = 0, c = clients; c; c = c->next, ++win_n) for(win_n = 0, c = clients; c; c = c->next, ++win_n)
list[win_n] = c->win; list[win_n] = c->win;
@ -279,7 +279,7 @@ ewmh_get_desktop_names(void)
for(i = 1; i < conf.ntag[s] + 1; ++i) for(i = 1; i < conf.ntag[s] + 1; ++i)
len += strlen(tags[s][i].name); len += strlen(tags[s][i].name);
str = emalloc(len + i + 1, sizeof(char*)); str = xcalloc(len + i + 1, sizeof(char*));
for(s = 0; s < S; ++s) for(s = 0; s < S; ++s)
for(i = 1; i < conf.ntag[s] + 1; ++i, ++pos) for(i = 1; i < conf.ntag[s] + 1; ++i, ++pos)

View File

@ -83,7 +83,7 @@ frame_create(Client *c)
/* Buttons */ /* Buttons */
if(BUTTONWH >= 1) if(BUTTONWH >= 1)
{ {
c->button = emalloc(conf.titlebar.nbutton, sizeof(Window)); c->button = xcalloc(conf.titlebar.nbutton, sizeof(Window));
for(i = 0; i < conf.titlebar.nbutton; ++i) for(i = 0; i < conf.titlebar.nbutton; ++i)
{ {
CWIN(c->button[i], c->titlebar->win, CWIN(c->button[i], c->titlebar->win,

View File

@ -60,14 +60,14 @@ getinfo_tag(void)
if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_TAG"), 0L, 4096, if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_TAG"), 0L, 4096,
False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret) False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
{ {
tag_name = _strdup((char*)ret); tag_name = xstrdup((char*)ret);
XFree(ret); XFree(ret);
} }
if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_TAG_LIST"), 0L, 4096, if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_TAG_LIST"), 0L, 4096,
False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret) False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
{ {
tag_list = _strdup((char*)ret); tag_list = xstrdup((char*)ret);
XFree(ret); XFree(ret);
} }
@ -116,7 +116,7 @@ getinfo_layout(void)
if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_LAYOUT"), 0L, 4096, if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_CURRENT_LAYOUT"), 0L, 4096,
False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret) False, ATOM("UTF8_STRING"), &rt, &rf, &ir, &il, &ret) == Success && ret)
{ {
layout = _strdup((char*)ret); layout = xstrdup((char*)ret);
XFree(ret); XFree(ret);
} }
@ -137,7 +137,7 @@ getinfo_mwfact(void)
if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_MWFACT"), 0L, 4096, if(XGetWindowProperty(dpy, ROOT, ATOM("_WMFS_MWFACT"), 0L, 4096,
False, XA_STRING, &rt, &rf, &ir, &il, &ret) == Success && ret) False, XA_STRING, &rt, &rf, &ir, &il, &ret) == Success && ret)
{ {
mwfact = _strdup((char*)ret); mwfact = xstrdup((char*)ret);
XFree(ret); XFree(ret);
} }

View File

@ -42,7 +42,7 @@ infobar_init(void)
s = screen_count(); s = screen_count();
if(!infobar) if(!infobar)
infobar = emalloc(s, sizeof(InfoBar)); infobar = xcalloc(s, sizeof(InfoBar));
for(sc = 0; sc < s; ++sc) for(sc = 0; sc < s; ++sc)
{ {
@ -127,7 +127,7 @@ infobar_init(void)
barwin_refresh(infobar[sc].bar); barwin_refresh(infobar[sc].bar);
/* Default statustext is set here */ /* Default statustext is set here */
infobar[sc].statustext = _strdup(WMFS_VERSION); infobar[sc].statustext = xstrdup(WMFS_VERSION);
infobar_draw(sc); infobar_draw(sc);
} }
@ -190,7 +190,7 @@ infobar_draw_selbar(int sc)
if(conf.selbar.maxlength >= 0 && sel) if(conf.selbar.maxlength >= 0 && sel)
{ {
str = emalloc(conf.selbar.maxlength + 4, sizeof(char)); str = xcalloc(conf.selbar.maxlength + 4, sizeof(char));
strncpy(str, sel->title, conf.selbar.maxlength); strncpy(str, sel->title, conf.selbar.maxlength);
if(strlen(sel->title) > (size_t)conf.selbar.maxlength) if(strlen(sel->title) > (size_t)conf.selbar.maxlength)
@ -220,7 +220,7 @@ infobar_draw_selbar(int sc)
void void
infobar_draw_taglist(int sc) infobar_draw_taglist(int sc)
{ {
int i, x, j; int i, x;
Client *c = NULL; Client *c = NULL;
Bool is_occupied[MAXTAG + 1]; Bool is_occupied[MAXTAG + 1];
@ -234,7 +234,7 @@ infobar_draw_taglist(int sc)
if(c->screen == sc) if(c->screen == sc)
is_occupied[c->tag] = True; is_occupied[c->tag] = True;
for(i = 1, x = j = 0; i < conf.ntag[sc] + 1; ++i) for(i = 1, x = 0; i < conf.ntag[sc] + 1; ++i)
{ {
/* Autohide tag feature */ /* Autohide tag feature */
if(conf.tagautohide) if(conf.tagautohide)

View File

@ -196,7 +196,7 @@ init_status(void)
return; return;
} }
conf.status_path = emalloc(strlen(home) + strlen(DEF_STATUS) + 2, sizeof(char)); conf.status_path = zmalloc(strlen(home) + strlen(DEF_STATUS) + 2);
sprintf(conf.status_path, "%s/"DEF_STATUS, home); sprintf(conf.status_path, "%s/"DEF_STATUS, home);
} }

View File

@ -156,7 +156,7 @@ launcher_execute(Launcher *launcher)
else else
{ {
tabhits = 1; tabhits = 1;
strcpy(tmpbuf, buf); strncpy(tmpbuf, buf, sizeof(tmpbuf));
} }
@ -169,7 +169,7 @@ launcher_execute(Launcher *launcher)
if (complete) if (complete)
{ {
strcpy(buf, tmpbuf); strncpy(buf, tmpbuf, sizeof(buf));
strncat(buf, complete, sizeof(buf)); strncat(buf, complete, sizeof(buf));
found = True; found = True;
free(complete); free(complete);
@ -179,7 +179,7 @@ launcher_execute(Launcher *launcher)
lastwastab = True; lastwastab = True;
/* start a new round of tabbing */ /* start a new round of tabbing */
if (!found) if (found == False)
tabhits = 0; tabhits = 0;
pos = strlen(buf); pos = strlen(buf);
@ -253,12 +253,11 @@ complete_on_command(char *start, size_t hits)
char **namelist = NULL; char **namelist = NULL;
int n = 0, i; int n = 0, i;
void *temp = NULL;
if (!getenv("PATH") || !start || hits <= 0) if (!getenv("PATH") || !start || hits <= 0)
return NULL; return NULL;
path = _strdup(getenv("PATH")); path = xstrdup(getenv("PATH"));
dirname = strtok(path, ":"); dirname = strtok(path, ":");
/* recursively open PATH */ /* recursively open PATH */
@ -272,10 +271,8 @@ complete_on_command(char *start, size_t hits)
{ {
if (!strncmp(content->d_name, start, strlen(start))) if (!strncmp(content->d_name, start, strlen(start)))
{ {
temp = realloc(namelist, ++n * sizeof(*namelist)); namelist = xrealloc(namelist, ++n, sizeof(*namelist));
if ( temp != NULL ) namelist[n-1] = xstrdup(content->d_name);
namelist = temp;
namelist[n-1] = strdup(content->d_name);
} }
} }
} }
@ -283,19 +280,20 @@ complete_on_command(char *start, size_t hits)
} }
dirname = strtok(NULL, ":"); dirname = strtok(NULL, ":");
} }
qsort(namelist, n, sizeof(char *), qsort_string_compare);
free(path); free(path);
if(n > 0) if(n > 0)
{ {
ret = _strdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start)); qsort(namelist, n, sizeof(char *), qsort_string_compare);
ret = xstrdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start));
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
free(namelist[i]); free(namelist[i]);
free(namelist);
} }
free(namelist);
return ret; return ret;
} }
@ -324,14 +322,14 @@ complete_on_files(char *start, size_t hits)
* the beginning of file to complete on pointer 'p'. * the beginning of file to complete on pointer 'p'.
*/ */
if (*(++p) == '\0' || !strrchr(p, '/')) if (*(++p) == '\0' || !strrchr(p, '/'))
path = _strdup("."); path = xstrdup(".");
else else
{ {
/* remplace ~ by $HOME in dirname */ /* remplace ~ by $HOME in dirname */
if (!strncmp(p, "~/", 2) && getenv("HOME")) if (!strncmp(p, "~/", 2) && getenv("HOME"))
xasprintf(&dirname, "%s%s", getenv("HOME"), p+1); xasprintf(&dirname, "%s%s", getenv("HOME"), p+1);
else else
dirname = _strdup(p); dirname = xstrdup(p);
/* Set p to filename to be complete /* Set p to filename to be complete
* and path the directory containing the file * and path the directory containing the file
@ -342,11 +340,11 @@ complete_on_files(char *start, size_t hits)
if (p != dirname) if (p != dirname)
{ {
*(p++) = '\0'; *(p++) = '\0';
path = _strdup(dirname); path = xstrdup(dirname);
} }
else else
{ {
path = _strdup("/"); path = xstrdup("/");
p++; p++;
} }
} }
@ -367,7 +365,7 @@ complete_on_files(char *start, size_t hits)
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
xasprintf(&ret, "%s/", content->d_name + strlen(p)); xasprintf(&ret, "%s/", content->d_name + strlen(p));
else else
ret = _strdup(content->d_name + strlen(p)); ret = xstrdup(content->d_name + strlen(p));
} }
else else
warn("%s", filepath); warn("%s", filepath);

View File

@ -325,7 +325,10 @@ multi_tile(int screen, Position type)
{ {
if(type == Top) if(type == Top)
mastergeo.y = (n <= nmaster) ? (uint)sg.y : sg.y + (sg.height - mwfact) - BORDH; mastergeo.y = (n <= nmaster) ? (uint)sg.y : sg.y + (sg.height - mwfact) - BORDH;
mastergeo.width = (sg.width / nmaster) - (BORDH * 4); if (nmaster != 0)
mastergeo.width = (sg.width / nmaster) - (BORDH * 4);
else
mastergeo.width = sg.width - (BORDH * 4);
mastergeo.height = (n <= nmaster) ? (uint)(sg.height - BORDH) : mwfact; mastergeo.height = (n <= nmaster) ? (uint)(sg.height - BORDH) : mwfact;
} }
else else
@ -333,7 +336,10 @@ multi_tile(int screen, Position type)
if(type == Left) if(type == Left)
mastergeo.x = (n <= nmaster) ? (uint)sg.x : (sg.x + sg.width) - mwfact - (BORDH * 2); mastergeo.x = (n <= nmaster) ? (uint)sg.x : (sg.x + sg.width) - mwfact - (BORDH * 2);
mastergeo.width = (n <= nmaster) ? (uint)(sg.width - (BORDH * 2)) : mwfact; mastergeo.width = (n <= nmaster) ? (uint)(sg.width - (BORDH * 2)) : mwfact;
mastergeo.height = (sg.height / nmaster) - BORDH; if (nmaster != 0)
mastergeo.height = sg.height - BORDH;
else
mastergeo.height = BORDH;
} }
/* TILED SIZE */ /* TILED SIZE */
@ -823,7 +829,7 @@ uicb_set_layout(uicb_t cmd)
for(n = 0; layout_list[n].name != NULL && layout_list[n].func != NULL; ++n); for(n = 0; layout_list[n].name != NULL && layout_list[n].func != NULL; ++n);
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i)
if(!strcmp(cmd, _strdup(layout_list[i].name))) if(!strcmp(cmd, xstrdup(layout_list[i].name)))
for(j = 0; j < LEN(conf.layout); ++j) for(j = 0; j < LEN(conf.layout); ++j)
if(layout_list[i].func == conf.layout[j].func) if(layout_list[i].func == conf.layout[j].func)
tags[selscreen][seltag[selscreen]].layout = conf.layout[j]; tags[selscreen][seltag[selscreen]].layout = conf.layout[j];

View File

@ -37,7 +37,7 @@ menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, c
{ {
/* Item */ /* Item */
menu->nitem = nitem; menu->nitem = nitem;
menu->item = emalloc(sizeof(MenuItem), nitem); menu->item = xcalloc(nitem, sizeof(*menu->item));
menu->name = name; menu->name = name;
/* Colors */ /* Colors */

View File

@ -14,8 +14,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif
#ifndef _BSD_SOURCE
#define _BSD_SOURCE #define _BSD_SOURCE
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -87,7 +91,7 @@ push_keyword(struct keyword *tail, enum keyword_t type, char *buf, size_t *offse
if (type == WORD && *offset == 0) if (type == WORD && *offset == 0)
return tail; return tail;
kw = xcalloc(1, sizeof(*kw)); kw = zcalloc(sizeof(*kw));
kw->type = type; kw->type = type;
kw->line = line; kw->line = line;
kw->file = file; kw->file = file;
@ -96,7 +100,7 @@ push_keyword(struct keyword *tail, enum keyword_t type, char *buf, size_t *offse
if (*offset != 0) { if (*offset != 0) {
buf[*offset] = '\0'; buf[*offset] = '\0';
if (!strcmp(buf, INCLUDE_CMD)) if (!strcmp(buf, INCLUDE_CMD))
type = kw->type = INCLUDE; kw->type = INCLUDE;
else else
kw->name = strdup(buf); kw->name = strdup(buf);
*offset = 0; *offset = 0;
@ -179,8 +183,8 @@ parse_keywords(const char *filename)
return NULL; return NULL;
} }
file = xcalloc(1, sizeof(*file)); file = zcalloc(sizeof(*file));
bufname = xcalloc(1, sizeof(*bufname) * BUFSIZ); bufname = zcalloc(sizeof(*bufname) * BUFSIZ);
file->name = strdup(path); file->name = strdup(path);
file->parent = NULL; file->parent = NULL;
@ -394,7 +398,7 @@ get_option(struct keyword **head)
size_t j = 0; size_t j = 0;
struct keyword *kw = *head; struct keyword *kw = *head;
o = xcalloc(1, sizeof(*o)); o = zcalloc(sizeof(*o));
o->name = kw->name; o->name = kw->name;
o->used = False; o->used = False;
o->line = kw->line; o->line = kw->line;
@ -495,7 +499,7 @@ get_section(struct keyword **head)
struct conf_sec *sub; struct conf_sec *sub;
struct keyword *kw = *head; struct keyword *kw = *head;
s = xcalloc(1, sizeof(*s)); s = zcalloc(sizeof(*s));
s->name = kw->name; s->name = kw->name;
TAILQ_INIT(&s->sub); TAILQ_INIT(&s->sub);
SLIST_INIT(&s->optlist); SLIST_INIT(&s->optlist);
@ -616,32 +620,3 @@ get_conf(const char *filename)
return 0; return 0;
} }
/* calloc wrapper */
void *
xcalloc(size_t nmemb, size_t size)
{
void *ret;
if (!(ret = calloc(nmemb, size)))
err(EXIT_FAILURE, "calloc");
return ret;
}
/* asprintf wrapper */
int
xasprintf(char **strp, const char *fmt, ...)
{
int ret;
va_list args;
va_start(args, fmt);
ret = vasprintf(strp, fmt, args);
va_end(args);
if (ret == -1)
err(EXIT_FAILURE, "asprintf");
return ret;
}

View File

@ -17,6 +17,7 @@
#ifndef PARSE_H #ifndef PARSE_H
#define PARSE_H #define PARSE_H
#include "wmfs.h"
#include <sys/queue.h> #include <sys/queue.h>
#define INCLUDE_CMD "@include" #define INCLUDE_CMD "@include"
@ -117,10 +118,4 @@ struct opt_type *fetch_opt(struct conf_sec *, char *, char *);
*/ */
size_t fetch_opt_count(struct opt_type *); size_t fetch_opt_count(struct opt_type *);
/* wrapper for calloc */
void *xcalloc(size_t, size_t);
/* wrapper for asprintf */
int xasprintf(char **, const char *, ...);
#endif /* PARSE_H */ #endif /* PARSE_H */

View File

@ -14,7 +14,9 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#ifndef _BSD_SOURCE
#define _BSD_SOURCE #define _BSD_SOURCE
#endif
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <err.h> #include <err.h>

View File

@ -91,6 +91,8 @@ screen_get_geo(int s)
XFree(xsi); XFree(xsi);
} }
#else
(void)s;
#endif /* HAVE_XINERAMA */ #endif /* HAVE_XINERAMA */
return geo; return geo;
@ -177,8 +179,8 @@ screen_init_geo(void)
int i; int i;
int s = screen_count(); int s = screen_count();
sgeo = emalloc(s, sizeof(XRectangle)); sgeo = xcalloc(s, sizeof(XRectangle));
spgeo = emalloc(s, sizeof(XRectangle)); spgeo = xcalloc(s, sizeof(XRectangle));
for(i = 0; i < s; ++i) for(i = 0; i < s; ++i)
sgeo[i] = screen_get_geo(i); sgeo[i] = screen_get_geo(i);

View File

@ -158,11 +158,11 @@ statustext_normal(int sc, char *str)
/* Draw normal text without any blocks */ /* Draw normal text without any blocks */
draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw), draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw),
FHINFOBAR, infobar[sc].bar->fg, 0, strwc); FHINFOBAR, infobar[sc].bar->fg, strwc);
if(n) if(n)
{ {
strcpy(buf, strwc); strncpy(buf, strwc, sizeof(buf));
for(i = k = 0; i < (int)strlen(str); ++i, ++k) for(i = k = 0; i < (int)strlen(str); ++i, ++k)
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\') if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
@ -177,9 +177,9 @@ statustext_normal(int sc, char *str)
/* Draw text with its color */ /* Draw text with its color */
draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw), draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw),
FHINFOBAR, col, 0, &buf[k]); FHINFOBAR, col, &buf[k]);
strcpy(buf, strwc); strncpy(buf, strwc, sizeof(buf));
++i; ++i;
} }
} }
@ -195,7 +195,7 @@ void
statustext_handle(int sc, char *str) statustext_handle(int sc, char *str)
{ {
char *lastst; char *lastst;
int i, nr, ng, ns, len, sw = 0; int i, nr, ng, ns, sw = 0;
StatusRec r[128]; StatusRec r[128];
StatusGraph g[128]; StatusGraph g[128];
StatusText s[128]; StatusText s[128];
@ -212,8 +212,7 @@ statustext_handle(int sc, char *str)
/* save last status text address (for free at the end) */ /* save last status text address (for free at the end) */
lastst = infobar[sc].statustext; lastst = infobar[sc].statustext;
infobar[sc].statustext = _strdup(str); infobar[sc].statustext = xstrdup(str);
len = ((strlen(str) > MAXSTATUS) ? MAXSTATUS : strlen(str));
/* Store rectangles, located text & images properties. */ /* Store rectangles, located text & images properties. */
nr = statustext_rectangle(r, str); nr = statustext_rectangle(r, str);
@ -233,7 +232,7 @@ statustext_handle(int sc, char *str)
/* Draw located text with stored properties. */ /* Draw located text with stored properties. */
for(i = 0; i < ns; ++i) for(i = 0; i < ns; ++i)
draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, 0, s[i].text); draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, s[i].text);
barwin_refresh(infobar[sc].bar); barwin_refresh(infobar[sc].bar);

View File

@ -85,7 +85,7 @@ systray_add(Window win)
if(!conf.systray.active) if(!conf.systray.active)
return; return;
s = emalloc(1, sizeof(Systray)); s = zcalloc(sizeof(Systray));
s->win = win; s->win = win;
s->geo.height = infobar[conf.systray.screen].bar->geo.height; s->geo.height = infobar[conf.systray.screen].bar->geo.height;
@ -98,8 +98,8 @@ systray_add(Window win)
ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0, traywin, 0); ewmh_send_message(s->win, s->win, "_XEMBED", CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0, traywin, 0);
/* Attach */ /* Attach */
if(trayicons) if(trayicons)
trayicons->prev = s; trayicons->prev = s;
s->next = trayicons; s->next = trayicons;
trayicons = s; trayicons = s;

View File

@ -543,7 +543,7 @@ tag_new(int s, char *name)
{ {
if(conf.tagnamecount) if(conf.tagnamecount)
{ {
displayedName = (char*) malloc( sizeof(char)*2 ); displayedName = zmalloc(2);
sprintf(displayedName, "[%d]", conf.ntag[s]); sprintf(displayedName, "[%d]", conf.ntag[s]);
} }
else else
@ -656,11 +656,22 @@ void
uicb_tag_rename(uicb_t cmd) uicb_tag_rename(uicb_t cmd)
{ {
screen_get_sel(); screen_get_sel();
char *str;
size_t len;
if(!cmd || !strlen(cmd)) if(!cmd || !strlen(cmd))
return; return;
strcpy(tags[selscreen][seltag[selscreen]].name, cmd); str = tags[selscreen][seltag[selscreen]].name;
len = strlen(str);
/* TODO: if strlen(cmd) > len, the tag name
* will be truncated...
* We can't do a realloc because if the pointer change
* free() on paser will segfault.on free_conf()...
*/
strncpy(str, cmd, len);
infobar_update_taglist(selscreen); infobar_update_taglist(selscreen);
infobar_draw(selscreen); infobar_draw(selscreen);

View File

@ -32,22 +32,100 @@
#include "wmfs.h" #include "wmfs.h"
/** Calloc with an error message if there is a probleme /** malloc with error support and size_t overflow protection
* \param element Element * \param nmemb number of objects
* \param size Size * \param size size of single object
* \return void pointer * \return non null void pointer
*/ */
void* void *
emalloc(uint element, uint size) xmalloc(size_t nmemb, size_t size)
{ {
void *ret = calloc(element, size); void *ret;
if(!ret) if (SIZE_MAX / nmemb < size)
warn("calloc()"); err(EXIT_FAILURE, "xmalloc(%zu, %zu), "
"size_t overflow detected", nmemb, size);
if ((ret = malloc(nmemb * size)) == NULL)
err(EXIT_FAILURE, "malloc(%zu)", nmemb * size);
return ret; return ret;
} }
/** calloc with error support
* \param nmemb Number of objects
* \param size size of single object
* \return non null void pointer
*/
void *
xcalloc(size_t nmemb, size_t size)
{
void *ret;
if ((ret = calloc(nmemb, size)) == NULL)
err(EXIT_FAILURE, "calloc(%zu * %zu)", nmemb, size);
return ret;
}
/** realloc with error support and size_t overflow check
* \param ptr old pointer
* \param nmemb number of objects
* \param size size of single object
* \return non null void pointer
*/
void *
xrealloc(void *ptr, size_t nmemb, size_t size)
{
void *ret;
if (SIZE_MAX / nmemb < size)
err(EXIT_FAILURE, "xrealloc(%p, %zu, %zu), "
"size_t overflow detected", ptr, nmemb, size);
if ((ret = realloc(ptr, nmemb * size)) == NULL)
err(EXIT_FAILURE, "realloc(%p, %zu)", ptr, nmemb * size);
return ret;
}
/** strdup with error support
* \param str char pointer
* \retun non null void pointer
*/
char *
xstrdup(const char *str)
{
char *ret;
if (str == NULL || (ret = strdup(str)) == NULL)
err(EXIT_FAILURE, "strdup(%s)", str);
return ret;
}
/** asprintf wrapper
* \param strp target string
* \param fmt format
* \return non zero integer
*/
int
xasprintf(char **strp, const char *fmt, ...)
{
int ret;
va_list args;
va_start(args, fmt);
ret = vasprintf(strp, fmt, args);
va_end(args);
if (ret == -1)
err(EXIT_FAILURE, "asprintf(%s)", fmt);
return ret;
}
/** Get a color with a string /** Get a color with a string
* \param color Color string * \param color Color string
* \return Color pixel * \return Color pixel
@ -93,20 +171,6 @@ setwinstate(Window win, long state)
return; return;
} }
/** My strdup. the strdup of string.h isn't ansi compatible..
* Thanks linkdd.
* \param str char pointer
*/
char*
_strdup(const char *str)
{
char *ret = emalloc(strlen(str) + 1, sizeof(char));
strcpy(ret, str);
return ret;
}
/* The following function are for configuration /* The following function are for configuration
usage. {{{ usage. {{{
*/ */
@ -176,9 +240,9 @@ alias_to_str(char *conf_choice)
tmpchar = conf.alias[i].content; tmpchar = conf.alias[i].content;
if(tmpchar) if(tmpchar)
return _strdup(tmpchar); return xstrdup(tmpchar);
else else
return _strdup(conf_choice); return xstrdup(conf_choice);
return NULL; return NULL;
} }
@ -327,7 +391,7 @@ clean_value(char *str)
int i; int i;
char c, *p; char c, *p;
if(!str || !(p = _strdup(str))) if(!str || !(p = xstrdup(str)))
return NULL; return NULL;
/* Remove useless spaces */ /* Remove useless spaces */
@ -353,7 +417,7 @@ patht(char *path)
if(!path) if(!path)
return NULL; return NULL;
strcpy(ret, path); strncpy(ret, path, sizeof(ret));
if(strstr(path, "~/")) if(strstr(path, "~/"))
sprintf(ret, "%s/%s", getenv("HOME"), path + 2); sprintf(ret, "%s/%s", getenv("HOME"), path + 2);

View File

@ -103,7 +103,7 @@ viwmfs(int argc, char **argv)
} }
} }
else else
strcpy(str, argv[2]); strncpy(str, argv[2], sizeof(str));
if(!strcmp(str, "help")) if(!strcmp(str, "help"))
{ {
@ -116,7 +116,7 @@ viwmfs(int argc, char **argv)
{ {
for(i = 0; i < strlen(str); str[i] = str[i + 1], ++i); for(i = 0; i < strlen(str); str[i] = str[i + 1], ++i);
cmd = _strdup(str); cmd = xstrdup(str);
for(i = 0; cmd[i] && cmd[i] != ' '; ++i); for(i = 0; cmd[i] && cmd[i] != ' '; ++i);
cmd[i] = '\0'; cmd[i] = '\0';

View File

@ -36,7 +36,6 @@ int
errorhandler(Display *d, XErrorEvent *event) errorhandler(Display *d, XErrorEvent *event)
{ {
char mess[256]; char mess[256];
Client *c;
/* Check if there is another WM running */ /* Check if there is another WM running */
if(BadAccess == event->error_code if(BadAccess == event->error_code
@ -48,7 +47,7 @@ errorhandler(Display *d, XErrorEvent *event)
* 42 = X_SetInputFocus * 42 = X_SetInputFocus
* 28 = X_GrabButton * 28 = X_GrabButton
*/ */
if((c = client_gb_win(event->resourceid))) if(client_gb_win(event->resourceid))
if(event->error_code == BadWindow if(event->error_code == BadWindow
|| event->request_code == 42 || event->request_code == 42
|| event->request_code == 28) || event->request_code == 28)
@ -421,9 +420,8 @@ main(int argc, char **argv)
int i; int i;
char *ol = "csgVS"; char *ol = "csgVS";
argv_global = _strdup(argv[0]); argv_global = xstrdup(argv[0]);
all_argv = argv; all_argv = argv;
sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME"));
while((i = getopt(argc, argv, "hviSc:s:g:C:V:")) != -1) while((i = getopt(argc, argv, "hviSc:s:g:C:V:")) != -1)
@ -467,7 +465,7 @@ main(int argc, char **argv)
break; break;
case 'C': case 'C':
strcpy(conf.confpath, optarg); strncpy(conf.confpath, optarg, sizeof(conf.confpath));
break; break;
case 'c': case 'c':

View File

@ -34,14 +34,22 @@
#define WMFS_H #define WMFS_H
/* glibc stuff */ /* glibc stuff */
#ifndef _BSD_SOURCE
#define _BSD_SOURCE /* vsnprintf */ #define _BSD_SOURCE /* vsnprintf */
#define _POSIX_SOURCE /* kill() */ #endif
#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE /* kill */
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* asprintf */
#endif
/* Lib headers */ /* Lib headers */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
@ -61,7 +69,7 @@
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
/* Local headers */ /* Local headers */
#include "parse/parse.h" #include "parse.h"
#include "structs.h" #include "structs.h"
/* Optional dependencies */ /* Optional dependencies */
@ -136,8 +144,8 @@ void barwin_refresh_color(BarWindow *bw);
void barwin_refresh(BarWindow *bw); void barwin_refresh(BarWindow *bw);
/* draw.c */ /* draw.c */
void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str); void draw_text(Drawable d, int x, int y, char* fg, char *str);
void draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset); void draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset);
void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data); void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data);
@ -281,11 +289,18 @@ void uicb_mouse_move(uicb_t);
void uicb_mouse_resize(uicb_t); void uicb_mouse_resize(uicb_t);
/* util.c */ /* util.c */
void *xmalloc(size_t, size_t);
void *xcalloc(size_t, size_t);
void *xrealloc(void *, size_t, size_t);
/* simples wrappers for allocating only one object */
#define zmalloc(size) xmalloc(1, (size))
#define zcalloc(size) xcalloc(1, (size))
#define zrealloc(ptr, size) xrealloc((ptr), 1, (size))
char *xstrdup(const char *);
int xasprintf(char **, const char *, ...);
ulong color_enlight(ulong col); ulong color_enlight(ulong col);
void *emalloc(uint element, uint size);
long getcolor(char *color); long getcolor(char *color);
void setwinstate(Window win, long state); void setwinstate(Window win, long state);
char* _strdup(char const *str);
/* Conf usage {{{ */ /* Conf usage {{{ */
void* name_to_func(char *name, const func_name_list_t *l); void* name_to_func(char *name, const func_name_list_t *l);
ulong char_to_modkey(char *name, key_name_list_t key_l[]); ulong char_to_modkey(char *name, key_name_list_t key_l[]);